Playwright/Base.pm

filter: Statementstmt 91.6% 55 / 60 Branchbran 73.0% 19 / 26 Conditioncond 33.3% 4 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 92.8% 13 / 14 Podpod 50.0% 1 / 2 totaltotal 77.5% 93 / 120 CC 19 SCAR 23.5
CC
19
Cov
80%
_api_request
22.4
_coerce
11.1
__ANON__
2.0
CRAP 10.5
« Playwright.pm ↑ Summary Playwright/Util.pm »
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
BranchTrueFalseTotal
if ($i < scalar @argspec) 4 3 7
42 4 ▶ next unless $i < @{ $args{args} };
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @{$args{"args"};} 1 3 4
43 3 my $arg = $args{args}[$i];
44 3 my $type = $argspec[$i]->{type};
45 3 ▶ if ( $type->{name} eq 'boolean' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type->{'name'} eq 'boolean') { } 1 2 3
elsif ($type->{'name'} eq 'Object') { } 1 1 2
46 1 my $truthy = int( !!$arg );
47 1 ▶ $args{args}[$i] = $truthy ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$truthy ? : 0 1 1
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
BranchTrueFalseTotal
if ref $type->{"properties"} eq "ARRAY" 0 1 1
53 1 foreach my $prop ( keys( %{ $type->{properties} } ) ) {
54 3 ▶ next unless exists $arg->{$prop};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg->{$prop} 1 2 3
55 2 my $truthy = int( !!$arg->{$prop} );
56 2 ▶ next unless $type->{properties}{$prop}{type}{name} eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
unless $type->{"properties"}{$prop}{"type"}{"name"} eq "boolean" 1 1 2
57 1 ▶ $args{args}[$i]->{$prop} = $truthy ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$truthy ? : 1 0 1
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
BranchTrueFalseTotal
if $args{"command"} =~ /^waitFor/u 0 2 2
72  
73 2 my $msg = Playwright::Base::_do->( $self, %args );
74  
75 2 ▶ if ( ref $msg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg eq "ARRAY") 0 2 2
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
BranchTrueFalseTotal
if ref $_ eq "HASH" and $_->{"_type"} and exists $Playwright::mapper{$_->{"_type"}} 0 0 0
Condition0%0/6
ref $_ eq "HASH" and $_->{"_type"} and exists $Playwright::mapper{$_->{"_type"}}
!ll&&!rl&&r
000
ref $_ eq "HASH" and $_->{"_type"}
!ll&&!rl&&r
000
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"}}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}} 1 1 2
Condition66%4/6
ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}}
!ll&&!rl&&r
101
ref $msg eq "HASH" and $msg->{"_type"}
!ll&&!rl&&r
011
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"}}
ABCresult
0XX0
10X0
1100
1111
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__
« Playwright.pm ↑ Summary Playwright/Util.pm »