| 1 | package Playwright; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Playwright::VERSION = '1.641'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #ABSTRACT: Perl client for Playwright | ||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use v5.28.0; # Before 5.006, v5.10.0 would not be understood. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use constant IS_WIN => $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::ShareDir(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Basename(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Cwd(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use LWP::UserAgent(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Sub::Install(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Net::EmptyPort(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use JSON::MaybeXS(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use File::Which(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use File::Temp(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Capture::Tiny qw{capture_merged capture_stderr}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Carp qw{confess}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Playwright::Base(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Playwright::Util(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Stuff closet full of skeletons at BEGIN time | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Playwright::ModuleList(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | no warnings 'experimental'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use feature qw{signatures}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | our ( $spec, $server_bin, $node_bin, %mapper ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub _check_node { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_node: called CC=8 SCAR=39.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Check that node is installed | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $node_bin = File::Which::which('node'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | confess("node must exist, be in your PATH and executable") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Playwright::node_bin and -x $Playwright::node_bin
MC/DC0%0/2
$Playwright::node_bin and -x $Playwright::node_bin
$Playwright::node_bin
-x $Playwright::node_bin
Truth table33%1/3
A and B
A= $Playwright::node_binB= -x $Playwright::node_bin
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | unless $node_bin && -x $node_bin; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Make sure it's possible to start the server | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $server_bin = File::Which::which('playwright_server'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # If it's not in $PATH, it should be in ../bin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $server_bin //= Playwright::Util::find_playwright_server(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Playwright::server_bin //= Playwright::Util::find_playwright_server()
MC/DC0%0/2
$Playwright::server_bin //= Playwright::Util::find_playwright_server()
$Playwright::server_bin
Playwright::Util::find_playwright_server()
Truth table0%0/3
A //= B
A= $Playwright::server_binB= Playwright::Util::find_playwright_server()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | confess( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Playwright::server_bin and -x $Playwright::server_bin
MC/DC0%0/2
$Playwright::server_bin and -x $Playwright::server_bin
$Playwright::server_bin
-x $Playwright::server_bin
Truth table0%0/3
A and B
A= $Playwright::server_binB= -x $Playwright::server_bin
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | "Can't locate playwright_server! | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | Please ensure it is installed in your PATH. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | If you installed this module from CPAN, it should already be." | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ) unless $server_bin && -x $server_bin; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $server_bin = Cwd::abs_path($server_bin); | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Attempt to start the server. If we can't do this, we almost certainly have dependency issues. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $output = ''; | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | if (IS_WIN) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $output = 'OK'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ($output) = | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | capture_merged { system( $node_bin, $server_bin, '--check' ) }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return if $output =~ m/OK/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | warn $output if $output; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | confess( | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | qq{playwright_server could not run successfully. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | See the above error message for why. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | It's likely to be unmet dependencies, or a NODE_PATH issue. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Install of node dependencies must be done manually. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | Run the following: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | npm i express playwright uuid | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sudo npx playwright install-deps | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | export NODE_PATH="\$(npm root):\$(npm root -g)" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | If you still experience issues, run the following: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | NODE_DEBUG=module playwright_server --check | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | This should tell you why node can't find the deps you have installed. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub _build_classes { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_classes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | foreach my $class ( keys(%$spec) ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $mapper{$class} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my ( $self, $res ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $class = "Playwright::$class"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | handle => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | id => $res->{_guid}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | type => $class, | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | parent => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | sub BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | our $SKIP_BEGIN; | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | _check_node() unless $SKIP_BEGIN; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | sub new ( $class, %options ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | #XXX yes, this is a race, so we need retries in _start_server | ||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | my $port = $options{port} // Net::EmptyPort::empty_port(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options{"port"} // Net::EmptyPort::empty_port()
MC/DC0%0/2
$options{"port"} // Net::EmptyPort::empty_port()
$options{"port"}
Net::EmptyPort::empty_port()
Truth table33%1/3
A // B
A= $options{"port"}B= Net::EmptyPort::empty_port()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | my $cdp_uri = $options{cdp_uri} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"cdp_uri"} // ""
MC/DC0%0/1
$options{"cdp_uri"} // ""
$options{"cdp_uri"}
Truth table50%1/2
A
A= $options{"cdp_uri"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my $timeout = $options{timeout} // 30; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"timeout"} // 30
MC/DC100%1/1
$options{"timeout"} // 30
$options{"timeout"}
Truth table100%2/2
A
A= $options{"timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | $options{maxrequest} //= '100kb'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"maxrequest"} //= "100kb"
MC/DC0%0/1
$options{"maxrequest"} //= "100kb"
$options{"maxrequest"}
Truth table50%1/2
A
A= $options{"maxrequest"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | my $cleanup = | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | ( $options{cleanup} // !( $options{port} || $options{host} ) ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
$options{"cleanup"} // !($options{"port"} || $options{"host"})
$options{'port'} || $options{'host'}
MC/DC0%0/1
$options{"cleanup"} // !($options{"port"} || $options{"host"})
$options{"cleanup"}
Truth table50%1/2
A
A= $options{"cleanup"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | my $self = bless( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ua => $options{ua} // LWP::UserAgent->new(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | host => $options{host} // 'localhost', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | port => $port, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | cdp_uri => $cdp_uri, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | debug => $options{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | cleanup => $cleanup, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | pid => $options{host} ? "REUSE" : _start_server( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | $port, $cdp_uri, $timeout, $options{debug}, $cleanup | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition57%4/7
$options{"ua"} // "LWP::UserAgent"->new
$options{"host"} // "localhost"
$$ // "bogus"
MC/DC0%0/2
$options{"ua"} // "LWP::UserAgent"->new
$options{"ua"}
"LWP::UserAgent"->new
MC/DC0%0/1
$options{"host"} // "localhost"
$options{"host"}
MC/DC0%0/1
$$ // "bogus"
$$
Truth table66%2/3
A // B
A= $options{"ua"}B= "LWP::UserAgent"->new
Truth table50%1/2
A
A= $options{"host"}
Truth table50%1/2
A
A= $$
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | parent => $$ // 'bogus', # Oh lawds, this can be undef sometimes | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $class, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | $self->_check_and_build_spec(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | _build_classes(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Control things about the environment we start pw in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | $ENV{MAX_REQUEST_SIZE} = $options{maxrequest}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | sub _check_and_build_spec ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_and_build_spec: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | return $spec if ref $spec eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $spec = | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Playwright::Util::request( 'GET', 'spec', $self->{host}, $self->{port}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $self->{ua}, ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | confess( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | "Could not retrieve Playwright specification. Check that your playwright installation is correct and complete." | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ) unless ref $spec eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return $spec; | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | sub launch ( $self, %args ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
launch: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | Playwright::Base::_coerce( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $spec->{BrowserType}{members}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | args => [ \%args ], | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | command => 'launch' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | delete $args{command}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | my $msg = Playwright::Util::request( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 'POST', 'session', $self->{host}, $self->{port}, $self->{ua}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | type => delete $args{type}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | args => [ \%args ] | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | return $Playwright::mapper{ $msg->{_type} }->( $self, $msg ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | if ( ref $msg eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | && $msg->{_type} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | && exists $Playwright::mapper{ $msg->{_type} }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}}
ref $msg eq "HASH" and $msg->{"_type"}
MC/DC0%0/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 table25%1/4
A and B and C
A= ref $msg eq "HASH"B= $msg->{"_type"}C= exists $Playwright::mapper{$msg->{"_type"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub server ( $self, %args ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | return Playwright::Util::request( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 'POST', 'server', $self->{host}, $self->{port}, $self->{ua}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | object => $args{browser}{guid}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | command => $args{command}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | sub await ( $self, $promise ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
await: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my $obj = Playwright::Util::await($promise); | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | ▶ | return $obj unless $obj->{_type}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | my $class = "Playwright::$obj->{_type}"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | type => $obj->{_type}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | id => $obj->{_guid}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | handle => $self | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub pusht( $object, $timeout, $navigation = 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pusht: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $object->{timeouts} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$object->{"timeouts"} //= []
MC/DC0%0/1
$object->{"timeouts"} //= []
$object->{"timeouts"}
Truth table0%0/2
A
A= $object->{"timeouts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | push( @{ $object->{timeouts} }, $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | return $object->setDefaultNavigationTimeout($timeout) if $navigation; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | return $object->setDefaultTimeout($timeout); | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub popt ( $object, $navigation = 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
popt: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $object->{timeouts} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$object->{"timeouts"} //= []
MC/DC0%0/1
$object->{"timeouts"} //= []
$object->{"timeouts"}
Truth table0%0/2
A
A= $object->{"timeouts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $last_timeout = pop( @{ $object->{timeouts} } ) // 1000; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
pop @{$$object{"timeouts"};} // 1000
MC/DC0%0/1
pop @{$$object{"timeouts"};} // 1000
pop @{$$object{"timeouts"};}
Truth table0%0/2
A
A= pop @{$$object{"timeouts"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | return $object->setDefaultNavigationTimeout($last_timeout) if $navigation; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return $object->setDefaultTimeout($last_timeout); | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub try_until ( $object, $method, @args ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_until: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ( $ctr, $result, $timeout ) = (0); | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $timeout = $object->{timeouts}[-1] if ref $object->{timeouts} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $timeout = $timeout / 1000 if $timeout; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $timeout //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$timeout //= 1
MC/DC0%0/1
$timeout //= 1
$timeout
Truth table0%0/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | while ( !$result ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $result = $object->$method(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | last if $result; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $ctr++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | last if $ctr >= $timeout; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | sub quit ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quit: called CC=12 SCAR=34.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Prevent double destroy after quit() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | return if $self->{killed}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Prevent destructor from firing in child processes so we can do things like async() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # This should also prevent the waitpid below from deadlocking due to two processes waiting on the same pid. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | my $ppid = $$ // 'hokum' | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$ // "hokum"
MC/DC0%0/1
$$ // "hokum"
$$
Truth table50%1/2
A
A= $$
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ; # If $$ is undef both here and in the parent, let's just keep going | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | return unless $ppid == $self->{parent}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Prevent destructor from firing in the event the caller instructs it to not fire | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | return unless $self->{cleanup}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Make sure we don't mash the exit code of things like prove | ||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | local $?; | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | $self->{killed} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | print "Attempting to terminate server process...\n" if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Best effort to whack this, we can't make guarantees during global destruction | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | capture_merged { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | Playwright::Util::request( 'GET', 'shutdown', $self->{host}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | $self->{port}, $self->{ua} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | } if $self->{ua}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | return $self->_kill_playwright_server_windows() if IS_WIN; | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # 0 is always WCONTINUED, 1 is always WNOHANG, and POSIX is an expensive import | ||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # When 0 is returned, the process is still active, so it needs more persuasion | ||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | foreach ( 0 .. 3 ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | return unless waitpid( $self->{pid}, 1 ) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Advanced persuasion | ||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | print "Forcibly terminating server process...\n" if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | kill( 'TERM', $self->{pid} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | #XXX unfortunately I can't just do a SIGALRM, because blocking system calls can't be intercepted on win32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | foreach ( 0 .. $self->{timeout} ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return unless waitpid( $self->{pid}, 1 ) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | warn "Could not shut down playwright server!"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | sub DESTROY ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | $self->quit(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub _wait_port( $port, $timeout, $debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait_port: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | #XXX unusedvars is wigging | ||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $debug = $debug; | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $result = $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Check if the port is already live, and short-circuit if this is the case. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | if (IS_WIN) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | for ( 0 .. $timeout ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | $result = qx{netstat -na | findstr "$port"}; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | print "Waiting on port $port: $result\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | last if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | sleep 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | return !!$result; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | return Net::EmptyPort::wait_port( $port, $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub _start_server ( $port, $cdp_uri, $timeout, $debug, $cleanup ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_server: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $debug = $debug ? '--debug' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Check if the port is already live, and short-circuit if this is the case. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ( _wait_port( $port, 1, $debug ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | print "Re-using playwright server on port $port...\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Set the PID as something bogus, we don't really care as we won't kill it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return "REUSE"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # On windows, the args will have to be handled slightly differently. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | if (IS_WIN) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | push( @args, qq{"$node_bin"}, qq{"$server_bin"} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | push( @args, $node_bin, $server_bin ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | push( @args, ( "--port", $port ) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | push( @args, "--cdp", $cdp_uri ) if $cdp_uri; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | push( @args, $debug ) if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | $ENV{DEBUG} = 'pw:api' if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return _start_server_windows( $port, $timeout, $debug, $cleanup, @args ) | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | if IS_WIN; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $pid = fork // confess("Could not fork"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
fork // confess("Could not fork")
MC/DC0%0/1
fork // confess("Could not fork")
fork
Truth table0%0/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | print "Waiting for playwright server on port $port to come up...\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | Net::EmptyPort::wait_port( $port, $timeout ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | or confess( "Server never came up after " . $timeout . "s!" ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | print "done\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # Orphan the process in the event that cleanup => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ( !$cleanup ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | print "Detaching child process...\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | chdir File::Temp::tempdir( CLEANUP => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | die "Cannot detach playwright_server process for persistence" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | if POSIX::setsid() < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | require Capture::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | capture_merged { exec(@args) }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | die("Could not exec!"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | exec(@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub _start_server_windows ( $port, $timeout, $debug, $cleanup, @args ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_server_windows: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $pid = qq/playwright-server:$port/; | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my @cmdprefix = ( "start /MIN", qq{"$pid"} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $cmdstring = join( ' ', @cmdprefix, @args ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | print "$cmdstring\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | system($cmdstring); | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | _wait_port( $port, $timeout, $debug ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | sub _kill_playwright_server_windows ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_kill_playwright_server_windows: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | my $killer = qq[taskkill /FI "WINDOWTITLE eq $self->{pid}"]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | print "$killer\n" if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | system($killer); | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||