Playwright.pm

filter: Statementstmt 52.2% 103 / 197 Branchbran 20.0% 16 / 80 Conditioncond 31.2% 15 / 48 MC/DCmcdc 4.0% 1 / 25 Subroutinesub 69.0% 29 / 42 Podpod 100% 8 / 8 totaltotal 43.0% 172 / 400 CC 66 SCAR 37.7
CC
66
Cov
41%
_start_server
210.0
try_until
56.0
_check_node
49.7
CRAP 43.5
↑ Summary Playwright/Base.pm »
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
BranchTrueFalseTotal
unless $Playwright::node_bin and -x $Playwright::node_bin 1 0 1
Condition33%1/3
$Playwright::node_bin and -x $Playwright::node_bin
!ll&&!rl&&r
010
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
ABresult
0X0
100
111
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()
l!l&&r!l&&!r
000
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()
ABresult
1X1
011
000
47  
48 0 ▶ confess(
Branch: 1 branch
BranchTrueFalseTotal
unless $Playwright::server_bin and -x $Playwright::server_bin 0 0 0
Condition0%0/3
$Playwright::server_bin and -x $Playwright::server_bin
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $output =~ /OK/u 0 0 0
66  
67 0 ▶ warn $output if $output;
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 0 0
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
BranchTrueFalseTotal
unless $Playwright::SKIP_BEGIN 0 1 1
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()
l!l&&r!l&&!r
020
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()
ABresult
1X1
011
000
115 2 ▶ my $cdp_uri = $options{cdp_uri} // '';
Condition50%1/2
$options{"cdp_uri"} // ""
l!l
02
MC/DC0%0/1
$options{"cdp_uri"} // ""
$options{"cdp_uri"}
Truth table50%1/2
A
A= $options{"cdp_uri"}
Aresult
11
00
116 2 ▶ my $timeout = $options{timeout} // 30;
Condition100%2/2
$options{"timeout"} // 30
l!l
11
MC/DC100%1/1
$options{"timeout"} // 30
$options{"timeout"}
Truth table100%2/2
A
A= $options{"timeout"}
Aresult
11
00
117 2 ▶ $options{maxrequest} //= '100kb';
Condition50%1/2
$options{"maxrequest"} //= "100kb"
l!l
02
MC/DC0%0/1
$options{"maxrequest"} //= "100kb"
$options{"maxrequest"}
Truth table50%1/2
A
A= $options{"maxrequest"}
Aresult
11
00
118 my $cleanup =
119 2 ▶ ( $options{cleanup} // !( $options{port} || $options{host} ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$options{'cleanup'} // !($options{'port'} || $options{'host'}) ? : 2 0 2
Condition40%2/5
$options{"cleanup"} // !($options{"port"} || $options{"host"})
l!l
02
$options{'port'} || $options{'host'}
l!l&&r!l&&!r
002
MC/DC0%0/1
$options{"cleanup"} // !($options{"port"} || $options{"host"})
$options{"cleanup"}
Truth table50%1/2
A
A= $options{"cleanup"}
Aresult
11
00
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
BranchTrueFalseTotal
$options{'host'} ? : 0 2 2
Condition57%4/7
$options{"ua"} // "LWP::UserAgent"->new
l!l&&r!l&&!r
110
$options{"host"} // "localhost"
l!l
02
$$ // "bogus"
l!l
20
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
ABresult
1X1
011
000
Truth table50%1/2
A
A= $options{"host"}
Aresult
11
00
Truth table50%1/2
A
A= $$
Aresult
11
00
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
BranchTrueFalseTotal
if ref $Playwright::spec eq "HASH" 1 1 2
148  
149 $spec =
150 Playwright::Util::request( 'GET', 'spec', $self->{host}, $self->{port},
151 1 $self->{ua}, );
152  
153 1 ▶ confess(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Playwright::spec eq "HASH" 1 0 1
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
BranchTrueFalseTotal
if ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}} 0 1 1
Condition33%2/6
ref $msg eq "HASH" and $msg->{"_type"} and exists $Playwright::mapper{$msg->{"_type"}}
!ll&&!rl&&r
100
ref $msg eq "HASH" and $msg->{"_type"}
!ll&&!rl&&r
100
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"}}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless $obj->{"_type"} 1 1 2
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"} //= []
l!l
00
MC/DC0%0/1
$object->{"timeouts"} //= []
$object->{"timeouts"}
Truth table0%0/2
A
A= $object->{"timeouts"}
Aresult
11
00
203 0 push( @{ $object->{timeouts} }, $timeout );
204 0 ▶ return $object->setDefaultNavigationTimeout($timeout) if $navigation;
Branch: 1 branch
BranchTrueFalseTotal
if $navigation 0 0 0
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"} //= []
l!l
00
MC/DC0%0/1
$object->{"timeouts"} //= []
$object->{"timeouts"}
Truth table0%0/2
A
A= $object->{"timeouts"}
Aresult
11
00
210 0 ▶ my $last_timeout = pop( @{ $object->{timeouts} } ) // 1000;
Condition0%0/2
pop @{$$object{"timeouts"};} // 1000
l!l
00
MC/DC0%0/1
pop @{$$object{"timeouts"};} // 1000
pop @{$$object{"timeouts"};}
Truth table0%0/2
A
A= pop @{$$object{"timeouts"};}
Aresult
11
00
211 0 ▶ return $object->setDefaultNavigationTimeout($last_timeout) if $navigation;
Branch: 1 branch
BranchTrueFalseTotal
if $navigation 0 0 0
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
BranchTrueFalseTotal
if ref $object->{"timeouts"} eq "ARRAY" 0 0 0
218 0 ▶ $timeout = $timeout / 1000 if $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 0 0 0
219 0 ▶ $timeout //= 1;
Condition0%0/2
$timeout //= 1
l!l
00
MC/DC0%0/1
$timeout //= 1
$timeout
Truth table0%0/2
A
A= $timeout
Aresult
11
00
220 0 ▶ while ( !$result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
221 0 $result = $object->$method(@args);
222 0 ▶ last if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
223 0 sleep 1;
224 0 $ctr++;
225 0 ▶ last if $ctr >= $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $ctr >= $timeout 0 0 0
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
BranchTrueFalseTotal
if $self->{"killed"} 0 1 1
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"
l!l
10
MC/DC0%0/1
$$ // "hokum"
$$
Truth table50%1/2
A
A= $$
Aresult
11
00
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
BranchTrueFalseTotal
unless $ppid == $self->{"parent"} 0 1 1
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
BranchTrueFalseTotal
unless $self->{"cleanup"} 0 1 1
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
BranchTrueFalseTotal
if $self->{"debug"} 0 1 1
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
BranchTrueFalseTotal
if $self->{"ua"} 1 0 1
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
BranchTrueFalseTotal
unless waitpid($self->{"pid"}, 1) == 0 1 0 1
264 0 sleep 1;
265 }
266  
267 # Advanced persuasion
268 0 ▶ print "Forcibly terminating server process...\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
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
BranchTrueFalseTotal
unless waitpid($self->{"pid"}, 1) == 0 0 0 0
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
BranchTrueFalseTotal
$debug ? : 0 0 0
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
BranchTrueFalseTotal
if (_wait_port($port, 1, $debug)) 0 0 0
309 0 ▶ print "Re-using playwright server on port $port...\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
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
BranchTrueFalseTotal
if $cdp_uri 0 0 0
326 0 ▶ push( @args, $debug ) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
327  
328 0 ▶ $ENV{DEBUG} = 'pw:api' if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
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")
l!l
00
MC/DC0%0/1
fork // confess("Could not fork")
fork
Truth table0%0/2
A
A= fork
Aresult
11
00
332 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) 0 0 0
333 0 ▶ print "Waiting for playwright server on port $port to come up...\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
334 if $debug;
335 0 ▶ Net::EmptyPort::wait_port( $port, $timeout )
Branch: 1 branch
BranchTrueFalseTotal
Net::EmptyPort::wait_port($port, $timeout) or confess('Server never came up after ' . $timeout . 's!') 0 0 0
336 or confess( "Server never came up after " . $timeout . "s!" );
337 0 ▶ print "done\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
338  
339 0 return $pid;
340 }
341  
342 # Orphan the process in the event that cleanup => 0
343 0 ▶ if ( !$cleanup ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cleanup) 0 0 0
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
BranchTrueFalseTotal
if POSIX::setsid() < 0 0 0 0
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
BranchTrueFalseTotal
if $debug 0 0 0
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
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
370 0 system($killer);
371 0 return 1;
372 }
373  
374 1 1;
375  
376 __END__
↑ Summary Playwright/Base.pm »