| 1 | package Playwright::Base; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Playwright::Base::VERSION = '1.641'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use v5.28; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Sub::Install(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Playwright::Util(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | #ABSTRACT: Object representing Playwright pages | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | no warnings 'experimental'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use feature qw{signatures}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub new ( $class, %options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | my $self = bless( | ||||||||||||||||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | type => $options{type}, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | guid => $options{id}, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ua => $options{handle}{ua}, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | port => $options{handle}{port}, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | host => $options{handle}{host}, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | parent => $options{parent}, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | $class | |||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | return ($self); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub _coerce ( $spec, %args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | #Coerce bools correctly | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my @argspec = values( %{ $spec->{ $args{command} }{args} } ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | @argspec = sort { $a->{order} <=> $b->{order} } @argspec; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | for ( my $i = 0 ; $i < scalar(@argspec) ; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | next unless $i < @{ $args{args} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | my $arg = $args{args}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | my $type = $argspec[$i]->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | if ( $type->{name} eq 'boolean' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $truthy = int( !!$arg ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | $args{args}[$i] = $truthy ? JSON::true : JSON::false; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | elsif ( $type->{name} eq 'Object' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | $type->{properties} = | ||||||||||||||||||||||||||||||||||||||||||
| 51 | Playwright::Util::arr2hash( $type->{properties}, 'name' ) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if ref $type->{properties} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | foreach my $prop ( keys( %{ $type->{properties} } ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | next unless exists $arg->{$prop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my $truthy = int( !!$arg->{$prop} ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | next unless $type->{properties}{$prop}{type}{name} eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | $args{args}[$i]->{$prop} = $truthy ? JSON::true : JSON::false; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | return %args; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub _api_request ( $self, %args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_api_request: called CC=9 SCAR=31.1
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | %args = Playwright::Base::_coerce( $self->spec(), %args ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | return Playwright::Util::async( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub { &Playwright::Base::_do( $self, %args ) } ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | if $args{command} =~ m/^waitFor/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $msg = Playwright::Base::_do->( $self, %args ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | if ( ref $msg eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | @$msg = map { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $subject = $_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | $subject = $Playwright::mapper{ $_->{_type} }->( $self, $_ ) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | if ( ref $_ eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | && $_->{_type} | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | && exists $Playwright::mapper{ $_->{_type} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $_ eq "HASH" and $_->{"_type"} and exists $Playwright::mapper{$_->{"_type"}}
ref $_ eq "HASH" and $_->{"_type"}
MC/DC0%0/3
ref $_ eq "HASH" and $_->{"_type"} and exists $Playwright::mapper{$_->{"_type"}}
ref $_ eq "HASH"
$_->{"_type"}
exists $Playwright::mapper{$_->{"_type"}}
Truth table0%0/4
A and B and C
A= ref $_ eq "HASH"B= $_->{"_type"}C= exists $Playwright::mapper{$_->{"_type"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $subject | |||||||||||||||||||||||||||||||||||||||||
| 83 | } @$msg; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | return $Playwright::mapper{ $msg->{_type} }->( $self, $msg ) | ||||||||||||||||||||||||||||||||||||||||||
| 86 | if ( ref $msg eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||
| 87 | && $msg->{_type} | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | && exists $Playwright::mapper{ $msg->{_type} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}}
ref $msg eq "HASH" and $msg->{"_type"}
MC/DC33%1/3
ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}}
ref $msg eq "HASH"
$msg->{"_type"}
exists $Playwright::mapper{$msg->{"_type"}}
Truth table50%2/4
A and B and C
A= ref $msg eq "HASH"B= $msg->{"_type"}C= exists $Playwright::mapper{$msg->{"_type"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | sub _do ( $self, %args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | return Playwright::Util::request( 'POST', 'command', $self->{host}, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | $self->{port}, $self->{ua}, %args ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spec: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | return $Playwright::spec; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||||||||||||||||