| 1 | package Shell::Autobox; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw(autobox); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use IPC::Run3 qw(run3); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # XXX this declaration must be on a single line | ||||||||||||||||||||||||||||
| 12 | # https://metacpan.org/pod/version#How-to-declare()-a-dotted-decimal-version | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use version; our $VERSION = version->declare('v2.0.1'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 2 | my $caller = (caller)[0]; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | for my $program (@_) { | |||||||||||||||||||||||||||
| 20 | 19 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||
| 21 | 19 | my ($input, @args) = @_; | |||||||||||||||||||||||||||
| 22 | 19 | my @command = ($program, @args); | |||||||||||||||||||||||||||
| 23 | 19 | my $command = join(' ', @command); | |||||||||||||||||||||||||||
| 24 | 19 | ▶ | my $stdin = (defined($input) && ref($input) eq '') ? \$input : $input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $input and ref $input eq ""
MC/DC50%1/2
defined $input and ref $input eq ""
defined $input
ref $input eq ""
Truth table66%2/3
A and B
A= defined $inputB= ref $input eq ""
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 19 | run3(\@command, $stdin, \my $stdout, \my $stderr, { | |||||||||||||||||||||||||||
| 27 | return_if_system_error => 1, # don't die on error | ||||||||||||||||||||||||||||
| 28 | }); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 19 | ▶ | my $error = (defined($stderr) && $stderr =~ /\S/) ? ": $stderr" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $stderr and $stderr =~ /\S/
MC/DC50%1/2
defined $stderr and $stderr =~ /\S/
defined $stderr
$stderr =~ /\S/
Truth table66%2/3
A and B
A= defined $stderrB= $stderr =~ /\S/
| |||||||||||||||||||||||||||||
| 31 | 19 | my $message = "$command$error"; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 19 | ▶ | if ($?) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | 4 | confess "can't exec $message"; | |||||||||||||||||||||||||||
| 35 | } elsif ($error) { | ||||||||||||||||||||||||||||
| 36 | 4 | warn "error running $message"; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 15 | ▶ | return (defined($stdout) && length($stdout)) ? $stdout : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $stdout and length $stdout
MC/DC50%1/2
defined $stdout and length $stdout
defined $stdout
length $stdout
Truth table66%2/3
A and B
A= defined $stdoutB= length $stdout
| |||||||||||||||||||||||||||||
| 40 | 1 | }; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | *{"$caller\::$program"} = $sub; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | $class->SUPER::import(SCALAR => $caller, ARRAY => $caller); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||