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