blib/lib/Zuzu/Module/Proc.pm

filter: Statementstmt 47.7% 192 / 402 Branchbran 24.7% 56 / 226 Conditioncond 17.7% 8 / 45 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 64.5% 31 / 48 Podpod 0.0% 0 / 1 totaltotal 38.3% 287 / 749 CC 142 SCAR 57.5
CC
142
Cov
38%
_run_pipeline_true_async
1332.0
_run_command
236.9
_result_from_wait_status
110.0
CRAP 313.5
« blib/lib/Zuzu/Module/String/Encode.pm ↑ Summary blib/lib/Zuzu/Module/Marshal.pm »
1 package Zuzu::Module::Proc;
2  
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 our $VERSION = '0.007000';
6  
7 6 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use IPC::Run qw( harness run timeout );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Time::HiRes qw( sleep time );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Cwd qw( getcwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 use Zuzu::Util::NativeHelpers qw(
15 native_class
16 native_function
17 perl_to_zuzu
18 zuzu_bool
19 zuzu_to_perl
20 6 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 my %SIGNAL_PREV;
23 my %SIGNAL_CALLBACKS;
24 6 my %SIGNAL_CALLBACK_INSTALLED;
25  
26 6 my $TEE_CODE = <<'PERL';
27 my $file = shift;
28 open my $fh, '>', $file or die "Could not open tee output: $!";
29 binmode STDIN;
30 binmode STDOUT;
31 binmode $fh;
32 while (1) {
33 my $read = sysread STDIN, my $buffer, 8192;
34 die "Could not read pipeline input: $!" if !defined $read;
35 last if !$read;
36 print {$fh} $buffer;
37 print STDOUT $buffer;
38 }
39 PERL
40  
41 sub _normalize_signal_name {
42 2 ▶ my ( $name ) = @_;
Subroutine _normalize_signal_name: called CC=2 SCAR=7.0
43  
44 2 ▶ my $signal = defined $name ? "$name" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
45 2 $signal =~ s/\A\s+//;
46 2 $signal =~ s/\s+\z//;
47 2 $signal =~ s/\ASIG//i;
48 2 $signal = uc $signal;
49  
50 2 return $signal;
51 }
52  
53 sub _as_command_array {
54 4 ▶ my ( $command, $argv ) = @_;
Subroutine _as_command_array: called CC=6 SCAR=21.4
55  
56 4 my @cmd;
57 4 ▶ if ( ref($command) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $command eq 'ARRAY') { } 0 4 4
58 0 ▶ @cmd = map { defined $_ ? "$_" : '' } @{ $command };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
59 }
60 else {
61 4 ▶ push @cmd, defined $command ? "$command" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $command ? : 4 0 4
62 4 ▶ if ( ref($argv) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv eq "ARRAY") 4 0 4
63 4 ▶ push @cmd, map { defined $_ ? "$_" : '' } @{ $argv };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 8 0 8
64 }
65 }
66  
67 4 return \@cmd;
68 }
69  
70 sub _install_onsignal_handler {
71 1 ▶ my ( $runtime, $signal ) = @_;
Subroutine _install_onsignal_handler: called CC=2 SCAR=7.3
72  
73 1 ▶ return if $SIGNAL_CALLBACK_INSTALLED{$signal};
Branch: 1 branch
BranchTrueFalseTotal
if $SIGNAL_CALLBACK_INSTALLED{$signal} 0 1 1
74  
75 1 $SIGNAL_PREV{$signal} = $SIG{$signal};
76 $SIG{$signal} = sub {
77 1 ▶ my $callbacks = $SIGNAL_CALLBACKS{$signal} // [];
Subroutine __ANON__: called CC=6 SCAR=19.9
Condition50%1/2
$SIGNAL_CALLBACKS{$signal} // []
l!l
10
MC/DC0%0/1
$SIGNAL_CALLBACKS{$signal} // []
$SIGNAL_CALLBACKS{$signal}
Truth table50%1/2
A
A= $SIGNAL_CALLBACKS{$signal}
Aresult
11
00
78 1 for my $callback ( @{ $callbacks } ) {
79 1 ▶ next if not blessed($callback)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function") 0 1 1
Condition33%1/3
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
builtin::blessed($callback) $callback->isa("Zuzu::Value::Function")
Truth table33%1/3
A and B
A= builtin::blessed($callback)B= $callback->isa("Zuzu::Value::Function")
ABresult
0X0
100
111
80 or not $callback->isa( 'Zuzu::Value::Function' );
81 eval {
82 1 $runtime->_call_function( $callback, [], '<std/proc>', 0 );
83 1 1;
84 1 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $runtime->_call_function($callback, [], "<std/proc>", 0); 1 } } or do { return } 0 1 1
85 0 return;
86 };
87 }
88 1 return;
89 1 };
90 1 $SIGNAL_CALLBACK_INSTALLED{$signal} = 1;
91  
92 1 return;
93 }
94  
95 sub _result_ok {
96 2 ▶ my ( $result ) = @_;
Subroutine _result_ok: called CC=8 SCAR=24.5
97  
98 2 ▶ return 0 if ref($result) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result ne "HASH" 0 2 2
99 2 ▶ return 0 if defined $result->{error} and $result->{error} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $result->{"error"} and $result->{"error"} ne "" 0 2 2
Condition33%1/3
defined $result->{"error"} and $result->{"error"} ne ""
!ll&&!rl&&r
200
MC/DC0%0/2
defined $result->{"error"} and $result->{"error"} ne ""
defined $result->{"error"} $result->{"error"} ne ""
Truth table33%1/3
A and B
A= defined $result->{"error"}B= $result->{"error"} ne ""
ABresult
0X0
100
111
100 2 ▶ return 0 if ( $result->{signal} // 0 ) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"signal"} // 0) != 0 0 2 2
Condition50%1/2
$result->{"signal"} // 0
l!l
20
MC/DC0%0/1
$result->{"signal"} // 0
$result->{"signal"}
Truth table50%1/2
A
A= $result->{"signal"}
Aresult
11
00
101 2 ▶ return 0 if ( $result->{exit_code} // 0 ) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"exit_code"} // 0) != 0 0 2 2
Condition50%1/2
$result->{"exit_code"} // 0
l!l
20
MC/DC0%0/1
$result->{"exit_code"} // 0
$result->{"exit_code"}
Truth table50%1/2
A
A= $result->{"exit_code"}
Aresult
11
00
102  
103 2 return 1;
104 }
105  
106 sub _platform_supports_true_pipeline_async {
107 9 ▶ return 0 if $^O =~ /^(?:MSWin32|dos|os2|VMS)\z/;
Subroutine _platform_supports_true_pipeline_async: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /^(?:MSWin32|dos|os2|VMS)\z/ 0 9 9
108 9 return 1;
109 }
110  
111 sub _result_from_wait_status {
112 0 ▶ my ( $cmd, $opts, $status, $stdout, $stderr, $error, $timed_out ) = @_;
Subroutine _result_from_wait_status: not called CC=10 SCAR=47.0
113  
114 0 my $capture_stdout = zuzu_bool( $opts->{capture_stdout}, 1 );
115 0 my $capture_stderr = zuzu_bool( $opts->{capture_stderr}, 1 );
116 0 my $merge_stderr = zuzu_bool( $opts->{merge_stderr}, 0 );
117 0 my $exit_code = $status >> 8;
118 0 my $signal = $status & 127;
119 0 ▶ my $core_dump = ( $status & 128 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status & 128 ? : 0 0 0
120 0 ▶ if ( $timed_out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timed_out) 0 0 0
121 0 ▶ $signal = 14 if $signal == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $signal == 0 0 0 0
122 0 ▶ $error = 'timeout after ' . ( 0 + ( $opts->{timeout} // 0 ) ) . 's';
Condition0%0/2
$opts->{"timeout"} // 0
l!l
00
MC/DC0%0/1
$opts->{"timeout"} // 0
$opts->{"timeout"}
Truth table0%0/2
A
A= $opts->{"timeout"}
Aresult
11
00
123 }
124  
125 0 ▶ my $result = {
Branch: 4 branches
BranchTrueFalseTotal
$capture_stdout || $merge_stderr ? : 0 0 0
$capture_stderr ? : 0 0 0
$merge_stderr ? : 0 0 0
$timed_out ? : 0 0 0
Condition0%0/3
$capture_stdout or $merge_stderr
l!l&&r!l&&!r
000
MC/DC0%0/2
$capture_stdout or $merge_stderr
$capture_stdout $merge_stderr
Truth table0%0/3
A or B
A= $capture_stdoutB= $merge_stderr
ABresult
1X1
011
000
126 command => $cmd,
127 exit_code => $exit_code,
128 signal => $signal,
129 core_dump => $core_dump,
130 ok => 0,
131 stdout => $capture_stdout || $merge_stderr ? $stdout : undef,
132 stderr => $capture_stderr ? ( $merge_stderr ? '' : $stderr ) : undef,
133 error => $error,
134 timed_out => $timed_out ? 1 : 0,
135 };
136 0 $result->{ok} = _result_ok($result);
137  
138 0 return $result;
139 }
140  
141 sub _timeout_result {
142 0 ▶ my ( $cmd, $opts ) = @_;
Subroutine _timeout_result: not called CC=2 SCAR=17.9
143  
144 return _result_from_wait_status(
145 $cmd,
146 $opts,
147 14,
148 '',
149 '',
150 0 ▶ 'timeout after ' . ( 0 + ( $opts->{timeout} // 0 ) ) . 's',
Condition0%0/2
$opts->{"timeout"} // 0
l!l
00
MC/DC0%0/1
$opts->{"timeout"} // 0
$opts->{"timeout"}
Truth table0%0/2
A
A= $opts->{"timeout"}
Aresult
11
00
151 1,
152 );
153 }
154  
155 sub _pipeline_result {
156 0 ▶ my ( $steps ) = @_;
Subroutine _pipeline_result: not called CC=4 SCAR=30.0
157  
158 0 my $failed_steps = scalar grep { !$_->{ok} } @{$steps};
159 0 ▶ my $ok = @{$steps}
Branch: 2 branches
BranchTrueFalseTotal
@{$steps;} ? : 0 0 0
$failed_steps ? : 0 0 0
160 ? ( $failed_steps ? 0 : 1 )
161 : 1;
162 0 ▶ my $last = @{$steps} ? $steps->[-1] : {
Branch: 1 branch
BranchTrueFalseTotal
@{$steps;} ? : 0 0 0
163 command => [],
164 exit_code => 0,
165 signal => 0,
166 core_dump => 0,
167 ok => 1,
168 stdout => '',
169 stderr => '',
170 error => undef,
171 timed_out => 0,
172 };
173  
174 return {
175 ok => $ok,
176 stdout => $last->{stdout},
177 stderr => $last->{stderr},
178 error => $last->{error},
179 exit_code => $last->{exit_code},
180 signal => $last->{signal},
181 core_dump => $last->{core_dump},
182 timed_out => $last->{timed_out},
183 0 steps => $steps,
184 };
185 }
186  
187 sub _run_command {
188 2 ▶ my ( $cmd, $opts ) = @_;
Subroutine _run_command: called CC=39 SCAR=54.7
189  
190 my $stdin = exists $opts->{stdin}
191 2 ▶ ? ( defined $opts->{stdin} ? "$opts->{stdin}" : '' )
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'stdin'} ? : 1 1 2
defined $opts->{'stdin'} ? : 1 0 1
192 : '';
193 2 my $capture_stdout = zuzu_bool( $opts->{capture_stdout}, 1 );
194 2 my $capture_stderr = zuzu_bool( $opts->{capture_stderr}, 1 );
195 2 my $merge_stderr = zuzu_bool( $opts->{merge_stderr}, 0 );
196 2 ▶ my $timeout = defined $opts->{timeout} ? 0 + $opts->{timeout} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'timeout'} ? : 0 2 2
197  
198 2 my $stdout = '';
199 2 my $stderr = '';
200 2 ▶ my $out_ref = $capture_stdout ? \$stdout : undef;
Branch: 1 branch
BranchTrueFalseTotal
$capture_stdout ? : 2 0 2
201 2 my $err_ref;
202 2 ▶ if ( $merge_stderr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merge_stderr) { } 0 2 2
203 0 $err_ref = $out_ref;
204 }
205 else {
206 2 ▶ $err_ref = $capture_stderr ? \$stderr : undef;
Branch: 1 branch
BranchTrueFalseTotal
$capture_stderr ? : 2 0 2
207 }
208  
209 2 my $error;
210 2 my $timed_out = 0;
211 2 my $ran_process = 0;
212 2 my %old_env;
213 my @unset_keys;
214 2 my $had_env = 0;
215 2 my $old_cwd;
216 2 my $had_cwd = 0;
217  
218 2 ▶ my $env = exists $opts->{env} ? $opts->{env} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'env'} ? : 0 2 2
219 2 ▶ if ( ref($env) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $env eq "HASH") 0 2 2
220 0 $had_env = 1;
221 0 for my $key ( sort CORE::keys %{ $env } ) {
222 0 ▶ if ( exists $ENV{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{$key}) { } 0 0 0
223 0 $old_env{$key} = $ENV{$key};
224 }
225 else {
226 0 push @unset_keys, $key;
227 }
228 0 ▶ if ( defined $env->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $env->{$key}) { } 0 0 0
229 0 $ENV{$key} = "$env->{$key}";
230 }
231 else {
232 0 delete $ENV{$key};
233 }
234 }
235 }
236  
237 2 ▶ if ( exists $opts->{cwd} and defined $opts->{cwd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"cwd"} and defined $opts->{"cwd"}) 0 2 2
Condition33%1/3
exists $opts->{"cwd"} and defined $opts->{"cwd"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $opts->{"cwd"} and defined $opts->{"cwd"}
exists $opts->{"cwd"} defined $opts->{"cwd"}
Truth table33%1/3
A and B
A= exists $opts->{"cwd"}B= defined $opts->{"cwd"}
ABresult
0X0
100
111
238 0 $had_cwd = 1;
239 0 $old_cwd = getcwd();
240 0 my $cwd = "$opts->{cwd}";
241 0 ▶ if ( !chdir $cwd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $cwd) 0 0 0
242 0 $error = "could not change cwd to $cwd: $!";
243 }
244 }
245  
246 eval {
247 2 ▶ if ( !defined $error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $error) 2 0 2
248 local $SIG{ALRM} = sub {
249 0 ▶ $timed_out = 1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
250 0 die "run timeout\n";
251 2 };
252 2 ▶ alarm $timeout if $timeout > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > 0 0 2 2
253 2 $ran_process = 1;
254 2 my @run_spec = ( $cmd, '<', \$stdin );
255 2 ▶ push @run_spec, '>', $out_ref if $capture_stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $capture_stdout 2 0 2
256 2 ▶ if ( $merge_stderr ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($merge_stderr) { } 0 2 2
elsif ($capture_stderr) { } 2 0 2
257 0 push @run_spec, '2>&1';
258 }
259 elsif ( $capture_stderr ) {
260 2 push @run_spec, '2>', $err_ref;
261 }
262 2 run(@run_spec);
263 2 ▶ alarm 0 if $timeout > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > 0 0 2 2
264 }
265 2 1;
266 2 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { unless (defined $error) { local $SIG{"ALRM"} = sub { $timed_out = 1; die "run timeout\n"; } ; alarm $timeout if $timeout > 0; $ran_process = 1; my(@run_spec) = ($cmd, "<", \$stdin); push @run_spec, ">", $out_ref if $capture_stdout; if ($merge_stderr) { push @run_spec, "2>&1"; } elsif ($capture_stderr) { push @run_spec, "2>", $err_ref; } ; run(@run_spec); alarm 0 if $timeout > 0; } ; 1 } } or do { $error = "$@"; alarm 0 if $timeout > 0 } 0 2 2
267 0 $error = "$@";
268 0 ▶ alarm 0 if $timeout > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > 0 0 0 0
269 };
270  
271 2 ▶ if ( $had_cwd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_cwd) 0 2 2
272 chdir $old_cwd
273 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
chdir $old_cwd or do { my $restore_error = "could not restore cwd to ${old_cwd}: $!"; $error = defined $error && $error ne "" ? "$error; $restore_error" : $restore_error } 0 0 0
274 0 my $restore_error =
275 "could not restore cwd to $old_cwd: $!";
276 0 ▶ $error = defined $error && $error ne ''
Branch: 1 branch
BranchTrueFalseTotal
defined $error && $error ne '' ? : 0 0 0
Condition0%0/3
defined $error and $error ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error and $error ne ""
defined $error $error ne ""
Truth table0%0/3
A and B
A= defined $errorB= $error ne ""
ABresult
0X0
100
111
277 ? "$error; $restore_error"
278 : $restore_error;
279 };
280 }
281  
282 2 ▶ if ( $had_env ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_env) 0 2 2
283 0 for my $key ( sort CORE::keys %old_env ) {
284 0 $ENV{$key} = $old_env{$key};
285 }
286 0 for my $key ( @unset_keys ) {
287 0 delete $ENV{$key};
288 }
289 }
290  
291 2 my $status = $?;
292 2 ▶ $status = 255 << 8
Branch: 1 branch
BranchTrueFalseTotal
if not $ran_process and defined $error and $error ne "" 0 2 2
Condition33%2/6
not $ran_process and defined $error and $error ne ""
!ll&&!rl&&r
200
not $ran_process and defined $error
!ll&&!rl&&r
200
MC/DC0%0/3
not $ran_process and defined $error and $error ne ""
not $ran_process defined $error $error ne ""
Truth table25%1/4
not(A) and B and C
A= not $ran_processB= defined $errorC= $error ne ""
ABCresult
0XX0
10X0
1100
1111
293 if !$ran_process and defined $error and $error ne '';
294 2 my $exit_code = $status >> 8;
295 2 my $signal = $status & 127;
296 2 ▶ my $core_dump = ( $status & 128 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status & 128 ? : 0 2 2
297 2 ▶ if ( $timed_out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timed_out) 0 2 2
298 0 ▶ $signal = 14 if $signal == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $signal == 0 0 0 0
299 0 $error = "timeout after ${timeout}s";
300 }
301  
302 2 ▶ my $result = {
Branch: 3 branches
BranchTrueFalseTotal
$capture_stdout ? : 2 0 2
$capture_stderr ? : 2 0 2
$timed_out ? : 0 2 2
303 command => $cmd,
304 exit_code => $exit_code,
305 signal => $signal,
306 core_dump => $core_dump,
307 ok => 0,
308 stdout => $capture_stdout ? $stdout : undef,
309 stderr => $capture_stderr ? $stderr : undef,
310 error => $error,
311 timed_out => $timed_out ? 1 : 0,
312 };
313 2 $result->{ok} = _result_ok($result);
314  
315 2 return $result;
316 }
317  
318 sub _run_pipeline_legacy {
319 0 ▶ my ( $items, $opts ) = @_;
Subroutine _run_pipeline_legacy: not called CC=5 SCAR=34.0
320  
321 0 my @steps;
322 0 ▶ my $stdin = exists $opts->{stdin} ? $opts->{stdin} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'stdin'} ? : 0 0 0
323 0 for my $command ( @{ $items } ) {
324 0 my $cmd = _as_command_array( zuzu_to_perl($command), [] );
325 0 my %step_opts = %{ $opts };
326 0 $step_opts{stdin} = $stdin;
327 0 $step_opts{capture_stdout} = 1;
328 0 my $result = _run_command( $cmd, \%step_opts );
329 0 push @steps, $result;
330 0 ▶ $stdin = defined $result->{stdout} ? $result->{stdout} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $result->{'stdout'} ? : 0 0 0
331 0 ▶ last if not $result->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->{"ok"} 0 0 0
332 }
333  
334 0 return _pipeline_result( \@steps );
335 }
336  
337 sub _run_pipeline_true_async {
338 0 ▶ my ( $items, $opts ) = @_;
Subroutine _run_pipeline_true_async: not called CC=36 SCAR=71.9
339  
340 0 my @cmds = map { _as_command_array( zuzu_to_perl($_), [] ) } @{ $items };
341 0 ▶ return _pipeline_result( [] ) if !@cmds;
Branch: 1 branch
BranchTrueFalseTotal
unless @cmds 0 0 0
342  
343 0 my $capture_stderr = zuzu_bool( $opts->{capture_stderr}, 1 );
344 0 my $merge_stderr = zuzu_bool( $opts->{merge_stderr}, 0 );
345 my $stdin = exists $opts->{stdin}
346 0 ▶ ? ( defined $opts->{stdin} ? "$opts->{stdin}" : '' )
Branch: 2 branches
BranchTrueFalseTotal
exists $opts->{'stdin'} ? : 0 0 0
defined $opts->{'stdin'} ? : 0 0 0
347 : '';
348 0 ▶ my $timeout_seconds = defined $opts->{timeout} ? 0 + $opts->{timeout} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'timeout'} ? : 0 0 0
349 0 my @stderr = map { '' } @cmds;
350 0 my $final_stdout = '';
351 0 my @tee_files;
352 my @original_process_ix;
353 0 my @spec;
354 0 my $process_ix = 0;
355  
356 0 for my $ix ( 0 .. $#cmds ) {
357 0 push @spec, $cmds[$ix];
358 0 push @original_process_ix, $process_ix++;
359 0 ▶ if ( $ix == 0 and length $stdin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix == 0 and length $stdin) 0 0 0
Condition0%0/3
$ix == 0 and length $stdin
!ll&&!rl&&r
000
MC/DC0%0/2
$ix == 0 and length $stdin
$ix == 0 length $stdin
Truth table0%0/3
A and B
A= $ix == 0B= length $stdin
ABresult
0X0
100
111
360 0 push @spec, '<', \$stdin;
361 }
362 0 ▶ if ( $merge_stderr ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($merge_stderr) { } 0 0 0
elsif ($capture_stderr) { } 0 0 0
363 0 push @spec, '2>&1';
364 }
365 elsif ( $capture_stderr ) {
366 0 push @spec, '2>', \$stderr[$ix];
367 }
368 0 ▶ if ( $ix < $#cmds ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < $#cmds) 0 0 0
369 0 my ( $fh, $path ) = tempfile(
370 'zuzu-proc-pipeline-XXXXXX',
371 TMPDIR => 1,
372 UNLINK => 0,
373 );
374 0 close $fh;
375 0 push @tee_files, $path;
376 0 push @spec, '|', [ $^X, '-e', $TEE_CODE, $path ], '2>', \my $tee_err;
377 0 $process_ix++;
378 0 push @spec, '|';
379 }
380 }
381 0 push @spec, '>', \$final_stdout;
382 0 ▶ push @spec, timeout( $timeout_seconds, exception => 'pipeline timeout' )
Branch: 1 branch
BranchTrueFalseTotal
if $timeout_seconds > 0 0 0 0
383 if $timeout_seconds > 0;
384  
385 0 my $h = harness(@spec);
386 0 my %old_env;
387 my @unset_keys;
388 0 my $had_env = 0;
389 0 my $old_cwd;
390 0 my $had_cwd = 0;
391 0 my $error;
392 0 ▶ my $env = exists $opts->{env} ? $opts->{env} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'env'} ? : 0 0 0
393 0 ▶ if ( ref($env) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $env eq "HASH") 0 0 0
394 0 $had_env = 1;
395 0 for my $key ( sort CORE::keys %{ $env } ) {
396 0 ▶ if ( exists $ENV{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{$key}) { } 0 0 0
397 0 $old_env{$key} = $ENV{$key};
398 }
399 else {
400 0 push @unset_keys, $key;
401 }
402 0 ▶ if ( defined $env->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $env->{$key}) { } 0 0 0
403 0 $ENV{$key} = "$env->{$key}";
404 }
405 else {
406 0 delete $ENV{$key};
407 }
408 }
409 }
410  
411 0 ▶ if ( exists $opts->{cwd} and defined $opts->{cwd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"cwd"} and defined $opts->{"cwd"}) 0 0 0
Condition0%0/3
exists $opts->{"cwd"} and defined $opts->{"cwd"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"cwd"} and defined $opts->{"cwd"}
exists $opts->{"cwd"} defined $opts->{"cwd"}
Truth table0%0/3
A and B
A= exists $opts->{"cwd"}B= defined $opts->{"cwd"}
ABresult
0X0
100
111
412 0 $had_cwd = 1;
413 0 $old_cwd = getcwd();
414 0 my $cwd = "$opts->{cwd}";
415 0 ▶ if ( !chdir $cwd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $cwd) 0 0 0
416 0 $error = "could not change cwd to $cwd: $!";
417 }
418 }
419  
420 0 my $timed_out = 0;
421 0 my $ok = eval {
422 0 ▶ $h->run if !defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
423 0 1;
424 };
425 0 ▶ if ( $had_cwd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_cwd) 0 0 0
426 chdir $old_cwd
427 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
chdir $old_cwd or do { my $restore_error = "could not restore cwd to ${old_cwd}: $!"; $error = defined $error && $error ne "" ? "$error; $restore_error" : $restore_error; $ok = 0 } 0 0 0
428 0 my $restore_error =
429 "could not restore cwd to $old_cwd: $!";
430 0 ▶ $error = defined $error && $error ne ''
Branch: 1 branch
BranchTrueFalseTotal
defined $error && $error ne '' ? : 0 0 0
Condition0%0/3
defined $error and $error ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error and $error ne ""
defined $error $error ne ""
Truth table0%0/3
A and B
A= defined $errorB= $error ne ""
ABresult
0X0
100
111
431 ? "$error; $restore_error"
432 : $restore_error;
433 0 $ok = 0;
434 };
435 }
436 0 ▶ if ( $had_env ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_env) 0 0 0
437 0 for my $key ( sort CORE::keys %old_env ) {
438 0 $ENV{$key} = $old_env{$key};
439 }
440 0 for my $key ( @unset_keys ) {
441 0 delete $ENV{$key};
442 }
443 }
444 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
445 0 my $eval_error = "$@";
446 0 ▶ $error = $eval_error if $eval_error ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $eval_error ne "" 0 0 0
447 0 ▶ $timed_out = $error =~ /pipeline timeout|timed out/i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$error =~ /pipeline timeout|timed out/i ? : 0 0 0
448 0 eval { $h->kill_kill; 1 };
449 }
450  
451 0 my @stdout = map { '' } @cmds;
452 0 for my $ix ( 0 .. $#tee_files ) {
453 0 ▶ if ( open my $fh, '<', $tee_files[$ix] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $tee_files[$ix]) 0 0 0
454 0 local $/;
455 0 $stdout[$ix] = <$fh>;
456 0 close $fh;
457 }
458 0 unlink $tee_files[$ix];
459 }
460 0 $stdout[-1] = $final_stdout;
461  
462 0 my @steps;
463 0 for my $ix ( 0 .. $#cmds ) {
464 0 ▶ if ( $timed_out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timed_out) 0 0 0
465 0 push @steps, _timeout_result( $cmds[$ix], $opts );
466 0 next;
467 }
468 0 my $status = eval {
469 0 $h->full_result( $original_process_ix[$ix] );
470 };
471 0 ▶ $status = 1 << 8 if !defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 0 0
472 push @steps, _result_from_wait_status(
473 $cmds[$ix],
474 {
475 0 %{ $opts },
476 capture_stdout => 1,
477 },
478 $status,
479 $stdout[$ix],
480 $stderr[$ix],
481 $error,
482 0,
483 );
484 }
485  
486 0 return _pipeline_result( \@steps );
487 }
488  
489 sub _async_task {
490 3 ▶ my ( $runtime, $name, $work, $wrap ) = @_;
Subroutine _async_task: called CC=1 SCAR=0.0
491  
492 3 my $worker = $runtime->_new_task(
493 name => "$name.worker",
494 start => 1,
495 schedule => 1,
496 thunk => $work,
497 );
498 return $runtime->_new_task(
499 name => $name,
500 schedule => 1,
501 thunk => sub {
502 3 ▶ my $value = $worker->await;
Subroutine __ANON__: called CC=2 SCAR=7.2
503 3 ▶ return defined $wrap ? $wrap->($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $wrap ? : 3 0 3
504 },
505 3 );
506 }
507  
508 sub _warn_blocking_operation {
509 2 ▶ my ( $runtime, $operation ) = @_;
Subroutine _warn_blocking_operation: called CC=2 SCAR=7.1
510  
511 2 ▶ $runtime->_warn_blocking_operation($operation)
Branch: 1 branch
BranchTrueFalseTotal
if $runtime->can("_warn_blocking_operation") 2 0 2
512 if $runtime->can('_warn_blocking_operation');
513  
514 2 return;
515 }
516  
517 sub _pipeline_async_legacy_native {
518 0 ▶ my ( $runtime ) = @_;
Subroutine _pipeline_async_legacy_native: not called CC=1 SCAR=6.9
519  
520 return native_function(
521 name => 'pipeline_async',
522 native => sub {
523 0 ▶ my ( $self, $commands, $options ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
524 0 my $items = zuzu_to_perl( $commands );
525 0 ▶ $items = [] if ref($items) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $items ne "ARRAY" 0 0 0
526 0 my $opts = zuzu_to_perl( $options );
527 0 ▶ $opts = {} if ref($opts) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 0 0
528  
529 return _async_task(
530 $runtime,
531 'proc.pipeline_async',
532 sub {
533 0 ▶ return _run_pipeline_legacy( $items, $opts );
Subroutine __ANON__: not called CC=1 SCAR=6.9
534 },
535 sub {
536 0 ▶ my ( $result ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
537 0 return perl_to_zuzu($result);
538 },
539 0 );
540 },
541 0 );
542 }
543  
544 sub _pipeline_async_true_native {
545 9 ▶ my ( $runtime ) = @_;
Subroutine _pipeline_async_true_native: called CC=1 SCAR=0.1
546  
547 return native_function(
548 name => 'pipeline_async',
549 native => sub {
550 1 ▶ my ( $self, $commands, $options ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.3
551 1 my $items = zuzu_to_perl( $commands );
552 1 ▶ $items = [] if ref($items) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $items ne "ARRAY" 0 1 1
553 1 my $opts = zuzu_to_perl( $options );
554 1 ▶ $opts = {} if ref($opts) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 1 1
555  
556 return _async_task(
557 $runtime,
558 'proc.pipeline_async',
559 sub {
560 0 ▶ return _run_pipeline_true_async( $items, $opts );
Subroutine __ANON__: not called CC=1 SCAR=6.9
561 },
562 sub {
563 1 ▶ my ( $result ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
564 1 return perl_to_zuzu($result);
565 },
566 1 );
567 },
568 9 );
569 }
570  
571 sub IMPORT {
572 9 ▶ my ( $class, $runtime ) = @_;
Subroutine IMPORT: called CC=2 SCAR=8.7
Pod undocumented
573  
574 9 my $proc_class = native_class(
575 name => 'Proc',
576 );
577  
578 9 my $env_class = native_class(
579 name => 'Env',
580 );
581  
582 $proc_class->static_methods->{pid} = native_function(
583 name => 'pid',
584 native => sub {
585 2 ▶ return 0 + $$;
Subroutine __ANON__: called CC=1 SCAR=0.0
586 },
587 9 );
588  
589  
590 $env_class->static_methods->{get} = native_function(
591 name => 'get',
592 native => sub {
593 1 ▶ my ( $self, $name, $default ) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.5
594 1 ▶ my $key = defined $name ? "$name" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 1 0 1
595 1 ▶ return $ENV{$key} if exists $ENV{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$key} 1 0 1
596 0 return $default;
597 },
598 9 );
599  
600 $env_class->static_methods->{set} = native_function(
601 name => 'set',
602 native => sub {
603 1 ▶ my ( $self, $name, $value ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.4
604 1 ▶ my $key = defined $name ? "$name" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 1 0 1
605 1 ▶ $ENV{$key} = defined $value ? "$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 1 0 1
606 1 return $ENV{$key};
607 },
608 9 );
609  
610 $env_class->static_methods->{remove} = native_function(
611 name => 'remove',
612 native => sub {
613 2 ▶ my ( $self, $name ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
614 2 ▶ my $key = defined $name ? "$name" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
615 2 delete $ENV{$key};
616 2 return undef;
617 },
618 9 );
619  
620 $proc_class->static_methods->{run} = native_function(
621 name => 'run',
622 native => sub {
623 2 ▶ my ( $self, $command, $argv, $options ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
624 2 _warn_blocking_operation( $runtime, 'std/proc Proc.run' );
625  
626 2 my $args = zuzu_to_perl( $argv );
627 2 ▶ $args = [] if ref($args) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args ne "ARRAY" 0 2 2
628  
629 2 my $opts = zuzu_to_perl( $options );
630 2 ▶ $opts = {} if ref($opts) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 1 1 2
631  
632 2 my $cmd = _as_command_array( zuzu_to_perl($command), $args );
633 2 my $result = _run_command( $cmd, $opts );
634 2 return perl_to_zuzu($result);
635 },
636 9 );
637  
638 $proc_class->static_methods->{run_async} = native_function(
639 name => 'run_async',
640 native => sub {
641 2 ▶ my ( $self, $command, $argv, $options ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.3
642  
643 2 my $args = zuzu_to_perl( $argv );
644 2 ▶ $args = [] if ref($args) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args ne "ARRAY" 0 2 2
645  
646 2 my $opts = zuzu_to_perl( $options );
647 2 ▶ $opts = {} if ref($opts) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 2 0 2
648  
649 2 my $cmd = _as_command_array( zuzu_to_perl($command), $args );
650 return _async_task(
651 $runtime,
652 'proc.run_async',
653 sub {
654 0 ▶ return _run_command( $cmd, $opts );
Subroutine __ANON__: not called CC=1 SCAR=6.9
655 },
656 sub {
657 2 ▶ my ( $result ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
658 2 return perl_to_zuzu($result);
659 },
660 2 );
661 },
662 9 );
663  
664 $proc_class->static_methods->{pipeline} = native_function(
665 name => 'pipeline',
666 native => sub {
667 0 ▶ my ( $self, $commands, $options ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
668 0 _warn_blocking_operation( $runtime, 'std/proc Proc.pipeline' );
669 0 my $items = zuzu_to_perl( $commands );
670 0 ▶ $items = [] if ref($items) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $items ne "ARRAY" 0 0 0
671 0 my $opts = zuzu_to_perl( $options );
672 0 ▶ $opts = {} if ref($opts) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 0 0
673  
674 0 return perl_to_zuzu( _run_pipeline_legacy( $items, $opts ) );
675 },
676 9 );
677  
678 $proc_class->static_methods->{pipeline_async} =
679 9 ▶ _platform_supports_true_pipeline_async()
Branch: 1 branch
BranchTrueFalseTotal
_platform_supports_true_pipeline_async() ? : 9 0 9
680 ? _pipeline_async_true_native($runtime)
681 : _pipeline_async_legacy_native($runtime);
682  
683 $proc_class->static_methods->{is_success} = native_function(
684 name => 'is_success',
685 native => sub {
686 0 ▶ my ( $self, $result ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
687 0 my $perl = zuzu_to_perl($result);
688 0 ▶ return _result_ok($perl) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_result_ok($perl) ? : 0 0 0
689 },
690 9 );
691  
692 $proc_class->static_methods->{status_text} = native_function(
693 name => 'status_text',
694 native => sub {
695 0 ▶ my ( $self, $result ) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
696 0 my $perl = zuzu_to_perl($result);
697 0 ▶ return 'invalid result' if ref($perl) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $perl ne "HASH" 0 0 0
698 0 ▶ if ( defined $perl->{error} and $perl->{error} ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $perl->{"error"} and $perl->{"error"} ne "") 0 0 0
Condition0%0/3
defined $perl->{"error"} and $perl->{"error"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $perl->{"error"} and $perl->{"error"} ne ""
defined $perl->{"error"} $perl->{"error"} ne ""
Truth table0%0/3
A and B
A= defined $perl->{"error"}B= $perl->{"error"} ne ""
ABresult
0X0
100
111
699 0 return "error: $perl->{error}";
700 }
701 0 ▶ if ( ( $perl->{signal} // 0 ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($perl->{"signal"} // 0) != 0) 0 0 0
Condition0%0/2
$perl->{"signal"} // 0
l!l
00
MC/DC0%0/1
$perl->{"signal"} // 0
$perl->{"signal"}
Truth table0%0/2
A
A= $perl->{"signal"}
Aresult
11
00
702 0 return "signal $perl->{signal}";
703 }
704 0 return "exit $perl->{exit_code}";
705 },
706 9 );
707  
708 $proc_class->static_methods->{kill} = native_function(
709 name => 'kill',
710 native => sub {
711 1 ▶ my ( $self, $signal_name, $pid ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
712 1 my $signal = _normalize_signal_name( $signal_name );
713 1 ▶ my $target = defined $pid ? 0 + $pid : 0 + $$;
Branch: 1 branch
BranchTrueFalseTotal
defined $pid ? : 1 0 1
714 1 my $count = CORE::kill( $signal, $target );
715 1 return $count;
716 },
717 9 );
718  
719 $proc_class->static_methods->{onsignal} = native_function(
720 name => 'onsignal',
721 native => sub {
722 1 ▶ my ( $self, $signal_name, $callback ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
723 1 my $signal = _normalize_signal_name( $signal_name );
724 $SIGNAL_CALLBACKS{$signal} = []
725 1 ▶ if not exists $SIGNAL_CALLBACKS{$signal};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $SIGNAL_CALLBACKS{$signal} 1 0 1
726 1 push @{ $SIGNAL_CALLBACKS{$signal} }, $callback;
727 1 _install_onsignal_handler( $runtime, $signal );
728 1 return scalar @{ $SIGNAL_CALLBACKS{$signal} };
729 },
730 9 );
731  
732 $proc_class->static_methods->{exit} = native_function(
733 name => 'exit',
734 native => sub {
735 1 ▶ my ( $self, $code ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
736 1 ▶ my $exit_code = defined $code ? 0 + $code : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $code ? : 1 0 1
737 1 CORE::exit( $exit_code );
738 },
739 9 );
740  
741 my $sleep_fn = native_function(
742 name => 'sleep',
743 native => sub {
744 0 ▶ my ( $seconds ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
745 0 _warn_blocking_operation( $runtime, 'std/proc sleep' );
746 0 ▶ my $duration = defined $seconds ? 0 + $seconds : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $seconds ? : 0 0 0
747 0 ▶ $duration = 0 if $duration < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $duration < 0 0 0 0
748 0 sleep($duration);
749 0 return undef;
750 },
751 9 );
752  
753 my $sleep_async_fn = native_function(
754 name => 'sleep_async',
755 native => sub {
756 0 ▶ my ( $seconds ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
757 0 ▶ my $duration = defined $seconds ? 0 + $seconds : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $seconds ? : 0 0 0
758 0 ▶ $duration = 0 if $duration < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $duration < 0 0 0 0
759 0 return $runtime->_new_task(
760 name => 'proc.sleep_async',
761 status => 'sleeping',
762 ready_at => time + $duration,
763 );
764 },
765 9 );
766  
767 return {
768 9 Proc => $proc_class,
769 Env => $env_class,
770 sleep => $sleep_fn,
771 sleep_async => $sleep_async_fn,
772 };
773 }
774  
775 6 1;
776  
777 =pod
778  
779 =head1 NAME
780  
781 Zuzu::Module::Proc - std/proc bindings for ZuzuScript.
782  
783 =head1 DESCRIPTION
784  
785 Implements C<std/proc>, exporting C<Proc>, C<Env>, and C<sleep>.
786  
787 =head1 CLASSES
788  
789 =head2 Env
790  
791 Static helpers for reading and mutating process environment
792 variables.
793  
794 =over
795  
796 =item * C<get(name, default?)>
797  
798 Reads an environment variable. Returns C<default> (or null) when
799 not set.
800  
801 =item * C<set(name, value)>
802  
803 Sets an environment variable and returns the new value.
804  
805 =item * C<remove(name)>
806  
807 Unsets an environment variable.
808  
809 =back
810  
811 =head2 Proc
812  
813 Static helpers for interacting with operating-system processes.
814  
815 =over
816  
817 =item * C<pid>
818  
819 Returns the current process ID.
820  
821  
822 =item * C<run(command, argv?, options?)>
823  
824 Runs an external process with C<IPC::Run>. Returns a Dict with
825 C<command>, C<exit_code>, C<signal>, C<core_dump>, C<ok>,
826 C<stdout>, C<stderr>, and C<error>.
827  
828 C<command> may be a string or an array-style command. C<argv>
829 provides additional arguments when C<command> is a string.
830  
831 Options currently supported:
832  
833 =over
834  
835 =item * C<stdin>
836  
837 =item * C<capture_stdout> (default true)
838  
839 =item * C<capture_stderr> (default true)
840  
841 =item * C<merge_stderr> (default false)
842  
843 =item * C<cwd>
844  
845 =back
846  
847 =item * C<kill(signal, pid?)>
848  
849 Sends a signal. PID defaults to the current process.
850  
851 =item * C<onsignal(signal, callback)>
852  
853 Registers a callback function to run when that signal is received.
854  
855 =item * C<exit(code)>
856  
857 Immediately exits the current process with the provided status code.
858  
859 =back
860  
861 =head2 sleep
862  
863 Function:
864  
865 =over
866  
867 =item * C<sleep(seconds)>
868  
869 Blocks the current process for the requested number of seconds. Fractional
870 seconds are supported.
871  
872 =back
873  
874 =head1 COPYRIGHT AND LICENCE
875  
876 B<< Zuzu::Module::Proc >> is copyright Toby Inkster.
877  
878 It is free software; you may redistribute it and/or modify it under
879 the terms of either the Artistic License 1.0 or the GNU General Public
880 License version 2.
881  
882 =cut
« blib/lib/Zuzu/Module/String/Encode.pm ↑ Summary blib/lib/Zuzu/Module/Marshal.pm »