lib/IPC/Open3/Utils.pm

filter: Statementstmt 79.1% 148 / 187 Branchbran 66.2% 98 / 148 Conditioncond 55.5% 30 / 54 MC/DCmcdc 21.8% 7 / 32 Subroutinesub 73.6% 14 / 19 Podpod 100% 8 / 8 totaltotal 68.0% 305 / 448 CC 97 SCAR 53.0
CC
97
Cov
71%
run_cmd
312.4
__ANON__
7.0
put_cmd_in
6.0
CRAP 199.7
↑ Summary t/ipc_opens_utils_testing.perl »
1 package IPC::Open3::Utils;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 $IPC::Open3::Utils::VERSION = '0.92';
7  
8 4 require Exporter;
9 4 @IPC::Open3::Utils::ISA = qw(Exporter);
10 4 @IPC::Open3::Utils::EXPORT = qw(run_cmd put_cmd_in);
11 4 @IPC::Open3::Utils::EXPORT_OK = qw(
12 run_cmd put_cmd_in
13 child_error_ok child_error_failed_to_execute
14 child_error_exit_signal child_error_seg_faulted
15 child_error_core_dumped child_error_exit_value
16 create_ipc_open3_utils_wrap_script
17 );
18 4 %IPC::Open3::Utils::EXPORT_TAGS = (
19 'all' => \@IPC::Open3::Utils::EXPORT_OK,
20 'cmd' => [qw(run_cmd put_cmd_in)],
21 'err' => [
22 qw(
23 child_error_ok child_error_failed_to_execute
24 child_error_exit_signal child_error_seg_faulted
25 child_error_core_dumped child_error_exit_value
26 )
27 ],
28 );
29  
30 4 require IO::Select;
31 4 require IPC::Open3;
32 4 require IO::Handle;
33  
34 35 ▶sub run_cmd {
Subroutine run_cmd: called CC=73 SCAR=57.4
Pod documented
35 35 my @cmd = @_;
36 35 ▶ my $arg_hr = ref $cmd[-1] eq 'HASH' ? pop(@cmd) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $cmd[-1] eq 'HASH' ? : 35 0 35
37 35 ▶ $arg_hr->{'ignore_handle'} ||= '';
Condition100%2/2
$arg_hr->{"ignore_handle"} ||= ""
l!l
332
MC/DC100%1/1
$arg_hr->{"ignore_handle"} ||= ""
$arg_hr->{"ignore_handle"}
Truth table100%2/2
A
A= $arg_hr->{"ignore_handle"}
Aresult
11
00
38  
39 35 ▶ if ( ref $arg_hr->{'handler'} ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg_hr->{"handler"} ne "CODE") 2 33 35
40 0 ▶ $arg_hr->{'handler'} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 0 my ( $cur_line, $stdin, $is_stderr, $is_open3_err, $short_circuit_loop_sr ) = @_;
42 0 ▶ if ($is_stderr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_stderr) { } 0 0 0
43 0 print STDERR $cur_line;
44 }
45 else {
46 0 print STDOUT $cur_line;
47 }
48  
49 0 return 1;
50 2 };
51 }
52  
53 35 my $stdout = IO::Handle->new();
54 35 my $stderr = IO::Handle->new(); # TODO ? $arg_hr->{'combine_fhs'} ? $stdout : IO::Handle->new(); && then no select()
55 35 my $stdin = IO::Handle->new();
56 35 my $sel = IO::Select->new();
57  
58 35 ▶ if ( ref $arg_hr->{'autoflush'} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg_hr->{"autoflush"} eq "HASH") 1 34 35
59 1 ▶ $stdout->autoflush(1) if $arg_hr->{'autoflush'}{'stdout'};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hr->{"autoflush"}{"stdout"} 1 0 1
60 1 ▶ $stderr->autoflush(1) if $arg_hr->{'autoflush'}{'stderr'};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hr->{"autoflush"}{"stderr"} 1 0 1
61 1 ▶ $stdin->autoflush(1) if $arg_hr->{'autoflush'}{'stdin'};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hr->{"autoflush"}{"stdin"} 0 1 1
62 }
63  
64 # this is a hack to work around an exit-before-use race condition
65 35 ▶ local $SIG{'PIPE'} = exists $SIG{'PIPE'} && defined $SIG{'PIPE'} ? $SIG{'PIPE'} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $SIG{'PIPE'} && defined $SIG{'PIPE'} ? : 0 35 35
Condition33%1/3
exists $SIG{"PIPE"} and defined $SIG{"PIPE"}
!ll&&!rl&&r
0350
MC/DC0%0/2
exists $SIG{"PIPE"} and defined $SIG{"PIPE"}
exists $SIG{"PIPE"} defined $SIG{"PIPE"}
Truth table33%1/3
A and B
A= exists $SIG{"PIPE"}B= defined $SIG{"PIPE"}
ABresult
0X0
100
111
66 35 my $current_sig_pipe = $SIG{'PIPE'};
67 35 ▶ if ( exists $arg_hr->{'pre_read_print_to_stdin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_hr->{"pre_read_print_to_stdin"}) 7 28 35
68 2 ▶ $SIG{'PIPE'} = sub {
Subroutine __ANON__: called CC=5 SCAR=19.4
69  
70 # my $oserr = $!;
71 # my $cherr = $?;
72 2 ▶ $stdin->close if defined $stdin && ref $stdin eq 'IO::Handle'; # && !$arg_hr->{'close_stdin'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin and ref $stdin eq "IO::Handle" 2 0 2
Condition33%1/3
defined $stdin and ref $stdin eq "IO::Handle"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $stdin and ref $stdin eq "IO::Handle"
defined $stdin ref $stdin eq "IO::Handle"
Truth table33%1/3
A and B
A= defined $stdinB= ref $stdin eq "IO::Handle"
ABresult
0X0
100
111
73 2 $stdout->close;
74 2 $stderr->close;
75  
76 # $! = $oserr;
77 # $? = $cherr;
78 2 ▶ $current_sig_pipe->() if $current_sig_pipe && ref $current_sig_pipe eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $current_sig_pipe and ref $current_sig_pipe eq "CODE" 0 2 2
Condition33%1/3
$current_sig_pipe and ref $current_sig_pipe eq "CODE"
!ll&&!rl&&r
200
MC/DC0%0/2
$current_sig_pipe and ref $current_sig_pipe eq "CODE"
$current_sig_pipe ref $current_sig_pipe eq "CODE"
Truth table33%1/3
A and B
A= $current_sig_pipeB= ref $current_sig_pipe eq "CODE"
ABresult
0X0
100
111
79 7 };
80 }
81  
82 # ensure these are always re-set at the beginning of an execution
83 35 $! = 0;
84 35 $? = 0;
85  
86 35 my $child_pid;
87 35 eval { $child_pid = IPC::Open3::open3( $stdin, $stdout, $stderr, @cmd ) };
88 35 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 11 24 35
89 11 ▶ if ( $@ =~ m{not enough arguments} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /not enough arguments/) { } 2 9 11
elsif ($@ =~ /open3: exec of .* failed\b/) { } 9 0 9
90 2 $! = 22; # Invalid argument
91 2 $? = 65280; # system();print $?;
92 }
93 elsif ( $@ =~ m{open3: exec of .* failed\b} ) {
94 9 $? = -1;
95 }
96  
97 11 ▶ if ( ref $arg_hr->{'open3_error'} eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg_hr->{'open3_error'} eq 'SCALAR') { } 4 7 11
98 4 ${ $arg_hr->{'open3_error'} } = $@;
99 }
100 else {
101 7 $arg_hr->{'open3_error'} = $@;
102 }
103  
104 11 ▶ if ( $arg_hr->{'carp_open3_errors'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{"carp_open3_errors"}) 0 11 11
105 0 require Carp;
106 0 Carp::carp($@);
107 }
108  
109 11 return;
110 }
111  
112 24 ▶ $arg_hr->{'timeout'} = exists $arg_hr->{'timeout'} ? abs( $arg_hr->{'timeout'} ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_hr->{'timeout'} ? : 1 23 24
113  
114 24 my $alarm;
115 my $original_alarm;
116  
117 # small hack to avoid uninitialized value warnings w/ out lots of warning.pm voo-doo to
118 # keep the "no warnings 'uninitialized'" scoped to this assignment but the local() scoped from here on
119 # local $SIG{'ALRM'} = $SIG{'ALRM'};# this gives uninitialized value warnings
120 24 my $no_unit_warnings = $SIG{'ALRM'};
121 24 ▶ local $SIG{'ALRM'} ||= '';
Condition50%1/2
local $SIG{"ALRM"} ||= ""
l!l
024
MC/DC0%0/1
local $SIG{"ALRM"} ||= ""
local $SIG{"ALRM"}
Truth table50%1/2
A
A= local $SIG{"ALRM"}
Aresult
11
00
122 24 ▶ if ( $arg_hr->{'timeout'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{'timeout'}) { } 0 24 24
123 0 ▶ if ( $arg_hr->{'timeout_is_microseconds'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{'timeout_is_microseconds'}) { } 0 0 0
124 0 ▶ if ( defined &Time::HiRes::ualarm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Time::HiRes::ualarm) { } 0 0 0
125 0 $alarm = \&Time::HiRes::ualarm;
126 }
127 else {
128 0 ▶ $alarm = defined &Time::HiRes::alarm ? \&Time::HiRes::alarm : sub { alarm( $_[0] ) }; # \&CORE::alarm, \&CORE::GLOBAL::alarm, etc don't work ...
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined &Time::HiRes::alarm ? : 0 0 0
129 0 $arg_hr->{'timeout'} = $arg_hr->{'timeout'} / 1_000_000;
130 0 ▶ $arg_hr->{'timeout'} = 1 if $arg_hr->{'timeout'} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hr->{"timeout"} < 1 0 0 0
131 0 $arg_hr->{'timeout_is_microseconds'} = 0;
132 }
133 }
134 else {
135 0 ▶ $alarm = defined &Time::HiRes::alarm ? \&Time::HiRes::alarm : sub { alarm( $_[0] ) }; # \&CORE::alarm, \&CORE::GLOBAL::alarm, etc don't work ...
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined &Time::HiRes::alarm ? : 0 0 0
136 }
137  
138 0 ▶ $SIG{'ALRM'} = sub { die 'Alarm clock' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 $original_alarm = $alarm->( $arg_hr->{'timeout'} );
140  
141 # undocumented, for testing purposes only
142 0 ▶ if ( exists $arg_hr->{'_timeout_info'} && ref( $arg_hr->{'_timeout_info'} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_hr->{"_timeout_info"} and ref $arg_hr->{"_timeout_info"} eq "HASH") 0 0 0
Condition0%0/3
exists $arg_hr->{"_timeout_info"} and ref $arg_hr->{"_timeout_info"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $arg_hr->{"_timeout_info"} and ref $arg_hr->{"_timeout_info"} eq "HASH"
exists $arg_hr->{"_timeout_info"} ref $arg_hr->{"_timeout_info"} eq "HASH"
Truth table0%0/3
A and B
A= exists $arg_hr->{"_timeout_info"}B= ref $arg_hr->{"_timeout_info"} eq "HASH"
ABresult
0X0
100
111
143 0 %{ $arg_hr->{'_timeout_info'} } = (
144 'timeout' => $arg_hr->{'timeout'},
145 'timeout_is_microseconds' => $arg_hr->{'timeout_is_microseconds'},
146 0 ▶ 'Time::Hires' => $INC{'Time/HiRes.pm'},
Branch: 2 branches
BranchTrueFalseTotal
defined &Time::HiRes::ualarm ? : 0 0 0
defined &Time::HiRes::alarm ? : 0 0 0
147 'Time::Hires::ualarm' => defined &Time::HiRes::ualarm ? 1 : 0,
148 'Time::Hires::alarm' => defined &Time::HiRes::alarm ? 1 : 0,
149 'original_alarm' => $original_alarm,
150 );
151 }
152 }
153 else {
154 4 ▶ no warnings 'uninitialized'; # at least we can scopt it here ...
Subroutine BEGIN: called CC=1 SCAR=0.0
155 24 $SIG{'ALRM'} = $no_unit_warnings;
156 }
157  
158 24 my $is_open3_err = 0;
159 24 my $open3_err_is_exec = 0;
160 24 my $return_bool = 1;
161 24 my $short_circuit_loop = 0;
162  
163 24 eval {
164  
165 24 ▶ if ( exists $arg_hr->{'_pre_run_sleep'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_hr->{"_pre_run_sleep"}) 6 18 24
166 6 ▶ if ( my $sec = int( $arg_hr->{'_pre_run_sleep'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sec = int $arg_hr->{"_pre_run_sleep"}) 6 0 6
167 6 sleep $sec; # undocumented, only for testing
168 }
169 }
170  
171 24 $sel->add($stdout); # unless exists $arg_hr->{'ignore_handle'} && $arg_hr->{'ignore_handle'} eq 'stdout';
172 24 $sel->add($stderr); # unless exists $arg_hr->{'ignore_handle'} && $arg_hr->{'ignore_handle'} eq 'stderr';
173  
174 24 ▶ if ( exists $arg_hr->{'pre_read_print_to_stdin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_hr->{"pre_read_print_to_stdin"}) 7 17 24
175 7 ▶ if ( my $type = ref( $arg_hr->{'pre_read_print_to_stdin'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = ref $arg_hr->{'pre_read_print_to_stdin'}) { } 2 5 7
176 2 ▶ if ( $type eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 1 1 2
elsif ($type eq 'CODE') { } 1 0 1
177 1 for my $line ( @{ $arg_hr->{'pre_read_print_to_stdin'} } ) {
178 2 $stdin->printflush($line);
179 }
180 }
181 elsif ( $type eq 'CODE' ) {
182 1 for my $line ( $arg_hr->{'pre_read_print_to_stdin'}->() ) {
183 2 $stdin->printflush($line);
184 }
185 }
186 }
187 else {
188 5 $stdin->printflush( $arg_hr->{'pre_read_print_to_stdin'} );
189 }
190 }
191  
192 24 ▶ if ( $arg_hr->{'close_stdin'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{"close_stdin"}) 3 21 24
193 3 $stdin->close();
194 3 undef $stdin;
195 }
196  
197 24 local *_;
198  
199 # to avoid "Modification of readonly value attempted" errors with @_
200 # You ask, "Do you mean the _open3()'s or while()'s @_? " and the answer is: "exactly!" ;p
201  
202 24 ▶ my $get_next = sub { readline(shift) };
Subroutine __ANON__: called CC=1 SCAR=0.0
203  
204 24 ▶ if ( my $byte_size = int( $arg_hr->{'read_length_bytes'} || 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $byte_size = int($arg_hr->{"read_length_bytes"} || 0)) 0 24 24
Condition50%1/2
$arg_hr->{'read_length_bytes'} || 0
l!l
024
MC/DC0%0/1
$arg_hr->{'read_length_bytes'} || 0
$arg_hr->{'read_length_bytes'}
Truth table50%1/2
A
A= $arg_hr->{'read_length_bytes'}
Aresult
11
00
205 0 my $buffer;
206 0 ▶ $byte_size = 128 if $byte_size < 128;
Branch: 1 branch
BranchTrueFalseTotal
if $byte_size < 128 0 0 0
207 0 ▶ $get_next = sub { shift->sysread( $buffer, $byte_size ); return $buffer; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 }
209  
210 24 my $odd_errno = int($!);
211  
212 READ_LOOP:
213 24 ▶ while ( my @ready = $sel->can_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@ready) = $sel->can_read) 57 21 78
214 HANDLE:
215 57 for my $fh (@ready) {
216 78 ▶ if ( $fh->eof ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->eof) 39 39 78
217 39 $sel->remove($fh);
218 39 $fh->close;
219 39 next HANDLE;
220 }
221  
222 39 ▶ my $is_stderr = $fh eq $stderr ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fh eq $stderr ? : 18 21 39
223  
224 CMD_OUTPUT:
225 39 ▶ while ( my $cur_line = $get_next->($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cur_line = &$get_next($fh)) 43 36 79
226 43 ▶ next CMD_OUTPUT if $arg_hr->{'ignore_handle'} eq ( $is_stderr ? 'stderr' : 'stdout' );
Branch: 2 branches
BranchTrueFalseTotal
if $arg_hr->{"ignore_handle"} eq ($is_stderr ? "stderr" : "stdout") 2 41 43
$is_stderr ? : 18 25 43
227  
228 41 ▶ $is_open3_err = 1 if $is_stderr && $cur_line =~ m{^open3:};
Branch: 1 branch
BranchTrueFalseTotal
if $is_stderr and $cur_line =~ /^open3:/ 0 41 41
Condition66%2/3
$is_stderr and $cur_line =~ /^open3:/
!ll&&!rl&&r
24170
MC/DC0%0/2
$is_stderr and $cur_line =~ /^open3:/
$is_stderr $cur_line =~ /^open3:/
Truth table66%2/3
A and B
A= $is_stderrB= $cur_line =~ /^open3:/
ABresult
0X0
100
111
229 41 ▶ if ($is_open3_err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_open3_err) 0 41 41
230 0 ▶ if ( ref $arg_hr->{'open3_error'} eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg_hr->{'open3_error'} eq 'SCALAR') { } 0 0 0
231 0 ${ $arg_hr->{'open3_error'} } = $cur_line;
232 }
233 else {
234 0 $arg_hr->{'open3_error'} = $cur_line;
235 }
236  
237 0 ▶ if ( $arg_hr->{'carp_open3_errors'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{"carp_open3_errors"}) 0 0 0
238 0 require Carp;
239 0 Carp::carp($cur_line);
240 }
241  
242 0 ▶ if ( $cur_line =~ m{open3: exec of .* failed\b} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur_line =~ /open3: exec of .* failed\b/) 0 0 0
243 0 $open3_err_is_exec = 1;
244 }
245 }
246  
247 41 $return_bool = $arg_hr->{'handler'}->( $cur_line, $stdin, $is_stderr, $is_open3_err, \$short_circuit_loop );
248  
249 40 ▶ last READ_LOOP if !$return_bool;
Branch: 1 branch
BranchTrueFalseTotal
unless $return_bool 1 39 40
250 39 ▶ last READ_LOOP if $is_open3_err && $arg_hr->{'stop_read_on_open3_err'}; # this is probably the last one anyway
Branch: 1 branch
BranchTrueFalseTotal
if $is_open3_err and $arg_hr->{"stop_read_on_open3_err"} 0 39 39
Condition33%1/3
$is_open3_err and $arg_hr->{"stop_read_on_open3_err"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$is_open3_err and $arg_hr->{"stop_read_on_open3_err"}
$is_open3_err $arg_hr->{"stop_read_on_open3_err"}
Truth table33%1/3
A and B
A= $is_open3_errB= $arg_hr->{"stop_read_on_open3_err"}
ABresult
0X0
100
111
251 39 ▶ last READ_LOOP if $short_circuit_loop;
Branch: 1 branch
BranchTrueFalseTotal
if $short_circuit_loop 1 38 39
252 }
253 }
254  
255 54 $odd_errno = int($!);
256 }
257  
258 23 ▶ $! = 0 if $odd_errno == 0 && $! == 9;
Branch: 1 branch
BranchTrueFalseTotal
if $odd_errno == 0 and $! == 9 0 23 23
Condition66%2/3
$odd_errno == 0 and $! == 9
!ll&&!rl&&r
2210
MC/DC0%0/2
$odd_errno == 0 and $! == 9
$odd_errno == 0 $! == 9
Truth table66%2/3
A and B
A= $odd_errno == 0B= $! == 9
ABresult
0X0
100
111
259  
260 # my $oserr = $!;
261 # my $cherr = $?;
262 23 ▶ $stdout->close if $stdout->opened;
Branch: 1 branch
BranchTrueFalseTotal
if $stdout->opened 1 22 23
263 23 ▶ $stderr->close if $stderr->opened;
Branch: 1 branch
BranchTrueFalseTotal
if $stderr->opened 2 21 23
264 23 ▶ $stdin->close if defined $stdin && ref $stdin eq 'IO::Handle' && $stdin->opened; # && !$arg_hr->{'close_stdin'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $stdin and ref $stdin eq "IO::Handle" and $stdin->opened 19 4 23
Condition83%5/6
defined $stdin and ref $stdin eq "IO::Handle" and $stdin->opened
!ll&&!rl&&r
3119
defined $stdin and ref $stdin eq "IO::Handle"
!ll&&!rl&&r
3020
MC/DC66%2/3
defined $stdin and ref $stdin eq "IO::Handle" and $stdin->opened
defined $stdin ref $stdin eq "IO::Handle" $stdin->opened
Truth table75%3/4
A and B and C
A= defined $stdinB= ref $stdin eq "IO::Handle"C= $stdin->opened
ABCresult
0XX0
10X0
1100
1111
265  
266 # $! = $oserr;
267 # $? = $cherr;
268  
269 23 waitpid $child_pid, 0;
270  
271 };
272  
273 24 ▶ if ( $arg_hr->{'timeout'} && defined $original_alarm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hr->{"timeout"} and defined $original_alarm) 0 24 24
Condition33%1/3
$arg_hr->{"timeout"} and defined $original_alarm
!ll&&!rl&&r
2400
MC/DC0%0/2
$arg_hr->{"timeout"} and defined $original_alarm
$arg_hr->{"timeout"} defined $original_alarm
Truth table33%1/3
A and B
A= $arg_hr->{"timeout"}B= defined $original_alarm
ABresult
0X0
100
111
274 0 $alarm->($original_alarm);
275 }
276  
277 24 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 23 24
278  
279 # if ($@ =~ m/^Alarm clock /) {
280 # $! = 60;
281 # # $? = ??;
282 # }
283 1 return;
284 }
285  
286 23 ▶ if ( $is_open3_err && $open3_err_is_exec && $? != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_open3_err and $open3_err_is_exec and $? != -1) 0 23 23
Condition33%2/6
$is_open3_err and $open3_err_is_exec and $? != -1
!ll&&!rl&&r
2300
$is_open3_err and $open3_err_is_exec
!ll&&!rl&&r
2300
MC/DC0%0/3
$is_open3_err and $open3_err_is_exec and $? != -1
$is_open3_err $open3_err_is_exec $? != -1
Truth table25%1/4
A and B and C
A= $is_open3_errB= $open3_err_is_execC= $? != -1
ABCresult
0XX0
10X0
1100
1111
287 0 $? = -1;
288 }
289  
290 23 ▶ return if $is_open3_err || !$return_bool || !child_error_ok($?);
Branch: 1 branch
BranchTrueFalseTotal
if $is_open3_err or not $return_bool or not child_error_ok($?) 4 19 23
Condition83%5/6
$is_open3_err or not $return_bool or not child_error_ok($?)
l!l&&r!l&&!r
1319
$is_open3_err or not $return_bool
l!l&&r!l&&!r
0122
MC/DC66%2/3
$is_open3_err or not $return_bool or not child_error_ok($?)
$is_open3_err not $return_bool not child_error_ok($?)
Truth table75%3/4
A or not(B) or not(C)
A= $is_open3_errB= not $return_boolC= not child_error_ok($?)
ABCresult
1XX1
01X1
0011
0000
291 19 return 1;
292 }
293  
294 18 ▶sub put_cmd_in {
Subroutine put_cmd_in: called CC=6 SCAR=17.9
Pod documented
295 18 my (@cmd) = @_;
296  
297 18 ▶ my $arg_hr = ref $cmd[-1] eq 'HASH' ? pop(@cmd) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $cmd[-1] eq 'HASH' ? : 13 5 18
298  
299 # not being this strict allows us to do "no" output ref quietness
300 # return if @cmd < 2;
301 # return if defined $cmd[-1] && !ref $cmd[-1];
302 # my $err = pop(@cmd);
303  
304 18 ▶ my $err = !defined $cmd[-1] || ref $cmd[-1] ? pop(@cmd) : undef;
Branch: 1 branch
BranchTrueFalseTotal
!defined($cmd[-1]) || ref $cmd[-1] ? : 18 0 18
Condition66%2/3
not defined $cmd[-1] or ref $cmd[-1]
l!l&&r!l&&!r
1170
MC/DC0%0/2
not defined $cmd[-1] or ref $cmd[-1]
not defined $cmd[-1] ref $cmd[-1]
Truth table66%2/3
not(A) or B
A= not defined $cmd[-1]B= ref $cmd[-1]
ABresult
1X1
011
000
305 18 ▶ my $out = !defined $cmd[-1] || ref $cmd[-1] ? pop(@cmd) : $err;
Branch: 1 branch
BranchTrueFalseTotal
!defined($cmd[-1]) || ref $cmd[-1] ? : 8 10 18
Condition100%3/3
not defined $cmd[-1] or ref $cmd[-1]
l!l&&r!l&&!r
1710
MC/DC100%2/2
not defined $cmd[-1] or ref $cmd[-1]
not defined $cmd[-1] ref $cmd[-1]
Truth table100%3/3
not(A) or B
A= not defined $cmd[-1]B= ref $cmd[-1]
ABresult
1X1
011
000
306  
307 29 ▶ $arg_hr->{'handler'} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
308 29 my ( $cur_line, $stdin, $is_stderr, $is_open3_err, $short_circuit_loop_sr ) = @_;
309  
310 29 ▶ my $mod = $is_stderr ? $err : $out;
Branch: 1 branch
BranchTrueFalseTotal
$is_stderr ? : 12 17 29
311 29 ▶ return 1 if !defined $mod;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mod 2 27 29
312  
313 27 ▶ if ( ref $mod eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mod eq 'SCALAR') { } 19 8 27
314 19 ${$mod} .= $cur_line;
315 }
316 else {
317 8 push @{$mod}, $cur_line;
318 }
319  
320 27 return 1;
321 18 };
322  
323 18 return run_cmd( @cmd, $arg_hr );
324 }
325  
326 #####################
327 #### child_error_* ##
328 #####################
329  
330 28 ▶sub child_error_ok {
Subroutine child_error_ok: called CC=3 SCAR=11.0
Pod documented
331 28 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 25 3 28
332 28 ▶ return 1 if $sysrc == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sysrc == 0 21 7 28
333 7 return;
334 }
335  
336 24 ▶sub child_error_failed_to_execute {
Subroutine child_error_failed_to_execute: called CC=2 SCAR=6.9
Pod documented
337 24 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 22 2 24
338 24 return $sysrc == -1;
339 }
340  
341 4 ▶sub child_error_seg_faulted {
Subroutine child_error_seg_faulted: called CC=3 SCAR=11.1
Pod documented
342 4 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
343 4 ▶ return if child_error_failed_to_execute($sysrc);
Branch: 1 branch
BranchTrueFalseTotal
if child_error_failed_to_execute($sysrc) 0 4 4
344 4 return child_error_exit_signal($sysrc) == 11;
345 }
346  
347 4 ▶sub child_error_core_dumped {
Subroutine child_error_core_dumped: called CC=3 SCAR=11.1
Pod documented
348 4 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
349 4 ▶ return if child_error_failed_to_execute($sysrc);
Branch: 1 branch
BranchTrueFalseTotal
if child_error_failed_to_execute($sysrc) 0 4 4
350 4 return $sysrc & 128;
351 }
352  
353 8 ▶sub child_error_exit_signal {
Subroutine child_error_exit_signal: called CC=3 SCAR=11.1
Pod documented
354 8 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 6 2 8
355 8 ▶ return if child_error_failed_to_execute($sysrc);
Branch: 1 branch
BranchTrueFalseTotal
if child_error_failed_to_execute($sysrc) 0 8 8
356 8 return $sysrc & 127;
357 }
358  
359 4 ▶sub child_error_exit_value {
Subroutine child_error_exit_value: called CC=3 SCAR=11.1
Pod documented
360 4 ▶ my $sysrc = @_ ? shift() : $?;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
361 4 ▶ return if child_error_failed_to_execute($sysrc);
Branch: 1 branch
BranchTrueFalseTotal
if child_error_failed_to_execute($sysrc) 0 4 4
362 4 return $sysrc >> 8;
363 }
364  
365 4 1;
366  
367 __END__
↑ Summary t/ipc_opens_utils_testing.perl »