Kaynağa Gözat

handle inappropriately named methods in Playwright

George S. Baugh 5 yıl önce
ebeveyn
işleme
48bd1061a4
3 değiştirilmiş dosya ile 29 ekleme ve 1 silme
  1. 2 0
      example.pl
  2. 18 0
      lib/Playwright.pm
  3. 9 1
      lib/Playwright/Base.pm

+ 2 - 0
example.pl

@@ -13,3 +13,5 @@ my $res = $page->goto('http://google.com', { waitUntil => 'networkidle' });
 print Dumper($res->status(), $browser->version());
 my $frameset = $page->mainFrame();
 print Dumper($frameset->childFrames());
+my $inputs = $page->selectMulti('input');
+print Dumper($inputs);

+ 18 - 0
lib/Playwright.pm

@@ -42,6 +42,24 @@ Currently understands commands you can send to all the playwright classes define
 See L<https://playwright.dev/#version=master&path=docs%2Fapi.md&q=>
 for what the classes do, and their usage.
 
+There is one major exception in how things work versus the documentation.
+The selector functions have to be renamed from starting with $ for obvious reasons.
+The renamed functions are as follows:
+
+=over 4
+
+=item $ => select
+
+=item $$ => selectMulti
+
+=item $eval => eval
+
+=item $$eval => evalMulti
+
+=back
+
+These functions are present as part of the Page, Frame and ElementHandle classes.
+
 =head1 CONSTRUCTOR
 
 =head2 new(HASH) = (Playwright)

+ 9 - 1
lib/Playwright/Base.pm

@@ -37,6 +37,13 @@ Creates a new page and returns a handle to interact with it.
 
 =cut
 
+our %methods_to_rename = (
+    '$'      => 'select',
+    '$$'     => 'selectMulti',
+    '$eval'  => 'eval',
+    '$$eval' => 'evalMulti',
+);
+
 sub new ($class, %options) {
 
     my $self = bless({
@@ -49,12 +56,13 @@ sub new ($class, %options) {
 
     # Install the subroutines if they aren't already
     foreach my $method (keys(%{$self->{spec}})) {
+        my $renamed = exists $methods_to_rename{$method} ? $methods_to_rename{$method} : $method;
         Sub::Install::install_sub({
             code => sub {
                 my $self = shift;
                 Playwright::Base::_request($self, args => [@_], command => $method, object => $self->{guid}, type => $self->{type} );
             },
-            as   => $method,
+            as   => $renamed,
             into => $class,
         }) unless $self->can($method);
     }