blib/lib/Argv.pm

filter: Statementstmt 47.1% 420 / 891 Branchbran 32.7% 182 / 556 Conditioncond 34.2% 64 / 187 MC/DCmcdc 9.5% 11 / 115 Subroutinesub 63.2% 43 / 68 Podpod 53.5% 15 / 28 totaltotal 39.8% 735 / 1845 CC 350 SCAR 57.7
CC
350
Cov
41%
system
1166.8
exec
676.9
qx
565.0
CRAP 321.6
↑ Summary /dev/null »
1 package Argv;
2  
3 1 $VERSION = '1.28';
4 1 @ISA = qw(Exporter);
5  
6 1 ▶use constant MSWIN => $^O =~ /MSWin|Windows_NT/i ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /MSWin|Windows_NT/i ? : 0 1 1
7 1 ▶use constant CYGWIN => $^O =~ /cygwin/i ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /cygwin/i ? : 0 1 1
8  
9 # To support the "FUNCTIONAL INTERFACE"
10 1 @EXPORT_OK = qw(system exec qv pipe MSWIN CYGWIN);
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 require Exporter;
15  
16 1 my $class = __PACKAGE__;
17  
18 1 my $NUL = MSWIN ? 'NUL' : '/dev/null';
19  
20 # Adapted from perltootc (see): an "eponymous meta-object" implementing
21 # "translucent attributes".
22 # For each key in the hash below, a method is automatically generated.
23 # Each method sets the object attr if called as an instance method or
24 # the class attr if called as a class method. They return the instance
25 # attr if it's defined, the class attr otherwise. The method name is
26 # lower-case; e.g. 'qxargs'. The default value of each attribute comes
27 # from the hash value set here, which may be overridden in the environment.
28 1 ▶use vars qw(%Argv);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 %Argv = (
30 AUTOCHOMP => $ENV{ARGV_AUTOCHOMP} || 0,
31 AUTOFAIL => $ENV{ARGV_AUTOFAIL} || 0,
32 AUTOGLOB => $ENV{ARGV_AUTOGLOB} || 0,
33 AUTOQUOTE => defined($ENV{ARGV_AUTOQUOTE}) ? $ENV{ARGV_AUTOQUOTE} : 1,
34 DBGLEVEL => $ENV{ARGV_DBGLEVEL} || 0,
35 DFLTSETS => {'' => 1},
36 ENVP => undef,
37 EXECWAIT => defined($ENV{ARGV_EXECWAIT}) ?
38 $ENV{ARGV_EXECWAIT} : scalar(MSWIN),
39 INPATHNORM => $ENV{ARGV_INPATHNORM} || 0,
40 MUSTEXEC => $ENV{ARGV_MUSTEXEC} || 0,
41 NOEXEC => $ENV{ARGV_NOEXEC} || 0,
42 OUTPATHNORM => $ENV{ARGV_OUTPATHNORM} || 0,
43 QXARGS => $ENV{ARGV_QXARGS} || -1,
44 QXFAIL => $ENV{ARGV_QXFAIL} || 0,
45 QUIET => defined($ENV{ARGV_QUIET}) ? $ENV{ARGV_QUIET} : 0,
46 STDIN => defined($ENV{ARGV_STDIN}) ? $ENV{ARGV_STDIN} : 0,
47 STDOUT => defined($ENV{ARGV_STDOUT}) ? $ENV{ARGV_STDOUT} : 1,
48 STDERR => defined($ENV{ARGV_STDERR}) ? $ENV{ARGV_STDERR} : 2,
49 SYFAIL => $ENV{ARGV_SYFAIL} || 0,
50 SYXARGS => $ENV{ARGV_SYXARGS} || 0,
51 0 ▶ PIPECB => sub { print shift; return 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 1 ▶);
Branch: 6 branches
BranchTrueFalseTotal
defined $ENV{'ARGV_AUTOQUOTE'} ? : 0 1 1
defined $ENV{'ARGV_EXECWAIT'} ? : 0 1 1
defined $ENV{'ARGV_QUIET'} ? : 0 1 1
defined $ENV{'ARGV_STDIN'} ? : 0 1 1
defined $ENV{'ARGV_STDOUT'} ? : 0 1 1
defined $ENV{'ARGV_STDERR'} ? : 0 1 1
Condition50%12/24
$ENV{'ARGV_AUTOCHOMP'} || 0
l!l
01
$ENV{'ARGV_AUTOFAIL'} || 0
l!l
01
$ENV{'ARGV_AUTOGLOB'} || 0
l!l
01
$ENV{'ARGV_DBGLEVEL'} || 0
l!l
01
$ENV{'ARGV_INPATHNORM'} || 0
l!l
01
$ENV{'ARGV_MUSTEXEC'} || 0
l!l
01
$ENV{'ARGV_NOEXEC'} || 0
l!l
01
$ENV{'ARGV_OUTPATHNORM'} || 0
l!l
01
$ENV{'ARGV_QXARGS'} || -1
l!l
01
$ENV{'ARGV_QXFAIL'} || 0
l!l
01
$ENV{'ARGV_SYFAIL'} || 0
l!l
01
$ENV{'ARGV_SYXARGS'} || 0
l!l
01
MC/DC0%0/1
$ENV{'ARGV_AUTOCHOMP'} || 0
$ENV{'ARGV_AUTOCHOMP'}
MC/DC0%0/1
$ENV{'ARGV_AUTOFAIL'} || 0
$ENV{'ARGV_AUTOFAIL'}
MC/DC0%0/1
$ENV{'ARGV_AUTOGLOB'} || 0
$ENV{'ARGV_AUTOGLOB'}
MC/DC0%0/1
$ENV{'ARGV_DBGLEVEL'} || 0
$ENV{'ARGV_DBGLEVEL'}
MC/DC0%0/1
$ENV{'ARGV_INPATHNORM'} || 0
$ENV{'ARGV_INPATHNORM'}
MC/DC0%0/1
$ENV{'ARGV_MUSTEXEC'} || 0
$ENV{'ARGV_MUSTEXEC'}
MC/DC0%0/1
$ENV{'ARGV_NOEXEC'} || 0
$ENV{'ARGV_NOEXEC'}
MC/DC0%0/1
$ENV{'ARGV_OUTPATHNORM'} || 0
$ENV{'ARGV_OUTPATHNORM'}
MC/DC0%0/1
$ENV{'ARGV_QXARGS'} || -1
$ENV{'ARGV_QXARGS'}
MC/DC0%0/1
$ENV{'ARGV_QXFAIL'} || 0
$ENV{'ARGV_QXFAIL'}
MC/DC0%0/1
$ENV{'ARGV_SYFAIL'} || 0
$ENV{'ARGV_SYFAIL'}
MC/DC0%0/1
$ENV{'ARGV_SYXARGS'} || 0
$ENV{'ARGV_SYXARGS'}
Truth table50%1/2
A
A= $ENV{'ARGV_AUTOCHOMP'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_AUTOFAIL'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_AUTOGLOB'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_DBGLEVEL'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_INPATHNORM'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_MUSTEXEC'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_NOEXEC'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_OUTPATHNORM'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_QXARGS'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_QXFAIL'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_SYFAIL'}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{'ARGV_SYXARGS'}
Aresult
11
00
53  
54 # Generates execution-attribute methods from the table above. Provided
55 # as a class method itself to potentially allow a derived class to
56 # generate more of these. Semantics of these methods are quite
57 # context-driven and are explained in the PODs.
58 1 ▶sub gen_exec_method {
Subroutine gen_exec_method: called CC=4 SCAR=14.6
Pod undocumented
59 1 my $meta = shift;
60 1 ▶ no strict 'refs'; # must evaluate $meta as a symbolic ref
Subroutine BEGIN: called CC=1 SCAR=0.0
61 0 ▶ my @data = @_ ? map {uc} @_ : keys %{$meta};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
62 1 for my $attr (@data) {
63 21 ▶ $$meta{$attr} ||= 0;
Condition100%2/2
$meta->{$attr} ||= 0
l!l
615
MC/DC100%1/1
$meta->{$attr} ||= 0
$meta->{$attr}
Truth table100%2/2
A
A= $meta->{$attr}
Aresult
11
00
64 21 my $method = lc $attr;
65 141 ▶ *$method = sub {
Subroutine __ANON__: called CC=16 SCAR=31.3
66 141 my $self = shift;
67 # In null context with no args, set boolean value 'on'.
68 141 ▶ @_ = (1) if !@_ && !defined(wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or defined wantarray 0 141 141
Condition66%2/3
@_ or defined wantarray
l!l&&r!l&&!r
111300
MC/DC0%0/2
@_ or defined wantarray
@_ defined wantarray
Truth table66%2/3
A or B
A= @_B= defined wantarray
ABresult
1X1
011
000
69 141 my $ret = 0;
70 141 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 139 2 141
71 139 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 9 130 139
72 9 ▶ if (defined(wantarray)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 4 5 9
73 4 ▶ if (ref $self->{$attr}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{$attr}) { } 0 4 4
elsif (defined $self->{$attr}) { } 0 4 4
74 0 unshift(@{$self->{$attr}}, shift);
75 } elsif (defined $self->{$attr}) {
76 0 $self->{$attr} = [shift, $self->{$attr}];
77 } else {
78 4 $self->{$attr} = [shift];
79 }
80 4 return $self;
81 } else {
82 5 $self->{$attr} = shift;
83 5 return undef;
84 }
85 } else {
86 $ret = defined($self->{$attr}) ?
87 130 ▶ $self->{$attr} : $class->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$attr} ? : 14 116 130
88 }
89 } else {
90 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 0 2
91 2 ▶ if (defined(wantarray)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 2 2
92 0 ▶ if (ref $class->{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class->{$attr}) { } 0 0 0
93 0 unshift(@{$class->{$attr}}, shift);
94 } else {
95 0 $class->{$attr} = [shift, $class->{$attr}];
96 }
97 } else {
98 2 $class->{$attr} = shift;
99 }
100 # If setting a class attribute, export it to the
101 # env in case we fork a child also using Argv.
102 2 my $ev = uc join('_', $class, $attr);
103 2 $ENV{$ev} = $class->{$attr};
104 2 return $self;
105 } else {
106 0 $ret = $class->{$attr};
107 }
108 }
109 130 ▶ if (ref($ret) eq 'ARRAY' && ref($ret->[0]) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret eq "ARRAY" and ref $ret->[0] ne "CODE") 4 126 130
Condition100%3/3
ref $ret eq "ARRAY" and ref $ret->[0] ne "CODE"
!ll&&!rl&&r
12514
MC/DC100%2/2
ref $ret eq "ARRAY" and ref $ret->[0] ne "CODE"
ref $ret eq "ARRAY" ref $ret->[0] ne "CODE"
Truth table100%3/3
A and B
A= ref $ret eq "ARRAY"B= ref $ret->[0] ne "CODE"
ABresult
0X0
100
111
110 4 my $stack = $ret;
111 4 $ret = shift @$stack;
112 4 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 4 0 4
113 4 ▶ if (@$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack) { } 0 4 4
114 0 $self->{$attr} = shift @$stack;
115 } else {
116 4 delete $self->{$attr};
117 }
118 } else {
119 0 $self->{$attr} = shift @$stack;
120 }
121 }
122 130 return $ret;
123 }
124 21 }
125 }
126  
127 # Generate all the attribute methods declared in %Argv above.
128 1 $class->gen_exec_method;
129  
130 # Generate methods for diverting stdin, stdout, and stderr in ->qx.
131 {
132 1 my %streams = (stdin => 1, stdout => 1, stderr => 2);
133 1 for my $name (keys %streams) {
134 3 my $method = "_qx_$name";
135 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
136 2 ▶ *$method = sub {
Subroutine __ANON__: called CC=8 SCAR=30.8
137 2 my $self = shift;
138 2 my $r_cmd = shift;
139 2 my $nfd = shift;
140 2 my $fd = $streams{$name};
141 2 ▶ if ($nfd !~ m%^[\d-]*$%) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $nfd =~ /^[\d-]*$/) { } 0 2 2
elsif ($fd == 0) { } 0 2 2
elsif ($nfd == 0) { } 0 2 2
elsif ($nfd == 3 - $fd) { } 0 2 2
elsif ($nfd != $fd) { } 0 2 2
142 0 push(@$r_cmd, "$fd$nfd");
143 } elsif ($fd == 0) {
144 0 ▶ warn "Error: illegal value '$nfd' for $name" if $nfd > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $nfd > 0 0 0 0
145 0 ▶ push(@$r_cmd, "<$NUL") if $nfd < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $nfd < 0 0 0 0
146 } elsif ($nfd == 0) {
147 0 push(@$r_cmd, "$fd>$NUL");
148 } elsif ($nfd == (3-$fd)) {
149 0 push(@$r_cmd, sprintf "%d>&%d", $fd, 3-$fd);
150 } elsif ($nfd != $fd) {
151 0 warn "Error: illegal value '$nfd' for $name";
152 }
153 3 };
154 }
155 }
156  
157 # Getopt::Long::GetOptions() respects '--' but strips it, while
158 # we want to respect '--' and leave it in. Thus this override.
159 5 ▶sub GetOptions {
Subroutine GetOptions: called CC=3 SCAR=11.2
Pod undocumented
160 5 ▶ @ARGV = map {/^--$/ ? qw(=--= --) : $_} @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
/^--$/ ? : 0 21 21
161 5 my $ret = Getopt::Long::GetOptions(@_);
162 5 ▶ @ARGV = map {/^=--=$/ ? qw(--) : $_} @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
/^=--=$/ ? : 0 11 11
163 5 return $ret;
164 }
165  
166 # This method is much like the generated exec methods but has some
167 # special-case logic: If called with a param which is true, it starts up
168 # a coprocess. If called with false (aka 0) it shuts down the coprocess
169 # and destroys the IPC::ChildSafe object. If called with no params at
170 # all it returns the existing IPC::ChildSafe object.
171 0 ▶sub ipc_childsafe {
Subroutine ipc_childsafe: not called CC=7 SCAR=37.8
Pod undocumented
172 0 my $self = shift;
173 0 my $ipc_state = $_[0];
174 0 my $ipc_obj;
175 0 ▶ if ($ipc_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ipc_state) 0 0 0
176 0 eval { require IPC::ChildSafe };
177 0 ▶ return undef if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
178 0 IPC::ChildSafe->VERSION(3.10);
179 0 $ipc_obj = IPC::ChildSafe->new(@_);
180 }
181 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
182 0 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
183 0 ▶ if (defined $ipc_state) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ipc_state) { } 0 0 0
184 0 $self->{_IPC_CHILDSAFE} = $ipc_obj;
185 0 return $self;
186 } else {
187 return exists($self->{_IPC_CHILDSAFE}) ?
188 0 ▶ $self->{_IPC_CHILDSAFE} : $class->{_IPC_CHILDSAFE};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_IPC_CHILDSAFE'} ? : 0 0 0
189 }
190 } else {
191 0 ▶ if (defined $ipc_state) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ipc_state) { } 0 0 0
192 0 $class->{_IPC_CHILDSAFE} = $ipc_obj;
193 0 return $self;
194 } else {
195 0 return $class->{_IPC_CHILDSAFE};
196 }
197 }
198 }
199  
200 # Class/instance method. Parses command line for e.g. -/dbg=1. See PODs.
201 0 ▶sub attropts {
Subroutine attropts: not called CC=8 SCAR=42.8
Pod documented
202 0 my $self = shift;
203 0 my $r_argv = undef;
204 0 my $prefix = '-/';
205 0 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 0 0 0
206 0 my $cfg = shift;
207 0 $r_argv = $cfg->{ARGV};
208 0 $prefix = $cfg->{PREFIX};
209 }
210 0 require Getopt::Long;
211 0 local $Getopt::Long::passthrough = 1;
212 0 local $Getopt::Long::genprefix = "($prefix)";
213 0 my @flags = map {"$_=i"} ((map lc, keys %Argv::Argv), @_);
214 0 my %opt;
215 0 ▶ if (ref $self) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
elsif ($r_argv) { } 0 0 0
elsif (@ARGV) { } 0 0 0
216 0 ▶ if ($r_argv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_argv) { } 0 0 0
217 0 local @ARGV = @$r_argv;
218 0 GetOptions(\%opt, @flags);
219 0 @$r_argv = @ARGV;
220 } else {
221 0 local @ARGV = $self->args;
222 0 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 0 0 0
223 0 GetOptions(\%opt, @flags);
224 0 $self->args(@ARGV);
225 }
226 }
227 } elsif ($r_argv) {
228 0 local @ARGV = @$r_argv;
229 0 GetOptions(\%opt, @flags);
230 0 @$r_argv = @ARGV;
231 } elsif (@ARGV) {
232 0 GetOptions(\%opt, @flags);
233 }
234 0 for my $method (keys %opt) {
235 0 $self->$method($opt{$method});
236 }
237 0 return $self;
238 }
239 1 *stdopts = \&attropts; # backward compatibility
240  
241 # A class method which returns a summary of operations performed in
242 # printable format. Called with a void context to start data-
243 # collection, with a scalar context to end it and get the report.
244 0 ▶sub summary {
Subroutine summary: not called CC=5 SCAR=34.0
Pod undocumented
245 0 my $cls = shift;
246 0 my($cmds, $operands);
247 0 ▶ if (!defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
248 0 $Argv::Summary = {};
249 0 return;
250 }
251 0 ▶ return unless $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
unless $Argv::Summary 0 0 0
252 0 my $fmt = "%30s: %4s\t%s\n";
253 0 my $str = sprintf $fmt, "$cls Summary", 'Cmds', 'Operands';
254 0 for (sort keys %{$Argv::Summary}) {
255 0 my @stats = @{$Argv::Summary->{$_}};
256 0 $cmds += $stats[0];
257 0 $operands += $stats[1];
258 0 $str .= sprintf $fmt, $_, $stats[0], $stats[1];
259 }
260 0 ▶ $str .= sprintf $fmt, 'TOTAL', $cmds, $operands if defined $cmds;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmds 0 0 0
261 0 $Argv::Summary = 0;
262 0 return $str;
263 }
264  
265 # Constructor.
266 8 ▶sub new {
Subroutine new: called CC=12 SCAR=29.2
Pod undocumented
267 8 my $proto = shift;
268 8 ▶ my $attrs = shift if ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 0 8 8
269 8 my $self;
270 8 ▶ if (ref($proto)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $proto) { } 1 7 8
271 # As an instance method, make a deep clone of the invoking object.
272 # Some cloners are fast but not commonly installed, others the
273 # reverse. We try them in order of speed and fall back to
274 # Data::Dumper which is slow but core Perl as of 5.6.0. I could
275 # just inherit from Clone or Storable but want to not force
276 # users who don't need cloning to install them.
277 1 eval {
278 1 require Clone;
279 1 Clone->VERSION(0.12); # 0.11 has a bug that breaks Argv
280 1 $self = Clone::clone($proto);
281 };
282 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
283 0 eval {
284 0 require Storable;
285 0 $self = Storable::dclone($proto);
286 };
287 }
288 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
289 0 require Data::Dumper;
290 # Older Perl versions may not have the XS interface installed,
291 # so try it and fall back to the pure-perl version on failure.
292 0 my $copy = eval {
293 0 Data::Dumper->Deepcopy(1)->new([$proto], ['self'])->Dumpxs;
294 };
295 0 ▶ $copy = Data::Dumper->Deepcopy(1)->new([$proto], ['self'])->Dump
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
296 if $@;
297 0 eval $copy;
298 }
299 1 ▶ die $@ if $@ || !$self;
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not $self 0 1 1
Condition33%1/3
$@ or not $self
l!l&&r!l&&!r
001
MC/DC0%0/2
$@ or not $self
$@ not $self
Truth table33%1/3
A or not(B)
A= $@B= not $self
ABresult
1X1
011
000
300 # At least some cloners can't clone a code ref...
301 1 $self->{PIPECB} = $proto->{PIPECB};
302 } else {
303 7 $self = {};
304 7 ▶ if ($proto ne __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto ne __PACKAGE__) 0 7 7
305 # Inherit class attributes from subclass class attributes.
306 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
307 0 for (keys %$proto) {
308 0 $self->{$_} = $proto->{$_};
309 }
310 }
311 7 $self->{AV_PROG} = [];
312 7 $self->{AV_ARGS} = [];
313 7 $self->{PIPECB} = $Argv{PIPECB};
314 7 bless $self, $proto;
315 7 $self->optset('');
316 }
317 8 ▶ $self->attrs($attrs) if $attrs;
Branch: 1 branch
BranchTrueFalseTotal
if $attrs 0 8 8
318 8 ▶ $self->argv(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 1 8
319 8 return $self;
320 }
321 1 *clone = \&new;
322  
323 # Nothing to do here, just avoiding interaction with AUTOLOAD.
324 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
325  
326 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=14.2
327 0 my $self = shift;
328 0 (my $cmd = $Argv::AUTOLOAD) =~ s/.*:://;
329 0 ▶ return if $cmd eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "DESTROY" 0 0 0
330 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
331 # install a new method '$cmd' to avoid autoload next time ...
332 0 ▶ *$cmd = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
333 0 my $self = shift;
334 0 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
335 0 $self->argv($cmd, @_);
336 } else {
337 0 $self->new($cmd, @_);
338 }
339 0 };
340 # ... then service this request
341 0 return $self->$cmd(@_);
342 }
343  
344 # Instance methods; most class methods are auto-generated above.
345  
346 # A shorthand way to set a bunch of attributes by passing a hashref
347 # of their names=>values.
348 0 ▶sub attrs {
Subroutine attrs: not called CC=3 SCAR=24.8
Pod undocumented
349 0 my $self = shift;
350 0 my $attrs = shift;
351 0 ▶ if ($attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 0 0 0
352 0 for my $key (keys %$attrs) {
353 0 (my $method = $key) =~ s/^-//;
354 0 $self->$method($attrs->{$key});
355 }
356 }
357 0 return $self;
358 }
359  
360 # Replace the instance's prog(), opt(), and args() vectors all together.
361 # Without arguments, return the command as it currently looks either as
362 # a list or a string depending on context.
363 8 ▶sub argv {
Subroutine argv: called CC=8 SCAR=23.4
Pod documented
364 8 my $self = shift;
365 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 8 0 8
366 8 ▶ $self->attrs(shift) if ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 0 8 8
367 8 $self->{AV_PROG} = [];
368 8 $self->{AV_OPTS}{''} = [];
369 8 $self->{AV_ARGS} = [];
370 8 ▶ $self->prog(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 8 0 8
371 8 ▶ $self->attrs(shift) if ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 0 8 8
372 8 ▶ $self->opts(@{shift @_}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 2 6 8
373 8 ▶ $self->args(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 3 8
374 8 return $self;
375 } else {
376 0 my @cmd = ($self->prog, $self->opts, $self->args);
377 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
378 0 return @cmd;
379 } else {
380 0 return "@cmd";
381 }
382 }
383 }
384 1 *cmd = \&argv; # backward compatibility
385  
386 # Set or get the 'prog' part of the command line.
387 10 ▶sub prog {
Subroutine prog: called CC=6 SCAR=19.5
Pod documented
388 10 my $self = shift;
389 10 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 9 1 10
elsif (not defined wantarray) { } 0 1 1
390 0 ▶ my @prg = ref $_[0] ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 9 9
391 9 @{$self->{AV_PROG}} = @prg;
392 } elsif (!defined(wantarray)) {
393 0 @{$self->{AV_PROG}} = ();
394 }
395 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 9 1 10
396 9 return $self;
397 } else {
398 0 ▶ return wantarray ? @{$self->{AV_PROG}} : ${$self->{AV_PROG}}[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
399 }
400 }
401  
402 # Set or get the 'args' part of the command line.
403 8 ▶sub args {
Subroutine args: called CC=5 SCAR=16.8
Pod documented
404 8 my $self = shift;
405 8 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 6 2 8
elsif (not defined wantarray) { } 0 2 2
406 0 ▶ my @args = ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 6 6
407 6 @{$self->{AV_ARGS}} = @args;
408 } elsif (!defined(wantarray)) {
409 0 @{$self->{AV_ARGS}} = ();
410 }
411 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 6 2 8
412 6 return $self;
413 } else {
414 2 return @{$self->{AV_ARGS}};
415 }
416 }
417  
418 # Generates the parse(), opts(), and flag() method families. During
419 # construction this is used to generate the methods for the anonymous
420 # option set; it can be used explicitly to generate parseXX(), optsXX(),
421 # and argsXX() for optset 'XX'.
422 10 ▶sub optset {
Subroutine optset: called CC=6 SCAR=19.1
Pod documented
423 10 my $self = shift;
424 10 for (@_) {
425 11 my $set = uc $_;
426 11 ▶ next if defined $self->{AV_OPTS}{$set};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"AV_OPTS"}{$set} 0 11 11
427 11 $self->{AV_OPTS}{$set} = [];
428 11 $self->{AV_LKG}{$set} = {};
429 11 my($p_meth, $o_meth, $f_meth) = map { $_ . $set } qw(parse opts flag);
430 11 $self->{AV_DESC}{$set} = [];
431 1 ▶ no strict 'refs'; # needed to muck with symbol table
Subroutine BEGIN: called CC=1 SCAR=0.0
432 5 ▶ *$p_meth = sub {
Subroutine __ANON__: called CC=6 SCAR=19.7
433 5 my $self = shift;
434 5 ▶ $self->{AV_DESC}{$set} ||= [];
Condition50%1/2
$self->{"AV_DESC"}{$set} ||= []
l!l
50
MC/DC0%0/1
$self->{"AV_DESC"}{$set} ||= []
$self->{"AV_DESC"}{$set}
Truth table50%1/2
A
A= $self->{"AV_DESC"}{$set}
Aresult
11
00
435 5 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 0 5
436 5 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 5 5
elsif (ref $_[0] eq 'HASH') { } 0 5 5
437 0 $self->{CFG}{$set} = shift;
438 } elsif (ref($_[0]) eq 'HASH') {
439 0 $self->warning("do not provide a linkage specifier");
440 0 shift;
441 }
442 5 @{$self->{AV_DESC}{$set}} = @_;
443 $self->factor($set,
444 $self->{AV_DESC}{$set}, $self->{AV_OPTS}{$set},
445 5 $self->{AV_ARGS}, $self->{CFG}{$set});
446 5 ▶ if (defined $self->{AV_OPTS}{$set}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"AV_OPTS"}{$set}) 5 0 5
447 5 my @parsedout = @{$self->{AV_OPTS}{$set}};
448 }
449 }
450 5 return @{$self->{AV_OPTS}{$set}};
451 11 ▶ } unless $Argv::{$p_meth};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Argv::{$p_meth} 5 6 11
452 6 ▶ *$o_meth = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
453 6 my $self = shift;
454 6 ▶ $self->{AV_OPTS}{$set} ||= [];
Condition50%1/2
$self->{"AV_OPTS"}{$set} ||= []
l!l
60
MC/DC0%0/1
$self->{"AV_OPTS"}{$set} ||= []
$self->{"AV_OPTS"}{$set}
Truth table50%1/2
A
A= $self->{"AV_OPTS"}{$set}
Aresult
11
00
455 6 ▶ if (@_ || !defined(wantarray)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or not defined wantarray) 2 4 6
Condition66%2/3
@_ or not defined wantarray
l!l&&r!l&&!r
204
MC/DC50%1/2
@_ or not defined wantarray
@_ not defined wantarray
Truth table66%2/3
A or not(B)
A= @_B= not defined wantarray
ABresult
1X1
011
000
456 2 @{$self->{AV_OPTS}{$set}} = @_;
457 }
458 6 ▶ return @_ ? $self : @{$self->{AV_OPTS}{$set}};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 4 6
459 11 ▶ } unless $Argv::{$o_meth};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Argv::{$o_meth} 5 6 11
460 0 ▶ *$f_meth = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
461 0 my $self = shift;
462 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 0 0 0
463 0 ▶ while(my($key, $val) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
464 0 $self->{AV_LKG}{$set}{$key} = $val;
465 }
466 } else {
467 0 my $key = shift;
468 0 return $self->{AV_LKG}{$set}{$key};
469 }
470 11 ▶ } unless $Argv::{$f_meth};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::Argv::{$f_meth} 5 6 11
471 }
472 10 return keys %{$self->{AV_DESC}}; # this is the set of known optsets.
473 }
474  
475 # Not generally used except internally; not documented. First arg
476 # is an option set name followed by bunch of array-refs: a pointer
477 # to a list of Getopt::Long-style option descs, a ref to be filled
478 # in with a list of found options, another containing the input
479 # args and to be filled in with the leftovers, and an optional
480 # one containing Getopt::Long-style config options.
481 5 ▶sub factor {
Subroutine factor: called CC=10 SCAR=24.5
Pod undocumented
482 5 my $self = shift;
483 5 my($pset, $r_desc, $r_opts, $r_args, $r_cfg) = @_;
484 5 my @vgra;
485 {
486 5 local @ARGV = @$r_args;
487 5 ▶ if ($r_desc && @$r_desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_desc and @$r_desc) 5 0 5
Condition33%1/3
$r_desc and @$r_desc
!ll&&!rl&&r
005
MC/DC0%0/2
$r_desc and @$r_desc
$r_desc @$r_desc
Truth table33%1/3
A and B
A= $r_descB= @$r_desc
ABresult
0X0
100
111
488 5 require Getopt::Long;
489 # Need this version so Configure() returns prev state.
490 5 Getopt::Long->VERSION(2.23);
491 5 ▶ if ($r_cfg && @$r_cfg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_cfg and @$r_cfg) { } 0 5 5
Condition33%1/3
$r_cfg and @$r_cfg
!ll&&!rl&&r
500
MC/DC0%0/2
$r_cfg and @$r_cfg
$r_cfg @$r_cfg
Truth table33%1/3
A and B
A= $r_cfgB= @$r_cfg
ABresult
0X0
100
111
492 0 my $prev = Getopt::Long::Configure(@$r_cfg);
493 0 GetOptions($self->{AV_LKG}{$pset}, @$r_desc);
494 0 Getopt::Long::Configure($prev);
495 } else {
496 5 local $Getopt::Long::passthrough = 1;
497 5 local $Getopt::Long::autoabbrev = 1;
498 5 ▶ local $Getopt::Long::debug = 1 if $self->dbglevel == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $self->dbglevel == 5 0 5 5
499 5 GetOptions($self->{AV_LKG}{$pset}, @$r_desc);
500 }
501 }
502 5 @vgra = @ARGV;
503 }
504 5 my(@opts, @args);
505 5 for (reverse @$r_args) {
506 21 ▶ if (@vgra && $vgra[$#vgra] eq $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vgra and $vgra[$#vgra] eq $_) { } 11 10 21
Condition100%3/3
@vgra and $vgra[$#vgra] eq $_
!ll&&!rl&&r
7311
MC/DC100%2/2
@vgra and $vgra[$#vgra] eq $_
@vgra $vgra[$#vgra] eq $_
Truth table100%3/3
A and B
A= @vgraB= $vgra[$#vgra] eq $_
ABresult
0X0
100
111
507 11 unshift(@args, pop (@vgra));
508 } else {
509 10 unshift(@opts, $_);
510 }
511 }
512 5 ▶ @$r_opts = @opts if $r_opts;
Branch: 1 branch
BranchTrueFalseTotal
if $r_opts 5 0 5
513 5 @$r_args = @args;
514 5 return @opts;
515 }
516  
517 # Extract and return any of the specified options from object.
518 0 ▶sub extract {
Subroutine extract: not called CC=2 SCAR=17.9
Pod documented
519 0 my $self = shift;
520 0 my $set = shift;
521 0 ▶ $self->optset($set) unless defined $self->{AV_LKG}{$set};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"AV_LKG"}{$set} 0 0 0
522 0 my $p_meth = 'parse' . $set;
523 0 my $o_meth = 'opts' . $set;
524 0 $self->$p_meth(@_);
525 0 my @extracts = $self->$o_meth();
526 0 return @extracts;
527 }
528  
529 10 ▶sub argpathnorm {
Subroutine argpathnorm: called CC=8 SCAR=37.7
Pod undocumented
530 10 my $self = shift;
531 10 my $norm = $self->inpathnorm;
532 10 ▶ return unless $norm && !ref($norm);
Branch: 1 branch
BranchTrueFalseTotal
unless $norm and not ref $norm 10 0 10
Condition33%1/3
$norm and not ref $norm
!ll&&!rl&&r
1000
MC/DC0%0/2
$norm and not ref $norm
$norm not ref $norm
Truth table33%1/3
A and not(B)
A= $normB= not ref $norm
ABresult
0X0
100
111
533 0 if (CYGWIN) { #for the cygwin shell
534 s%\\%\\\\%g for @_;
535 }
536 0 return unless MSWIN;
537 0 for my $word (@_) {
538 # If requested, change / for \ in Windows file paths.
539 # This is necessarily an inexact science.
540 0 my @fragments = split ' ', $word;
541 0 for (@fragments) {
542 0 ▶ if (m%^"?/%) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^"?/]) { } 0 0 0
543 0 ▶ if (m%(.*/\w+):(.+)%) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[(.*/\w+):(.+)]) { } 0 0 0
544 # If it looks like an option specifying a path (/opt:path),
545 # normalize only the path part.
546 0 my($opt, $path) = ($1, $2);
547 0 $path =~ s%/%\\%g;
548 0 $_ = "$opt:$path";
549 } else {
550 # If it contains a slash (any kind) after the initial one
551 # treat it as a full path. This is where you get into
552 # ambiguity with combined options (e.g. /E/I/Q/S) which
553 # could technically be a path. So that's just not allowed
554 # when path-norming.
555 0 my $slashes = tr/\/\\//;
556 0 ▶ s%/%\\%g if $slashes > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $slashes > 1 0 0 0
557 }
558 } else {
559 0 s%/%\\%g;
560 }
561 }
562 0 $word = "@fragments";
563 }
564 }
565  
566 # Quotes @_ in place against shell expansion. Usually called via autoquote attr
567 1 ▶sub quote {
Subroutine quote: called CC=9 SCAR=31.4
Pod documented
568 1 my $self = shift;
569 1 for (grep {defined} @_) {
570 # Hack - allow user to exempt any arg from quoting by prefixing '^'.
571 2 ▶ next if s%^\^%%;
Branch: 1 branch
BranchTrueFalseTotal
if s/^\^// 0 2 2
572 # Special case - turn internal newlines back to literal \n on Win32
573 2 s%\n%\\n%gs if MSWIN;
574 # If arg is already quoted with '': on Unix it's safe, leave alone.
575 # On Windows, replace the single quotes with escaped double quotes.
576 2 ▶ if (m%^'(.*)'$%s) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^'(.*)'$/s) { } 0 2 2
elsif (/^".*"$/s) { } 0 2 2
577 0 $_ = qq(\\"$1\\") if MSWIN;
578 0 next;
579 } elsif (m%^".*"$%s) {
580 0 $_ = qq(\\"$_\\") if MSWIN || CYGWIN;
581 0 next;
582 }
583 # Skip if contains no special chars.
584 2 if (MSWIN) {
585 # On windows globbing is not handled by the shell so we
586 # let '*' go by.
587 next unless m%[^-=:_."\w\\/*]% || tr%\n%%;
588 } else {
589 2 ▶ next unless m%[^-=:_."\w\\/]% || m%\\n% || tr%\n%%;
Branch: 1 branch
BranchTrueFalseTotal
unless m[[^-=:_."\w\\/]] or /\\n/ or tr/\n// 2 0 2
Condition33%2/6
m[[^-=:_."\w\\/]] or /\\n/ or tr/\n//
l!l&&r!l&&!r
002
m[[^-=:_."\w\\/]] or /\\n/
l!l&&r!l&&!r
002
MC/DC0%0/3
m[[^-=:_."\w\\/]] or /\\n/ or tr/\n//
m[[^-=:_."\w\\/]] /\\n/ tr/\n//
Truth table25%1/4
A or B or C
A= m[[^-=:_."\w\\/]]B= /\\n/C= tr/\n//
ABCresult
1XX1
01X1
0011
0000
590 }
591 # Special case - leave things that look like redirections alone.
592 0 ▶ next if /^\d?(?:<{1,2})|(?:>{1,2})/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\d?(?:<{1,2})|(?:>{1,2})/ 0 0 0
593 # This is a hack to support MKS-built perl 5.004. Don't know
594 # if the problem is with MKS builds or 5.004 per se.
595 0 next if MSWIN && $] < 5.005;
596 # Now quote embedded quotes ...
597 0 $_ =~ s%(\\*)"%$1$1\\"%g;
598 # quote a trailing \ so it won't quote the quote (!) ...
599 0 s%\\{1}$%\\\\%;
600 # and last the entire string.
601 0 $_ = qq("$_");
602 }
603 1 return $self;
604 }
605  
606 # Submits @_ to Perl's glob() function. Usually invoked via autoglob attr.
607 1 ▶sub glob {
Subroutine glob: called CC=7 SCAR=22.5
Pod documented
608 1 my $self = shift;
609 1 ▶ my @orig = @_ ? @_ : $self->args;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
610 1 ▶ if (! @orig) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@orig) 0 1 1
611 0 $self->warning("no arguments to glob");
612 0 return 0;
613 }
614 1 my @globbed;
615 1 for (@orig) {
616 1 ▶ if (/^'(.*)'$/) { # allow '' to escape globbing
Branch: 2 branches
BranchTrueFalseTotal
if (/^'(.*)'$/) { } 0 1 1
elsif (/[*?]/) { } 1 0 1
617 0 push(@globbed, $1);
618 } elsif (/[*?]/) {
619 1 push(@globbed, glob)
620 1 ▶ } else {
Subroutine BEGIN: called CC=1 SCAR=0.0
621 0 push(@globbed, $_)
622 }
623 }
624 1 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 1 1
625 0 return @globbed;
626 } else {
627 1 $self->args(@globbed);
628 }
629 }
630  
631 # Internal. Takes a list of optset names, returns a list of options.
632 11 ▶sub _sets2opts {
Subroutine _sets2opts: called CC=9 SCAR=22.1
633 11 my $self = shift;
634 11 my(@sets, @opts);
635 11 ▶ if (! @_) {
Branch: 3 branches
BranchTrueFalseTotal
if (not @_) { } 8 3 11
elsif ($_[0] eq '-') { } 2 1 3
elsif ($_[0] eq '+') { } 0 1 1
636 8 @sets = keys %{$self->dfltsets};
637 } elsif ($_[0] eq '-') {
638 2 @sets = ();
639 } elsif ($_[0] eq '+') {
640 0 @sets = $self->optset;
641 } else {
642 1 my %known = map {$_ => 1} $self->optset;
643 1 ▶ for (@_) { $self->warning("Unknown optset '$_'\n") if !$known{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$_} 0 1 1
644 1 @sets = @_;
645 }
646 11 for my $set (@sets) {
647 9 ▶ next unless $self->{AV_OPTS}{$set} && @{$self->{AV_OPTS}{$set}};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"AV_OPTS"}{$set} and @{$self->{"AV_OPTS"}{$set};} 7 2 9
Condition100%3/3
$self->{"AV_OPTS"}{$set} and @{$self->{"AV_OPTS"}{$set};}
!ll&&!rl&&r
162
MC/DC100%2/2
$self->{"AV_OPTS"}{$set} and @{$self->{"AV_OPTS"}{$set};}
$self->{"AV_OPTS"}{$set} @{$self->{"AV_OPTS"}{$set};}
Truth table100%3/3
A and B
A= $self->{"AV_OPTS"}{$set}B= @{$self->{"AV_OPTS"}{$set};}
ABresult
0X0
100
111
648 2 push(@opts, @{$self->{AV_OPTS}{$set}});
649 }
650 11 return @opts;
651 }
652  
653 # Internal, collects data for use by 'summary' method.
654 0 ▶sub _addstats {
Subroutine _addstats: not called CC=2 SCAR=17.9
655 0 my $self = shift;
656 0 my($prg, $argcnt) = @_;
657 0 ▶ my $stats = $Argv::Summary->{$prg} || [0, 0];
Condition0%0/2
$Argv::Summary->{$prg} || [0, 0]
l!l
00
MC/DC0%0/1
$Argv::Summary->{$prg} || [0, 0]
$Argv::Summary->{$prg}
Truth table0%0/2
A
A= $Argv::Summary->{$prg}
Aresult
11
00
658 0 $$stats[0]++;
659 0 $$stats[1] += $argcnt;
660 0 $Argv::Summary->{$prg} = $stats;
661 }
662  
663 # Handles ->autofail operations. If given a scalar, exit with the value
664 # of that scalar on failure unless the scalar == 0, in which case
665 # don't exit. If given a ref to a scalar, increment the scalar for
666 # each failure. If given a code ref, call that subroutine. An array ref
667 # is assumed to contain a code ref followed by parameters for the sub.
668 2 ▶sub fail {
Subroutine fail: called CC=8 SCAR=27.2
Pod undocumented
669 2 my($self, $specific) = @_;
670 2 my $general = $self->autofail;
671 2 ▶ if (my $val = $specific || $general) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $val = $specific || $general) 1 1 2
Condition66%2/3
$specific || $general
l!l&&r!l&&!r
011
MC/DC50%1/2
$specific || $general
$specific $general
Truth table66%2/3
A || B
A= $specificB= $general
ABresult
1X1
011
000
672 1 ▶ if (ref($val) eq 'CODE') {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $val eq 'CODE') { } 0 1 1
elsif (ref $val eq 'ARRAY') { } 1 0 1
elsif (ref $val eq 'SCALAR') { } 0 0 0
elsif (not $val =~ /^\d*$/) { } 0 0 0
elsif ($val) { } 0 0 0
673 0 &$val($self);
674 } elsif (ref($val) eq 'ARRAY') {
675 1 my @arr = @$val;
676 1 my $func = shift(@arr);
677 1 &$func(@arr);
678 } elsif (ref($val) eq 'SCALAR') {
679 0 $$val++;
680 } elsif ($val !~ /^\d*$/) {
681 0 die $val;
682 } elsif ($val) {
683 0 exit $val;
684 }
685 }
686 2 return $self;
687 }
688  
689 # Convert lines to UNIX (/) format iff they represent file pathnames.
690 0 ▶sub unixpath {
Subroutine unixpath: not called CC=3 SCAR=24.8
Pod undocumented
691 0 my $self = shift;
692 0 for (@_) {
693 0 chomp(my $chomped = $_);
694 0 ▶ s%\\%/%g if -e $chomped;
Branch: 1 branch
BranchTrueFalseTotal
if -e $chomped 0 0 0
695 }
696 }
697  
698 # A no-op except it prints the current state of the object to stderr.
699 0 ▶sub objdump {
Subroutine objdump: not called CC=2 SCAR=17.9
Pod documented
700 0 my $self = shift;
701 0 ▶ (my $obj = shift || 'argv') =~ s%^\$%%;
Condition0%0/2
shift() || 'argv'
l!l
00
MC/DC0%0/1
shift() || 'argv'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
702 0 require Data::Dumper;
703 0 print STDERR Data::Dumper->new([$self], [$obj])->Dumpxs;
704 0 return $self;
705 }
706  
707 2 ▶sub readonly {
Subroutine readonly: called CC=5 SCAR=19.0
Pod documented
708 2 my $self = shift;
709 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
710 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 2 2
711 0 $self->{AV_READONLY} = shift;
712 0 return $self;
713 } else {
714 2 ▶ if (exists($self->{AV_READONLY})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'AV_READONLY'}) { } 0 2 2
715 0 return $self->{AV_READONLY}; # instance
716 } else {
717 2 my $class = ref $self;
718 2 ▶ if ($class && exists($class->{AV_READONLY})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class and exists $class->{'AV_READONLY'}) { } 0 2 2
Condition33%1/3
$class and exists $class->{"AV_READONLY"}
!ll&&!rl&&r
020
MC/DC0%0/2
$class and exists $class->{"AV_READONLY"}
$class exists $class->{"AV_READONLY"}
Truth table33%1/3
A and B
A= $classB= exists $class->{"AV_READONLY"}
ABresult
0X0
100
111
719 0 return $class->{AV_READONLY}; # class
720 } else {
721 2 return 'no';
722 }
723 }
724 }
725 }
726  
727 2 ▶sub _read_only {
Subroutine _read_only: called CC=1 SCAR=0.0
728 2 my $self = shift;
729 2 return $self->readonly =~ /^y/i;
730 }
731  
732 # Hidden method for printing debug output.
733 4 ▶sub _dbg {
Subroutine _dbg: called CC=17 SCAR=40.8
734 4 my $self = shift;
735 4 my($level, $prefix, $fh, @txt) = @_;
736 4 my @tmp = @txt;
737 4 ▶ for (@tmp) { $_ = qq("$_") if /\s/ && !/^"/ }
Branch: 1 branch
BranchTrueFalseTotal
if /\s/ and not /^"/ 0 8 8
Condition33%1/3
/\s/ and not /^"/
!ll&&!rl&&r
800
MC/DC0%0/2
/\s/ and not /^"/
/\s/ not /^"/
Truth table33%1/3
A and not(B)
A= /\s/B= not /^"/
ABresult
0X0
100
111
738  
739 # Print all EV's that were added to or modified from the real env.
740 4 my $envp = $self->envp;
741 4 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) 0 4 4
742 0 for (sort keys %$envp) {
743 0 ▶ next if $ENV{$_} && $ENV{$_} eq $envp->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{$_} and $ENV{$_} eq $envp->{$_} 0 0 0
Condition0%0/3
$ENV{$_} and $ENV{$_} eq $envp->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{$_} and $ENV{$_} eq $envp->{$_}
$ENV{$_} $ENV{$_} eq $envp->{$_}
Truth table0%0/3
A and B
A= $ENV{$_}B= $ENV{$_} eq $envp->{$_}
ABresult
0X0
100
111
744 0 print $fh "+ [\$$_=", $envp->{$_}, "]\n";
745 }
746 }
747  
748 4 ▶ $self->objdump if $level >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $level >= 3 0 4 4
749 4 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
750 4 ▶ if ($ifd !~ m%^[\d-]*$%) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ifd =~ /^[\d-]*$/) { } 0 4 4
elsif ($ifd < 0) { } 0 4 4
751 0 $ifd =~ s%/%\\%g if MSWIN;
752 0 push(@tmp, $ifd);
753 } elsif ($ifd < 0) {
754 0 push(@tmp, "<$NUL");
755 }
756 4 ▶ if ($ofd !~ m%^[\d-]*$%) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $ofd =~ /^[\d-]*$/) { } 0 4 4
elsif ($ofd <= 0) { } 1 3 4
elsif ($ofd != 1) { } 0 3 3
757 0 $ofd =~ s%/%\\%g if MSWIN;
758 0 push(@tmp, $ofd);
759 } elsif ($ofd <= 0) {
760 1 push(@tmp, "1>$NUL");
761 } elsif ($ofd != 1) {
762 0 push(@tmp, "1>&$ofd");
763 }
764 4 ▶ if ($efd !~ m%^[\d-]*$%) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $efd =~ /^[\d-]*$/) { } 0 4 4
elsif ($efd <= 0) { } 0 4 4
elsif ($efd != 2) { } 0 4 4
765 0 $efd =~ s%/%\\%g if MSWIN;
766 0 push(@tmp, "2$efd");
767 } elsif ($efd <= 0) {
768 0 push(@tmp, "2>$NUL");
769 } elsif ($efd != 2) {
770 0 push(@tmp, "2>&$efd");
771 }
772 4 print $fh "$prefix @tmp\n";
773 }
774  
775 # Attempt to derive the value of ARG_MAX (the maximum command-line
776 # length) for the current platform. Windows isn't really POSIX and
777 # in my tests POSIX::ARG_MAX() usually throws an exception.
778 # Therefore, on Windows we catch the exception and set the value
779 # to 32767. I don't know what the actual limit is but 32K seems to
780 # work whereas 64K fails and I haven't tried to narrow that range
781 # (actually a bit of subsequent testing showed 48000 to work and
782 # 50000 to fail, but I still prefer to depend on a round number).
783 # On other platforms, if ARG_MAX is missing we use _POSIX_ARG_MAX
784 # (4096) # as the default (that being the smallest value of ARG_MAX
785 # allowed by the POSIX standard).
786 {
787 1 my($_argmax, $_pathmax);
788 1 ▶ sub _arg_max {
Subroutine _arg_max: called CC=2 SCAR=7.0
789 1 require Config;
790 1 ▶ if (!defined($_argmax)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_argmax) 1 0 1
791 1 $_argmax = MSWIN ? 32767 : 4096;
792 1 eval { require POSIX; $_argmax = POSIX::ARG_MAX(); };
793 # The terminating NULL of argv.
794 1 $_argmax -= $Config::Config{ptrsize};
795 }
796 1 return $_argmax;
797 }
798 2 ▶ sub _path_max {
Subroutine _path_max: called CC=2 SCAR=6.9
799 2 ▶ if (!defined($_pathmax)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_pathmax) 1 1 2
800 1 $_pathmax = MSWIN ? 260 : 1024;
801 1 eval { require POSIX; $_pathmax = POSIX::PATH_MAX(); };
802 }
803 2 return $_pathmax;
804 }
805 }
806  
807 # Determine the size of the environment block for subtraction
808 # from the calculated value of ARG_MAX. We allow for an equals
809 # sign and terminating null in each EV, plus the pointer
810 # within the environ array that references it.
811 # Note: Windows limits do not appear to include the environment block.
812 1 ▶sub _env_size {
Subroutine _env_size: called CC=3 SCAR=11.0
813 1 require Config;
814 1 my $envlen = 0;
815 1 my $ptrsize = $Config::Config{ptrsize};
816 1 for my $ev (keys %ENV) {
817 28 $envlen += length($ev);
818 28 ▶ $envlen += length($ENV{$ev}) if $ENV{$ev};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{$ev} 26 2 28
819 28 $envlen += 2 + $ptrsize;
820 }
821 # Need one more pointer's worth for the terminating NULL in 'environ'.
822 1 return $envlen + $ptrsize;
823 }
824  
825 # In the case where the user wants to do qxargs-style chunking by
826 # buffer length rather than argument count, we need to keep pushing
827 # args onto said buffer till we run out of room.
828 0 ▶sub _chunk_by_length {
Subroutine _chunk_by_length: not called CC=4 SCAR=30.0
829 0 require Config;
830 0 my ($args, $max) = @_;
831 0 my @chunk = ();
832 0 my $chunklen = 0;
833 0 my $extra = $Config::Config{ptrsize} + 1;
834 0 ▶ while (grep {defined} @{$args}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_;} @{$args;}) 0 0 0
835 # Reached max length?
836 0 ▶ if (($chunklen + length(${$args}[0]) + $extra) >= $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunklen + length(do { $args }->[0]) + $extra >= $max) { } 0 0 0
837 # Always send at least one chunk no matter what.
838 0 ▶ push(@chunk, shift(@{$args})) unless @chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless @chunk 0 0 0
839 0 last;
840 } else {
841 0 $chunklen += length(${$args}[0]) + $extra;
842 0 push(@chunk, shift(@{$args}));
843 }
844 }
845 #printf STDERR "CHUNK: $chunklen (MAX=$max, LEFT=%d)\n", scalar(@{$args});
846 0 return @chunk;
847 }
848  
849 # Wrapper around Perl's exec(). Strawberry Perl 5.12 warns...
850 1 ▶{ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
851 1 ▶sub exec {
Subroutine exec: called CC=32 SCAR=65.2
Pod documented
852 1 ▶ $class->new(@_)->exec if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 1 1
Condition33%1/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
001
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
853 1 my $self = shift;
854 1 ▶ if ((ref($self) ne $class) && $self->ipc_childsafe) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne $class and $self->ipc_childsafe) { } 0 1 1
Condition33%1/3
ref $self ne $class and $self->ipc_childsafe
!ll&&!rl&&r
100
MC/DC0%0/2
ref $self ne $class and $self->ipc_childsafe
ref $self ne $class $self->ipc_childsafe
Truth table33%1/3
A and B
A= ref $self ne $classB= $self->ipc_childsafe
ABresult
0X0
100
111
855 0 ▶ exit($self->system(@_) || $self->ipc_childsafe->finish);
Condition0%0/3
$self->system(@_) || $self->ipc_childsafe->finish
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->system(@_) || $self->ipc_childsafe->finish
$self->system(@_) $self->ipc_childsafe->finish
Truth table0%0/3
A || B
A= $self->system(@_)B= $self->ipc_childsafe->finish
ABresult
1X1
011
000
856 } elsif (MSWIN && $self->execwait) {
857 exit($self->system(@_) >> 8);
858 } else {
859 1 my $envp = $self->envp;
860 1 my $dbg = $self->dbglevel;
861 1 my @cmd = (@{$self->{AV_PROG}},
862 1 $self->_sets2opts(@_), @{$self->{AV_ARGS}});
863 1 ▶ if ($self->noexec && !$self->_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noexec and not $self->_read_only) { } 1 0 1
Condition33%1/3
$self->noexec and not $self->_read_only
!ll&&!rl&&r
001
MC/DC0%0/2
$self->noexec and not $self->_read_only
$self->noexec not $self->_read_only
Truth table33%1/3
A and not(B)
A= $self->noexecB= not $self->_read_only
ABresult
0X0
100
111
864 1 $self->_dbg($dbg, '-', \*STDERR, @cmd);
865 } else {
866 0 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
867 0 ▶ $self->_dbg($dbg, '+', \*STDERR, @cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 0 0
868 0 open(_I, '<&STDIN');
869 0 open(_O, '>&STDOUT');
870 0 open(_E, '>&STDERR');
871 0 ▶ if ($ifd !~ m%^[\d-]*$%) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ifd =~ /^[\d-]*$/) { } 0 0 0
elsif ($ifd < 0) { } 0 0 0
872 0 ▶ open(STDIN, $ifd) || warn "$ifd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, $ifd or warn "${ifd}: $!" 0 0 0
873 } elsif ($ifd < 0) {
874 0 ▶ open(STDIN, "<$NUL") || warn "STDIN: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<$NUL" or warn "STDIN: $!" 0 0 0
875 } else {
876 0 ▶ warn "Warning: illegal value '$ifd' for stdin" if $ifd > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd > 0 0 0 0
877 }
878 0 ▶ if ($ofd !~ m%^[\d-]*$% && !$self->quiet) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $ofd =~ /^[\d-]*$/ || $self->quiet) { } 0 0 0
elsif ($ofd <= 0 or $self->quiet) { } 0 0 0
elsif ($ofd == 2) { } 0 0 0
elsif ($ofd != 1) { } 0 0 0
Condition0%0/3
$ofd =~ /^[\d-]*$/ || $self->quiet
l!l&&r!l&&!r
000
MC/DC0%0/2
$ofd =~ /^[\d-]*$/ || $self->quiet
$ofd =~ /^[\d-]*$/ $self->quiet
Truth table0%0/3
A || B
A= $ofd =~ /^[\d-]*$/B= $self->quiet
ABresult
1X1
011
000
879 0 ▶ open(STDOUT, $ofd) || warn "$ofd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, $ofd or warn "${ofd}: $!" 0 0 0
880 ▶ } elsif ($ofd <= 0 || $self->quiet) {
Condition0%0/3
$ofd <= 0 or $self->quiet
l!l&&r!l&&!r
000
MC/DC0%0/2
$ofd <= 0 or $self->quiet
$ofd <= 0 $self->quiet
Truth table0%0/3
A or B
A= $ofd <= 0B= $self->quiet
ABresult
1X1
011
000
881 0 ▶ open(STDOUT, ">$NUL") || warn "STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">$NUL" or warn "STDOUT: $!" 0 0 0
882 } elsif ($ofd == 2) {
883 0 ▶ open(STDOUT, '>&STDERR') || warn "Can't dup stdout";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&STDERR" or warn "Can't dup stdout" 0 0 0
884 } elsif ($ofd != 1) {
885 0 warn "Warning: illegal value '$ofd' for stdout";
886 }
887 0 ▶ if ($efd !~ m%^[\d-]*$%) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $efd =~ /^[\d-]*$/) { } 0 0 0
elsif ($efd <= 0) { } 0 0 0
elsif ($efd == 1) { } 0 0 0
elsif ($efd > 2) { } 0 0 0
888 0 ▶ open(STDERR, $efd) || warn "$efd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, $efd or warn "${efd}: $!" 0 0 0
889 } elsif ($efd <= 0) {
890 0 ▶ open(STDERR, ">$NUL") || warn "STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">$NUL" or warn "STDERR: $!" 0 0 0
891 } elsif ($efd == 1) {
892 0 ▶ open(STDERR, '>&STDOUT') || warn "Can't dup stderr";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or warn "Can't dup stderr" 0 0 0
893 } elsif ($efd > 2) {
894 0 warn "Warning: illegal value '$efd' for stderr";
895 }
896 0 my $rc;
897 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
898 0 local %ENV = %$envp;
899 0 $rc = exec(@cmd);
900 } else {
901 0 $rc = exec(@cmd);
902 }
903 # Shouldn't get here but defensive programming and all that ...
904 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
905 0 my $error = "$!";
906 0 open(STDIN, '<&_I'); close(_I);
907 0 open(STDOUT, '>&_O'); close(_O);
908 0 open(STDERR, '>&_E'); close(_E);
909 0 die "$0: $cmd[0]: $error\n";
910 }
911 }
912 }
913 }}
914  
915 1 ▶sub lastresults {
Subroutine lastresults: called CC=3 SCAR=16.8
Pod documented
916 2 my $self = shift;
917 2 ▶ if (defined(wantarray)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 2 2
918 0 my @qxarr = @{$self->{AV_LASTRESULTS}};
919 0 my $rc = shift @qxarr;
920 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
921 0 return @qxarr;
922 } else {
923 0 return $rc;
924 }
925 } else {
926 2 $self->{AV_LASTRESULTS} = \@_;
927 }
928 }
929  
930 # Internal - service method for system/exec to call into IPC::ChildSafe.
931 0 ▶sub _ipccmd {
Subroutine _ipccmd: not called CC=4 SCAR=30.0
932 0 my $self = shift;
933 0 my $cmd = shift;
934 # Throw out the prog name since it's already running
935 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
936 0 $cmd = "@_";
937 } else {
938 0 $cmd =~ s/^\w+\s*//;
939 }
940 # Hack - there's an "impedance mismatch" between instance
941 # methods in this class and the class methods in
942 # IPC::ChildSafe, so we toggle the attrs for every cmd.
943 0 my $csobj = $self->ipc_childsafe;
944 0 $csobj->dbglevel($self->dbglevel);
945 0 ▶ $csobj->noexec($self->noexec) if $self->noexec && !$self->_read_only;
Branch: 1 branch
BranchTrueFalseTotal
if $self->noexec and not $self->_read_only 0 0 0
Condition0%0/3
$self->noexec and not $self->_read_only
!ll&&!rl&&r
000
MC/DC0%0/2
$self->noexec and not $self->_read_only
$self->noexec not $self->_read_only
Truth table0%0/3
A and not(B)
A= $self->noexecB= not $self->_read_only
ABresult
0X0
100
111
946 0 my %results = $csobj->cmd($cmd);
947 0 return %results;
948 }
949  
950 # Wrapper around Perl's system().
951 9 ▶sub system {
Subroutine system: called CC=66 SCAR=70.6
Pod documented
952 9 ▶ return $class->new(@_)->system if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 9 9
Condition33%1/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
009
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
953 9 my $self = shift;
954 9 my $envp = $self->envp;
955 9 my $rc = 0;
956 9 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
957 9 ▶ $self->args($self->glob) if $self->autoglob;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autoglob 0 9 9
958 9 my @prog = @{$self->{AV_PROG}};
959 9 my @opts = $self->_sets2opts(@_);
960 9 my @args = @{$self->{AV_ARGS}};
961 9 ▶ my $childsafe = ((ref($self) ne $class) &&
Branch: 1 branch
BranchTrueFalseTotal
ref $self ne $class && $self->ipc_childsafe && !$self->mustexec ? : 0 9 9
Condition33%2/6
ref $self ne $class and $self->ipc_childsafe and not $self->mustexec
!ll&&!rl&&r
900
ref $self ne $class and $self->ipc_childsafe
!ll&&!rl&&r
900
MC/DC0%0/3
ref $self ne $class and $self->ipc_childsafe and not $self->mustexec
ref $self ne $class $self->ipc_childsafe not $self->mustexec
Truth table25%1/4
A and B and not(C)
A= ref $self ne $classB= $self->ipc_childsafeC= not $self->mustexec
ABCresult
0XX0
10X0
1100
1111
962 $self->ipc_childsafe && !$self->mustexec) ? 1 : 0;
963  
964 # These potentially modify their arguments in place.
965 9 $self->argpathnorm(@prog, @args);
966 9 ▶ $self->quote(@prog, @opts, @args)
Branch: 1 branch
BranchTrueFalseTotal
if $childsafe and $self->autoquote 0 9 9
Condition33%1/3
$childsafe and $self->autoquote
!ll&&!rl&&r
900
MC/DC0%0/2
$childsafe and $self->autoquote
$childsafe $self->autoquote
Truth table33%1/3
A and B
A= $childsafeB= $self->autoquote
ABresult
0X0
100
111
967 if (((MSWIN && (@prog + @opts + @args) > 1) || $childsafe) &&
968 $self->autoquote);
969 9 my @cmd = (@prog, @opts, @args);
970 9 my $dbg = $self->dbglevel;
971 9 ▶ if ($childsafe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childsafe) { } 0 9 9
972 0 ▶ $self->_addstats("@prog", scalar @args) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 0 0
973 0 ▶ $self->warning("cannot change \%ENV of child process") if $envp;
Branch: 1 branch
BranchTrueFalseTotal
if $envp 0 0 0
974 0 ▶ $self->warning("cannot close stdin of child process") if $ifd;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd 0 0 0
975 0 my %results = $self->_ipccmd(@cmd);
976 0 $? = $rc = ($results{status} << 8);
977 0 ▶ if ($self->quiet) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->quiet) { } 0 0 0
elsif (not $ofd =~ /^[\d-]*$/) { } 0 0 0
elsif ($ofd == 2) { } 0 0 0
978 # say nothing
979 } elsif ($ofd !~ m%^[\d-]*$%) {
980 0 ▶ if (open(OFD, $ofd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open OFD, $ofd) { } 0 0 0
981 0 ▶ print OFD @{$results{stdout}} if @{$results{stdout}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stdout"};} 0 0 0
982 0 close OFD;
983 } else {
984 0 warn "$ofd: $!";
985 }
986 } elsif ($ofd == 2) {
987 0 ▶ print STDERR @{$results{stdout}} if @{$results{stdout}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stdout"};} 0 0 0
988 } else {
989 0 ▶ warn "Warning: illegal value '$ofd' for stdout" if $ofd > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $ofd > 2 0 0 0
990 0 ▶ print STDOUT @{$results{stdout}} if @{$results{stdout}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stdout"};} 0 0 0
991 }
992 0 ▶ if ($efd == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($efd == 1) { } 0 0 0
elsif (not $efd =~ /^[\d-]*$/) { } 0 0 0
993 0 ▶ print STDOUT @{$results{stderr}} if @{$results{stderr}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stderr"};} 0 0 0
994 } elsif ($efd !~ m%^[\d-]*$%) {
995 0 ▶ if (open(EFD, $efd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open EFD, $efd) { } 0 0 0
996 0 ▶ print EFD @{$results{stderr}} if @{$results{stderr}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stderr"};} 0 0 0
997 0 close EFD;
998 } else {
999 0 warn "$efd: $!";
1000 }
1001 } else {
1002 0 ▶ warn "Warning: illegal value '$efd' for stderr" if $efd > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $efd > 2 0 0 0
1003 0 ▶ print STDERR @{$results{stderr}} if @{$results{stderr}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$results{"stderr"};} 0 0 0
1004 }
1005 } else {
1006 # Reset to defaults in dbg mode (what's this for?)
1007 9 ▶ ($ofd, $efd) = (1, 2) if defined($dbg) && $dbg > 2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbg and $dbg > 2 0 9 9
Condition33%1/3
defined $dbg and $dbg > 2
!ll&&!rl&&r
090
MC/DC0%0/2
defined $dbg and $dbg > 2
defined $dbg $dbg > 2
Truth table33%1/3
A and B
A= defined $dbgB= $dbg > 2
ABresult
0X0
100
111
1008 9 ▶ if ($self->noexec && !$self->_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noexec and not $self->_read_only) 1 8 9
Condition66%2/3
$self->noexec and not $self->_read_only
!ll&&!rl&&r
801
MC/DC50%1/2
$self->noexec and not $self->_read_only
$self->noexec not $self->_read_only
Truth table66%2/3
A and not(B)
A= $self->noexecB= not $self->_read_only
ABresult
0X0
100
111
1009 1 $self->_dbg($dbg, '-', \*STDERR, @cmd);
1010 1 return 0;
1011 }
1012 8 open(_I, '<&STDIN');
1013 8 open(_O, '>&STDOUT');
1014 8 open(_E, '>&STDERR');
1015  
1016 8 ▶ if ($ifd !~ m%^[\d-]*$%) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ifd =~ /^[\d-]*$/) { } 0 8 8
elsif ($ifd < 0) { } 0 8 8
1017 0 ▶ open(STDIN, $ifd) || warn "$ifd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, $ifd or warn "${ifd}: $!" 0 0 0
1018 } elsif ($ifd < 0) {
1019 0 ▶ open(STDIN, "<$NUL") || warn "STDIN: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<$NUL" or warn "STDIN: $!" 0 0 0
1020 } else {
1021 8 ▶ warn "Warning: illegal value '$ifd' for stdin" if $ifd > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd > 0 0 8 8
1022 }
1023  
1024 8 ▶ if ($ofd !~ m%^[\d-]*$% && !$self->quiet) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $ofd =~ /^[\d-]*$/ || $self->quiet) { } 0 8 8
elsif ($ofd <= 0 or $self->quiet) { } 4 4 8
elsif ($ofd == 2) { } 0 4 4
elsif ($ofd != 1) { } 0 4 4
Condition33%1/3
$ofd =~ /^[\d-]*$/ || $self->quiet
l!l&&r!l&&!r
800
MC/DC0%0/2
$ofd =~ /^[\d-]*$/ || $self->quiet
$ofd =~ /^[\d-]*$/ $self->quiet
Truth table33%1/3
A || B
A= $ofd =~ /^[\d-]*$/B= $self->quiet
ABresult
1X1
011
000
1025 0 ▶ open(STDOUT, $ofd) || warn "$ofd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, $ofd or warn "${ofd}: $!" 0 0 0
1026 ▶ } elsif ($ofd <= 0 || $self->quiet) {
Condition66%2/3
$ofd <= 0 or $self->quiet
l!l&&r!l&&!r
404
MC/DC50%1/2
$ofd <= 0 or $self->quiet
$ofd <= 0 $self->quiet
Truth table66%2/3
A or B
A= $ofd <= 0B= $self->quiet
ABresult
1X1
011
000
1027 4 ▶ open(STDOUT, ">$NUL") || warn "STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">$NUL" or warn "STDOUT: $!" 4 0 4
1028 } elsif ($ofd == 2) {
1029 0 ▶ open(STDOUT, '>&STDERR') || warn "Can't dup stdout";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&STDERR" or warn "Can't dup stdout" 0 0 0
1030 } elsif ($ofd != 1) {
1031 0 warn "Warning: illegal value '$ofd' for stdout";
1032 }
1033  
1034 8 ▶ if ($efd !~ m%^[\d-]*$%) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $efd =~ /^[\d-]*$/) { } 0 8 8
elsif ($efd <= 0) { } 2 6 8
elsif ($efd == 1) { } 0 6 6
elsif ($efd > 2) { } 0 6 6
1035 0 ▶ open(STDERR, $efd) || warn "$efd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, $efd or warn "${efd}: $!" 0 0 0
1036 } elsif ($efd <= 0) {
1037 2 ▶ open(STDERR, ">$NUL") || warn "STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">$NUL" or warn "STDERR: $!" 2 0 2
1038 } elsif ($efd == 1) {
1039 0 ▶ open(STDERR, '>&STDOUT') || warn "Can't dup stderr";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or warn "Can't dup stderr" 0 0 0
1040 } elsif ($efd > 2) {
1041 0 warn "Warning: illegal value '$efd' for stderr";
1042 }
1043  
1044 8 my $limit = $self->syxargs;
1045 8 ▶ if ($limit && @args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @args) { } 0 8 8
Condition33%1/3
$limit and @args
!ll&&!rl&&r
800
MC/DC0%0/2
$limit and @args
$limit @args
Truth table33%1/3
A and B
A= $limitB= @args
ABresult
0X0
100
111
1046 0 ▶ if ($limit == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit == -1) 0 0 0
1047 0 $limit = -_arg_max();
1048 0 $limit += _env_size() if !MSWIN;
1049 # There's no shell used in list-form system() ...
1050 0 $limit += _path_max(); # for @prog
1051 0 $limit += length("@opts");
1052 }
1053 0 ▶ while (my @chunk = $limit > 0 ?
Branch: 2 branches
BranchTrueFalseTotal
if (my(@chunk) = $limit > 0 ? splice(@args, 0, $limit) : _chunk_by_length(\@args, abs $limit)) 0 0 0
$limit > 0 ? : 0 0 0
1054 splice(@args, 0, $limit) :
1055 _chunk_by_length(\@args, abs($limit))) {
1056 0 ▶ $self->_addstats("@prog", scalar @chunk) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 0 0
1057 0 @cmd = (@prog, @opts, @chunk);
1058 0 ▶ $self->_dbg($dbg, '+', \*_E, @cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 0 0
1059 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
1060 0 local %ENV = %$envp;
1061 0 $rc |= system @cmd;
1062 } else {
1063 0 $rc |= system @cmd;
1064 }
1065 }
1066 } else {
1067 8 ▶ $self->_addstats("@prog", scalar @args) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 8 8
1068 8 ▶ $self->_dbg($dbg, '+', \*_E, @cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 2 6 8
1069 8 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 8 8
1070 0 local %ENV = %$envp;
1071 0 $rc = system @cmd;
1072 } else {
1073 8 $rc = system @cmd;
1074 }
1075 }
1076 8 open(STDIN, '<&_I'); close(_I);
1077 8 open(STDOUT, '>&_O'); close(_O);
1078 8 open(STDERR, '>&_E'); close(_E);
1079 }
1080 8 ▶ print STDERR "+ (\$? == $?)\n" if $dbg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg > 1 0 8 8
1081 8 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 2 6 8
1082 2 $self->lastresults($?>>8, ());
1083 2 $self->fail($self->syfail);
1084 }
1085 8 return $rc;
1086 }
1087  
1088 # Wrapper around Perl's qx(), aka backquotes.
1089 1 ▶sub qx {
Subroutine qx: called CC=49 SCAR=63.4
Pod documented
1090 1 ▶ return $class->new(@_)->qx if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 1 1
Condition33%1/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
001
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
1091 1 my $self = shift;
1092 1 my $envp = $self->envp;
1093 1 my @prog = @{$self->{AV_PROG}};
1094 1 my @opts = $self->_sets2opts(@_);
1095 1 my @args = @{$self->{AV_ARGS}};
1096 1 ▶ my $childsafe = ((ref($self) ne $class) &&
Branch: 1 branch
BranchTrueFalseTotal
ref $self ne $class && $self->ipc_childsafe && !$self->mustexec ? : 0 1 1
Condition33%2/6
ref $self ne $class and $self->ipc_childsafe and not $self->mustexec
!ll&&!rl&&r
100
ref $self ne $class and $self->ipc_childsafe
!ll&&!rl&&r
100
MC/DC0%0/3
ref $self ne $class and $self->ipc_childsafe and not $self->mustexec
ref $self ne $class $self->ipc_childsafe not $self->mustexec
Truth table25%1/4
A and B and not(C)
A= ref $self ne $classB= $self->ipc_childsafeC= not $self->mustexec
ABCresult
0XX0
10X0
1100
1111
1097 $self->ipc_childsafe && !$self->mustexec) ? 1 : 0;
1098  
1099 # These potentially modify their arguments in place.
1100 1 @args = $self->glob(@args)
1101 if MSWIN && $self->autoglob && $childsafe;
1102 1 $self->argpathnorm(@prog, @args);
1103 1 ▶ $self->quote(@prog, @opts, @args)
Branch: 1 branch
BranchTrueFalseTotal
if @prog + @opts + @args > 1 || $childsafe and $self->autoquote 1 0 1
Condition33%2/6
@prog + @opts + @args > 1 || $childsafe and $self->autoquote
!ll&&!rl&&r
001
@prog + @opts + @args > 1 or $childsafe
l!l&&r!l&&!r
100
MC/DC0%0/3
@prog + @opts + @args > 1 || $childsafe and $self->autoquote
@prog + @opts + @args > 1 $childsafe $self->autoquote
Truth table20%1/5
A or B and C
A= @prog + @opts + @args > 1B= $childsafeC= $self->autoquote
ABCresult
00X0
1X00
0100
1X11
0111
1104 if (((@prog + @opts + @args) > 1 || $childsafe) && $self->autoquote);
1105  
1106 1 my @cmd = (@prog, @opts, @args);
1107 1 my @data;
1108 1 my $dbg = 0;
1109 1 my $rc = 0;
1110 1 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
1111 1 ▶ my $noexec = $self->noexec && !$self->_read_only;
Condition33%1/3
$self->noexec && !$self->_read_only
!ll&&!rl&&r
100
MC/DC0%0/2
$self->noexec && !$self->_read_only
$self->noexec !$self->_read_only
Truth table33%1/3
A && not(B)
A= $self->noexecB= !$self->_read_only
ABresult
0X0
100
111
1112 1 ▶ if ($childsafe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childsafe) { } 0 1 1
1113 0 ▶ $self->_addstats("@prog", scalar @args) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 0 0
1114 0 ▶ $self->warning("cannot change \%ENV of child process") if $envp;
Branch: 1 branch
BranchTrueFalseTotal
if $envp 0 0 0
1115 0 ▶ $self->warning("cannot close stdin of child process") if $ifd;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd 0 0 0
1116 0 ▶ if ($noexec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) { } 0 0 0
1117 0 $self->_dbg($dbg, '-', \*STDERR, @cmd);
1118 } else {
1119 0 my %results = $self->_ipccmd(@cmd);
1120 0 ▶ if ($ofd <= 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ofd <= 0) { } 0 0 0
elsif ($ofd == 1) { } 0 0 0
elsif ($ofd == 2) { } 0 0 0
1121 # ignore the results
1122 } elsif ($ofd == 1) {
1123 0 push(@data, @{$results{stdout}});
1124 } elsif ($ofd == 2) {
1125 0 print STDERR @{$results{stdout}};
1126 } else {
1127 0 warn "Warning: illegal value '$ofd' for stdout";
1128 }
1129 0 ▶ if ($efd == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($efd == 1) { } 0 0 0
1130 0 push(@data, @{$results{stderr}});
1131 } else {
1132 0 ▶ print STDERR @{$results{stderr}} if $efd;
Branch: 1 branch
BranchTrueFalseTotal
if $efd 0 0 0
1133 0 ▶ warn "Warning: illegal value '$efd' for stderr" if $efd > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $efd > 2 0 0 0
1134 }
1135 0 $? = $rc = $results{status} << 8;
1136 }
1137 } else {
1138 1 $dbg = $self->dbglevel;
1139 # Reset to defaults in dbg mode (what's this for?)
1140 1 ▶ ($ofd, $efd) = (1, 2) if defined($dbg) && $dbg > 2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbg and $dbg > 2 0 1 1
Condition33%1/3
defined $dbg and $dbg > 2
!ll&&!rl&&r
010
MC/DC0%0/2
defined $dbg and $dbg > 2
defined $dbg $dbg > 2
Truth table33%1/3
A and B
A= defined $dbgB= $dbg > 2
ABresult
0X0
100
111
1141 1 my $limit = $self->qxargs;
1142 1 ▶ if ($limit && @args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and @args) { } 1 0 1
Condition33%1/3
$limit and @args
!ll&&!rl&&r
001
MC/DC0%0/2
$limit and @args
$limit @args
Truth table33%1/3
A and B
A= $limitB= @args
ABresult
0X0
100
111
1143 1 ▶ if ($limit == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit == -1) 1 0 1
1144 1 $limit = -_arg_max();
1145 1 $limit += _env_size() if !MSWIN;
1146 1 $limit += _path_max(); # for the shell
1147 1 $limit += length('-c');
1148 1 $limit += _path_max(); # for @prog
1149 1 $limit += length("@opts");
1150 }
1151 1 ▶ while (my @chunk = $limit > 0 ?
Branch: 2 branches
BranchTrueFalseTotal
if (my(@chunk) = $limit > 0 ? splice(@args, 0, $limit) : _chunk_by_length(\@args, abs $limit)) 1 1 2
$limit > 0 ? : 2 0 2
1152 splice(@args, 0, $limit) :
1153 _chunk_by_length(\@args, abs($limit))) {
1154 1 ▶ $self->_addstats("@prog", scalar @chunk) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 1 1
1155 1 @cmd = (@prog, @opts, @chunk);
1156 1 ▶ if ($noexec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) { } 0 1 1
1157 0 $self->_dbg($dbg, '-', \*STDERR, @cmd);
1158 } else {
1159 1 ▶ $self->_dbg($dbg, '+', \*STDERR, @cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 1 1
1160 1 $self->_qx_stderr(\@cmd, $efd);
1161 1 $self->_qx_stdout(\@cmd, $ofd);
1162 1 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 1 1
1163 0 local %ENV = %$envp;
1164 0 push(@data, qx(@cmd));
1165 } else {
1166 1 push(@data, qx(@cmd));
1167 }
1168 1 ▶ $rc ||= $?;
Condition33%1/3
$rc ||= $?
l!l&&r!l&&!r
001
MC/DC0%0/2
$rc ||= $?
$rc $?
Truth table33%1/3
A ||= B
A= $rcB= $?
ABresult
1X1
011
000
1169 }
1170 }
1171 } else {
1172 0 ▶ $self->_addstats("@prog", scalar @args) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 0 0
1173 0 ▶ if ($noexec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) { } 0 0 0
1174 0 $self->_dbg($dbg, '-', \*STDERR, @cmd);
1175 } else {
1176 0 ▶ $self->_dbg($dbg, '+', \*STDERR, @cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 0 0
1177 0 $self->_qx_stderr(\@cmd, $efd);
1178 0 $self->_qx_stdout(\@cmd, $ofd);
1179 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
1180 0 local %ENV = %$envp;
1181 0 @data = qx(@cmd);
1182 } else {
1183 0 @data = qx(@cmd);
1184 }
1185 0 ▶ $rc ||= $?;
Condition0%0/3
$rc ||= $?
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc ||= $?
$rc $?
Truth table0%0/3
A ||= B
A= $rcB= $?
ABresult
1X1
011
000
1186 }
1187 }
1188 1 ▶ $? = $rc if $rc && ! $?;
Branch: 1 branch
BranchTrueFalseTotal
if $rc and not $? 0 1 1
Condition33%1/3
$rc and not $?
!ll&&!rl&&r
100
MC/DC0%0/2
$rc and not $?
$rc not $?
Truth table33%1/3
A and not(B)
A= $rcB= not $?
ABresult
0X0
100
111
1189 }
1190 1 ▶ print STDERR "+ (\$? == $?)\n" if $dbg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg > 1 0 1 1
1191 1 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 1 1
1192 0 $self->lastresults($?>>8, @data);
1193 0 $self->fail($self->qxfail);
1194 }
1195 1 $self->unixpath(@data) if MSWIN && $self->outpathnorm;
1196 1 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 0 1
1197 0 ▶ print STDERR map {"+ <- $_"} @data if @data && $dbg >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @data and $dbg >= 2 0 1 1
Condition33%1/3
@data and $dbg >= 2
!ll&&!rl&&r
010
MC/DC0%0/2
@data and $dbg >= 2
@data $dbg >= 2
Truth table33%1/3
A and B
A= @dataB= $dbg >= 2
ABresult
0X0
100
111
1198 1 ▶ chomp(@data) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 1 1
1199 1 return @data;
1200 } else {
1201 0 my $data = join('', @data);
1202 0 ▶ print STDERR "+ <- $data" if @data && $dbg >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @data and $dbg >= 2 0 0 0
Condition0%0/3
@data and $dbg >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
@data and $dbg >= 2
@data $dbg >= 2
Truth table0%0/3
A and B
A= @dataB= $dbg >= 2
ABresult
0X0
100
111
1203 0 ▶ chomp($data) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
1204 0 return $data;
1205 }
1206 }
1207 # Can't override qx() in main package so we export an alias instead.
1208 1 *qv = \&qx;
1209  
1210 0 ▶sub pipe {
Subroutine pipe: not called CC=9 SCAR=45.0
Pod documented
1211 0 ▶ return $class->new(@_)->pipe if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
1212  
1213 0 my $self = shift;
1214  
1215 0 my $cb = $self->pipecb;
1216 0 ▶ $self->error("No callback supplied") unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 0 0
1217  
1218 0 my ($pipe, $pid) = $self->readpipe(@_);
1219 0 my $line;
1220 0 my $abort = 0;
1221 0 ▶ while($line = <$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $pipe)) 0 0 0
1222 0 ▶ chomp($line) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
1223 0 my $keepGoing = &$cb($line);
1224 0 ▶ if (!$keepGoing) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keepGoing) 0 0 0
1225 0 ▶ if ($self->_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_read_only) 0 0 0
1226 0 $abort = 1;
1227 0 last;
1228 }
1229 0 $self->warning("Not abortable unless readonly - continuing!");
1230 }
1231 }
1232 0 if (MSWIN && $abort) {
1233 # This is somewhat ugly, but due to perl impl details as well as
1234 # the fact that Windows does not have the proper counterpart to
1235 # SIGPIPE, we'll have to 'help' things along...
1236 #
1237 Argv::Win32Utils::killProcessTree($self, $pid);
1238 }
1239 0 my $rc = close($pipe);
1240 0 ▶ $self->fail($self->qxfail) if !$rc;
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 0 0 0
1241 0 return $rc;
1242 }
1243  
1244 # Wrapper around Perl's "open(FOO, '<cmd> |')" operator.
1245 0 ▶sub readpipe {
Subroutine readpipe: not called CC=13 SCAR=52.0
Pod undocumented
1246 0 ▶ return $class->new(@_)->readpipe if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
1247 0 my $self = shift;
1248 0 my $envp = $self->envp;
1249 0 my @prog = @{$self->{AV_PROG}};
1250 0 my @opts = $self->_sets2opts(@_);
1251 0 my @args = @{$self->{AV_ARGS}};
1252  
1253 # These potentially modify their arguments in place.
1254 0 $self->argpathnorm(@prog, @args);
1255 0 ▶ $self->quote(@prog, @opts, @args)
Branch: 1 branch
BranchTrueFalseTotal
if @prog + @opts + @args > 1 and $self->autoquote 0 0 0
Condition0%0/3
@prog + @opts + @args > 1 and $self->autoquote
!ll&&!rl&&r
000
MC/DC0%0/2
@prog + @opts + @args > 1 and $self->autoquote
@prog + @opts + @args > 1 $self->autoquote
Truth table0%0/3
A and B
A= @prog + @opts + @args > 1B= $self->autoquote
ABresult
0X0
100
111
1256 if (((@prog + @opts + @args) > 1) && $self->autoquote);
1257  
1258 0 my @cmd = (@prog, @opts, @args);
1259 0 my $dbg = 0;
1260 0 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
1261 0 ▶ my $noexec = $self->noexec && !$self->_read_only;
Condition0%0/3
$self->noexec && !$self->_read_only
!ll&&!rl&&r
000
MC/DC0%0/2
$self->noexec && !$self->_read_only
$self->noexec !$self->_read_only
Truth table0%0/3
A && not(B)
A= $self->noexecB= !$self->_read_only
ABresult
0X0
100
111
1262 0 $dbg = $self->dbglevel;
1263 0 ▶ $self->_addstats("@prog", scalar @args) if $Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if $Argv::Summary 0 0 0
1264 0 ▶ if ($noexec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) { } 0 0 0
1265 0 $self->_dbg($dbg, '-', \*STDERR, @cmd, '|');
1266 } else {
1267 0 my $handle;
1268 0 ▶ $self->_dbg($dbg, '+', \*STDERR, @cmd, '|') if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 0 0
1269 0 $self->_qx_stderr(\@cmd, $efd);
1270 0 $self->_qx_stdout(\@cmd, $ofd);
1271 0 my $rc;
1272 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
1273 0 local %ENV = %$envp;
1274 0 $rc = open($handle, "@cmd |");
1275 } else {
1276 0 $rc = open($handle, "@cmd |");
1277 }
1278 0 ▶ $self->fail($self->qxfail) if !$rc || !defined($handle);
Branch: 1 branch
BranchTrueFalseTotal
unless $rc and defined $handle 0 0 0
Condition0%0/3
$rc and defined $handle
!ll&&!rl&&r
000
MC/DC0%0/2
$rc and defined $handle
$rc defined $handle
Truth table0%0/3
A and B
A= $rcB= defined $handle
ABresult
0X0
100
111
1279 0 my $oldfh = select($handle); $| = 1; select($oldfh);
1280 0 ▶ return wantarray ? ($handle, $rc) : $handle;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1281 }
1282 }
1283  
1284 # Internal - provide a warning with std format and caller's context.
1285 0 ▶sub warning {
Subroutine warning: not called CC=2 SCAR=12.2
Pod undocumented
1286 0 my $self = shift;
1287 0 (my $prog = $0) =~ s%.*[/\\]%%;
1288 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1289 0 ▶ carp('Warning: ', ${$self->{AV_PROG}}[-1] || $prog, ': ', @_);
Condition0%0/3
do { $$self{'AV_PROG'} }->[-1] || $prog
l!l&&r!l&&!r
000
MC/DC0%0/2
do { $$self{'AV_PROG'} }->[-1] || $prog
do { $$self{'AV_PROG'} }->[-1] $prog
Truth table0%0/3
A || B
A= do { $$self{'AV_PROG'} }->[-1]B= $prog
ABresult
1X1
011
000
1290 }
1291  
1292 # Internal - provide a fatal error with std format and caller's context.
1293 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=12.2
Pod undocumented
1294 0 my $self = shift;
1295 0 (my $prog = $0) =~ s%.*[/\\]%%;
1296 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1297 0 ▶ croak('Error: ', ${$self->{AV_PROG}}[-1] || $prog, ': ', @_);
Condition0%0/3
do { $$self{'AV_PROG'} }->[-1] || $prog
l!l&&r!l&&!r
000
MC/DC0%0/2
do { $$self{'AV_PROG'} }->[-1] || $prog
do { $$self{'AV_PROG'} }->[-1] $prog
Truth table0%0/3
A || B
A= do { $$self{'AV_PROG'} }->[-1]B= $prog
ABresult
1X1
011
000
1298 }
1299  
1300 # Hack this thing in here to help with *&#$ Windows. We want to hide it
1301 # as much as possible in the hope that a better way may be found
1302 # someday. Thus it's implemented as an "inner class" rather than
1303 # a separate file.
1304 {
1305 1 package Argv::Win32Utils;
1306  
1307 # Preload this to avoid INIT block failure in Win32::API::Type
1308 # (but it may not be installed at all, which is ok).
1309 1 eval "require Win32::API";
1310  
1311 # For internal use only - attempt to kill the process tree stemming from
1312 # the given pid.
1313 # Attempts several ways using various packages that may or may not be
1314 # present.
1315 0 ▶ sub killProcessTree {
Subroutine killProcessTree: not called CC=3 SCAR=24.8
1316 0 my $argv = shift;
1317 0 my $pid = shift;
1318  
1319 # Undocumented way to turn this off in case it causes big problems...
1320 0 ▶ return 0 if $ENV{ARGV_WIN32UTILS_SKIP_KILLPROCESSTREE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"ARGV_WIN32UTILS_SKIP_KILLPROCESSTREE"} 0 0 0
1321  
1322 0 require Win32::Process;
1323
1324 0 my ($implDesc, $impl) = __findImpl($argv);
1325 0 ▶ print STDERR "Using $implDesc...\n" if $argv->dbglevel > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $argv->dbglevel > 1 0 0 0
1326 0 &$impl($argv, $pid);
1327
1328 0 return 0;
1329 }
1330  
1331 # For internal use only - attempt to kill a single process
1332 0 ▶ sub killProcess {
Subroutine killProcess: not called CC=2 SCAR=17.9
1333 0 my $argv = shift;
1334 0 my $pid = shift;
1335  
1336 0 ▶ print STDERR "Killing $pid...\n" if $argv->dbglevel > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $argv->dbglevel > 1 0 0 0
1337 0 return Win32::Process::KillProcess($pid, 0);
1338 }
1339  
1340 # Implementation using Win32::Process::Info
1341 # This pkg can give us a (pruned) pid tree with the expected
1342 # layout right away.
1343 0 ▶ sub __win32_process_info {
Subroutine __win32_process_info: not called CC=1 SCAR=6.9
1344 0 my $argv = shift;
1345 0 my $pid = shift;
1346  
1347 0 my %pidTree = new Win32::Process::Info->Subprocesses($pid);
1348 0 __deepKill($argv, $pid, \%pidTree);
1349
1350 0 return 0;
1351 }
1352  
1353 # Implementation using Win32::ToolHelp
1354 # this pkg gives a different view - rework into a pid tree
1355 # by 1) enter all pids as keys, and then 2) add their children.
1356 0 ▶ sub __win32_toolhelp {
Subroutine __win32_toolhelp: not called CC=3 SCAR=24.8
1357 0 my $argv = shift;
1358 0 my $pid = shift;
1359  
1360 0 my %pidTree;
1361 0 my @allProcesses = Win32::ToolHelp::GetProcesses();
1362 0 $pidTree{$_->[1]} = [] foreach (@allProcesses);
1363 0 push(@{$pidTree{$_->[5]}}, $_->[1]) foreach (@allProcesses);
1364 0 __deepKill($argv, $pid, \%pidTree);
1365  
1366 0 return 0;
1367 }
1368  
1369 # Kill processes depth first by following the tree.
1370 0 ▶ sub __deepKill {
Subroutine __deepKill: not called CC=2 SCAR=17.9
1371 0 my $argv = shift;
1372 0 my $pid = shift;
1373 0 my $pidTree = shift;
1374
1375 # give a parent an opportunity to terminate by itself
1376 # which is likely when their child died
1377 #
1378 0 foreach my $childPid (@{$pidTree->{$pid}}) {
1379 0 __deepKill($argv, $childPid, $pidTree);
1380 }
1381 0 killProcess($argv, $pid);
1382 }
1383  
1384 # Dynamically find an implementation that can figure out
1385 # the process tree and kill it.
1386 # Fall back to just kill the root pid (which may just be enough).
1387 0 ▶ sub __findImpl {
Subroutine __findImpl: not called CC=3 SCAR=24.8
1388 0 my $argv = shift;
1389
1390 # begin with a list to ensure a preferred search order
1391 # but put the list in a hash for easy lookup
1392 #
1393 0 my @implList = (
1394 "Win32::ToolHelp", \&__win32_toolhelp,
1395 "Win32::Process::Info", \&__win32_process_info,
1396 );
1397 0 my %implHash = @implList;
1398 0 foreach my $implName (@implList) {
1399 0 eval "use $implName";
1400 0 ▶ return ("$implName (tree capable)", $implHash{$implName}) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
1401 }
1402
1403 # no luck, use fallback
1404 0 my @helpers = keys(%implHash);
1405 0 $argv->warning("No process tree helper found - install any of these packages: [@helpers]");
1406 0 return ("Win32::Process (not tree capable)", \&killProcess);
1407 }
1408  
1409 1 1;
1410 }
1411  
1412 1 1;
1413  
1414 __END__
↑ Summary /dev/null »