| 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.73'; | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 16 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 17 | 2 | my ($callpack, $callfile, $callline) = caller; | |||||||||||||||||||||||||||
| 18 | 2 | my @EXPORT; | |||||||||||||||||||||||||||
| 19 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | =over | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item B<_make_cmd> | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $sub = _make_cmd($cmd); | ||||||||||||||||||||||||||||
| 43 | $sub = $shell->_make_cmd($cmd); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Creates a closure which invokes the system command C<$cmd>. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =back | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =end private | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub _make_cmd { | ||||||||||||||||||||||||||
|
Subroutine
_make_cmd: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | shift if ref $_[0] && $_[0]->isa( 'Shell' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and $_[0]->isa("Shell")
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")
| |||||||||||||||||||||||||||||
| 55 | 3 | my $cmd = shift; | |||||||||||||||||||||||||||
| 56 | 3 | my $null = File::Spec::Functions::devnull(); | |||||||||||||||||||||||||||
| 57 | 3 | ▶ | $Shell::capture_stderr ||= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Shell::capture_stderr ||= 0
MC/DC100%1/1
$Shell::capture_stderr ||= 0
$Shell::capture_stderr
Truth table100%2/2
A
A= $Shell::capture_stderr
| |||||||||||||||||||||||||||||
| 58 | # closing over $^O, $cmd, and $null | ||||||||||||||||||||||||||||
| 59 | 5 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=26.8
| |||||||||||||||||||||||||||||
| 60 | 5 | ▶ | shift if ref $_[0] && $_[0]->isa( 'Shell' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] and $_[0]->isa("Shell")
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")
| |||||||||||||||||||||||||||||
| 61 | 5 | ▶ | if (@_ < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 3 | ▶ | $Shell::capture_stderr == 1 ? `$cmd 2>&1` : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | $Shell::capture_stderr == -1 ? `$cmd 2>$null` : | ||||||||||||||||||||||||||||
| 64 | `$cmd`; | ||||||||||||||||||||||||||||
| 65 | } elsif (OS eq 'os2') { | ||||||||||||||||||||||||||||
| 66 | local(*SAVEOUT, *READ, *WRITE); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | open SAVEOUT, '>&STDOUT' or die; | ||||||||||||||||||||||||||||
| 69 | pipe READ, WRITE or die; | ||||||||||||||||||||||||||||
| 70 | open STDOUT, '>&WRITE' or die; | ||||||||||||||||||||||||||||
| 71 | close WRITE; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | my $pid = system(1, $cmd, @_); | ||||||||||||||||||||||||||||
| 74 | die "Can't execute $cmd: $!\n" if $pid < 0; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | open STDOUT, '>&SAVEOUT' or die; | ||||||||||||||||||||||||||||
| 77 | close SAVEOUT; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | if (wantarray) { | ||||||||||||||||||||||||||||
| 80 | my @ret = <READ>; | ||||||||||||||||||||||||||||
| 81 | close READ; | ||||||||||||||||||||||||||||
| 82 | waitpid $pid, 0; | ||||||||||||||||||||||||||||
| 83 | @ret; | ||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | local($/) = undef; | ||||||||||||||||||||||||||||
| 86 | my $ret = <READ>; | ||||||||||||||||||||||||||||
| 87 | close READ; | ||||||||||||||||||||||||||||
| 88 | waitpid $pid, 0; | ||||||||||||||||||||||||||||
| 89 | $ret; | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 2 | my $a; | |||||||||||||||||||||||||||
| 93 | 2 | my @arr = @_; | |||||||||||||||||||||||||||
| 94 | 2 | ▶ | unless( $Shell::raw ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 2 | if (OS eq 'MSWin32') { | |||||||||||||||||||||||||||
| 96 | # XXX this special-casing should not be needed | ||||||||||||||||||||||||||||
| 97 | # if we do quoting right on Windows. :-( | ||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||
| 99 | # First, escape all quotes. Cover the case where we | ||||||||||||||||||||||||||||
| 100 | # want to pass along a quote preceded by a backslash | ||||||||||||||||||||||||||||
| 101 | # (i.e., C<"param \""" end">). | ||||||||||||||||||||||||||||
| 102 | # Ugly, yup? You know, windoze. | ||||||||||||||||||||||||||||
| 103 | # Enclose in quotes only the parameters that need it: | ||||||||||||||||||||||||||||
| 104 | # try this: c:> dir "/w" | ||||||||||||||||||||||||||||
| 105 | # and this: c:> dir /w | ||||||||||||||||||||||||||||
| 106 | for (@arr) { | ||||||||||||||||||||||||||||
| 107 | s/"/\\"/g; | ||||||||||||||||||||||||||||
| 108 | s/\\\\"/\\\\"""/g; | ||||||||||||||||||||||||||||
| 109 | $_ = qq["$_"] if /\s/; | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 2 | for (@arr) { | |||||||||||||||||||||||||||
| 113 | 2 | s/(['\\])/\\$1/g; | |||||||||||||||||||||||||||
| 114 | 2 | $_ = $_; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 2 | ▶ | push @arr, '2>&1' if $Shell::capture_stderr == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 2 | ▶ | push @arr, '2>$null' if $Shell::capture_stderr == -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 2 | ▶ | open(SUBPROC, join(' ', $cmd, @arr, '|')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | or die "Can't exec $cmd: $!\n"; | ||||||||||||||||||||||||||||
| 122 | 2 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 2 | my @ret = <SUBPROC>; | |||||||||||||||||||||||||||
| 124 | 2 | close SUBPROC; # XXX Oughta use a destructor. | |||||||||||||||||||||||||||
| 125 | 2 | @ret; | |||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | 0 | local($/) = undef; | |||||||||||||||||||||||||||
| 128 | 0 | my $ret = <SUBPROC>; | |||||||||||||||||||||||||||
| 129 | 0 | close SUBPROC; | |||||||||||||||||||||||||||
| 130 | 0 | $ret; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 3 | }; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 3 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 137 | 3 | ▶ | shift if ref $_[0] && $_[0]->isa( 'Shell' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] and $_[0]->isa("Shell")
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")
| |||||||||||||||||||||||||||||
| 138 | 3 | my $cmd = $AUTOLOAD; | |||||||||||||||||||||||||||
| 139 | 3 | $cmd =~ s/^.*:://; | |||||||||||||||||||||||||||
| 140 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 3 | *$AUTOLOAD = _make_cmd($cmd); | |||||||||||||||||||||||||||
| 142 | 3 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 2 | 1; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||||||||||