blib/lib/Shell.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 66.6% 16 / 24 Conditioncond 63.6% 7 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 81.1% 99 / 122 CC 19 SCAR 19.6
CC
19
Cov
83%
__ANON__
14.6
_make_cmd
4.3
import
3.0
CRAP 7.1
↑ Summary
1 package Shell;
2 2 ▶use 5.006_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our($capture_stderr, $raw, $VERSION, $AUTOLOAD);
8  
9 2 $VERSION = '0.72_01';
10 2 $VERSION = eval $VERSION;
11  
12 1 ▶sub new { bless \my $foo, shift }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
14  
15 sub import {
16 2 ▶ my $self = shift;
Subroutine import: called CC=3 SCAR=11.1
17 2 my ($callpack, $callfile, $callline) = caller;
18 2 my @EXPORT;
19 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 2 2
20 0 @EXPORT = @_;
21 } else {
22 2 @EXPORT = 'AUTOLOAD';
23 }
24 2 foreach my $sym (@EXPORT) {
25 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 *{"${callpack}::$sym"} = \&{"Shell::$sym"};
27 }
28 }
29  
30 # NOTE: this is used to enable constant folding in
31 # expressions like (OS eq 'MSWin32') and
32 # (OS eq 'os2') just like it happened in 0.6 version
33 # which used eval "string" to install subs on the fly.
34 2 ▶use constant OS => $^O;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =begin private
37  
38 =item B<_make_cmd>
39  
40 $sub = _make_cmd($cmd);
41 $sub = $shell->_make_cmd($cmd);
42  
43 Creates a closure which invokes the system command C<$cmd>.
44  
45 =end private
46  
47 =cut
48  
49 sub _make_cmd {
50 3 ▶ shift if ref $_[0] && $_[0]->isa( 'Shell' );
Subroutine _make_cmd: called CC=4 SCAR=14.5
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $_[0]->isa("Shell") 0 3 3
Condition33%1/3
ref $_[0] and $_[0]->isa("Shell")
!ll&&!rl&&r
300
MC/DC0%0/2
ref $_[0] and $_[0]->isa("Shell")
ref $_[0] $_[0]->isa("Shell")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("Shell")
ABresult
0X0
100
111
51 3 my $cmd = shift;
52 3 my $null = File::Spec::Functions::devnull();
53 3 ▶ $Shell::capture_stderr ||= 0;
Condition100%2/2
$Shell::capture_stderr ||= 0
l!l
12
MC/DC100%1/1
$Shell::capture_stderr ||= 0
$Shell::capture_stderr
Truth table100%2/2
A
A= $Shell::capture_stderr
Aresult
11
00
54 # closing over $^O, $cmd, and $null
55 return sub {
56 5 ▶ shift if ref $_[0] && $_[0]->isa( 'Shell' );
Subroutine __ANON__: called CC=12 SCAR=26.8
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $_[0]->isa("Shell") 1 4 5
Condition66%2/3
ref $_[0] and $_[0]->isa("Shell")
!ll&&!rl&&r
401
MC/DC50%1/2
ref $_[0] and $_[0]->isa("Shell")
ref $_[0] $_[0]->isa("Shell")
Truth table66%2/3
A and B
A= ref $_[0]B= $_[0]->isa("Shell")
ABresult
0X0
100
111
57 5 ▶ if (@_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 1) { } 3 2 5
58 3 ▶ $Shell::capture_stderr == 1 ? `$cmd 2>&1` :
Branch: 2 branches
BranchTrueFalseTotal
$Shell::capture_stderr == 1 ? : 1 2 3
$Shell::capture_stderr == -1 ? : 0 2 2
59 $Shell::capture_stderr == -1 ? `$cmd 2>$null` :
60 `$cmd`;
61 } elsif (OS eq 'os2') {
62 local(*SAVEOUT, *READ, *WRITE);
63  
64 open SAVEOUT, '>&STDOUT' or die;
65 pipe READ, WRITE or die;
66 open STDOUT, '>&WRITE' or die;
67 close WRITE;
68  
69 my $pid = system(1, $cmd, @_);
70 die "Can't execute $cmd: $!\n" if $pid < 0;
71  
72 open STDOUT, '>&SAVEOUT' or die;
73 close SAVEOUT;
74  
75 if (wantarray) {
76 my @ret = <READ>;
77 close READ;
78 waitpid $pid, 0;
79 @ret;
80 } else {
81 local($/) = undef;
82 my $ret = <READ>;
83 close READ;
84 waitpid $pid, 0;
85 $ret;
86 }
87 } else {
88 2 my $a;
89 2 my @arr = @_;
90 2 ▶ unless( $Shell::raw ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($Shell::raw) 2 0 2
91 2 if (OS eq 'MSWin32') {
92 # XXX this special-casing should not be needed
93 # if we do quoting right on Windows. :-(
94 #
95 # First, escape all quotes. Cover the case where we
96 # want to pass along a quote preceded by a backslash
97 # (i.e., C<"param \""" end">).
98 # Ugly, yup? You know, windoze.
99 # Enclose in quotes only the parameters that need it:
100 # try this: c:> dir "/w"
101 # and this: c:> dir /w
102 for (@arr) {
103 s/"/\\"/g;
104 s/\\\\"/\\\\"""/g;
105 $_ = qq["$_"] if /\s/;
106 }
107 } else {
108 2 for (@arr) {
109 2 s/(['\\])/\\$1/g;
110 2 $_ = $_;
111 }
112 }
113 }
114 2 ▶ push @arr, '2>&1' if $Shell::capture_stderr == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $Shell::capture_stderr == 1 0 2 2
115 2 ▶ push @arr, '2>$null' if $Shell::capture_stderr == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $Shell::capture_stderr == -1 0 2 2
116 2 ▶ open(SUBPROC, join(' ', $cmd, @arr, '|'))
Branch: 1 branch
BranchTrueFalseTotal
open SUBPROC, join(" ", $cmd, @arr, "|") or die "Can't exec ${cmd}: $!\n" 0 2 2
117 or die "Can't exec $cmd: $!\n";
118 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 0 2
119 2 my @ret = <SUBPROC>;
120 2 close SUBPROC; # XXX Oughta use a destructor.
121 2 @ret;
122 } else {
123 0 local($/) = undef;
124 0 my $ret = <SUBPROC>;
125 0 close SUBPROC;
126 0 $ret;
127 }
128 }
129 3 };
130 }
131  
132 sub AUTOLOAD {
133 3 ▶ shift if ref $_[0] && $_[0]->isa( 'Shell' );
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $_[0]->isa("Shell") 1 2 3
Condition66%2/3
ref $_[0] and $_[0]->isa("Shell")
!ll&&!rl&&r
201
MC/DC50%1/2
ref $_[0] and $_[0]->isa("Shell")
ref $_[0] $_[0]->isa("Shell")
Truth table66%2/3
A and B
A= ref $_[0]B= $_[0]->isa("Shell")
ABresult
0X0
100
111
134 3 my $cmd = $AUTOLOAD;
135 3 $cmd =~ s/^.*:://;
136 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
137 3 *$AUTOLOAD = _make_cmd($cmd);
138 3 goto &$AUTOLOAD;
139 }
140  
141 2 1;
142  
143 __END__
↑ Summary