| 1 | package Sys::Cmd::Process; | ||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use v5.18; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp qw[]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Log::Any qw[$log]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = 'v0.986.3'; | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | ### START Class::Inline ### v0.0.1 Thu Dec 11 13:24:57 2025 | ||||||||||||||||||||||||||||||
| 10 | 2 | require Carp; | |||||||||||||||||||||||||||||
| 11 | 2 | our ( @_CLASS, $_FIELDS, %_NEW ); | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 31 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 14 | 31 | my $class = shift; | |||||||||||||||||||||||||||||
| 15 | 31 | ▶ | my $CLASS = ref $class || $class; | ||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||
| 16 | 31 | ▶ | $_NEW{$CLASS} //= do { | ||||||||||||||||||||||||||||
|
Condition66%2/3
$Sys::Cmd::Process::_NEW{$CLASS} //= do {
my(%seen, @new, @build);
my(@possible) = $CLASS;
while (@possible) {
my $c = shift @possible;
no strict 'refs';
push @new, $c . '::_NEW' if exists &{$c . '::_NEW';};
push @build, $c . '::BUILD' if exists &{$c . '::BUILD';};
++$seen{$c};
if (exists &{$c . '::DOES';}) {
push @possible, grep({not $seen{$_}++;} $c->DOES("*"));
};
push @possible, grep({not $seen{$_}++;} @{$c . '::ISA';});
};
[[reverse(@new)], [reverse(@build)]]
}
MC/DC0%0/2
$Sys::Cmd::Process::_NEW{$CLASS} //= do {
my(%seen, @new, @build);
my(@possible) = $CLASS;
while (@possible) {
my $c = shift @possible;
no strict 'refs';
push @new, $c . '::_NEW' if exists &{$c . '::_NEW';};
push @build, $c . '::BUILD' if exists &{$c . '::BUILD';};
++$seen{$c};
if (exists &{$c . '::DOES';}) {
push @possible, grep({not $seen{$_}++;} $c->DOES("*"));
};
push @possible, grep({not $seen{$_}++;} @{$c . '::ISA';});
};
[[reverse(@new)], [reverse(@build)]]
}
$Sys::Cmd::Process::_NEW{$CLASS}
do {
my(%seen, @new, @build);
my(@possible) = $CLASS;
while (@possible) {
my $c = shift @possible;
no strict 'refs';
push @new, $c . '::_NEW' if exists &{$c . '::_NEW';};
push @build, $c . '::BUILD' if exists &{$c . '::BUILD';};
++$seen{$c};
if (exists &{$c . '::DOES';}) {
push @possible, grep({not $seen{$_}++;} $c->DOES("*"));
};
push @possible, grep({not $seen{$_}++;} @{$c . '::ISA';});
};
[[reverse(@new)], [reverse(@build)]]
}
Truth table66%2/3
A //= B
A= $Sys::Cmd::Process::_NEW{$CLASS}B= do {
my(%seen, @new, @build);
my(@possible) = $CLASS;
while (@possible) {
my $c = shift @possible;
no strict 'refs';
push @new, $c . '::_NEW' if exists &{$c . '::_NEW';};
push @build, $c . '::BUILD' if exists &{$c . '::BUILD';};
++$seen{$c};
if (exists &{$c . '::DOES';}) {
push @possible, grep({not $seen{$_}++;} $c->DOES("*"));
};
push @possible, grep({not $seen{$_}++;} @{$c . '::ISA';});
};
[[reverse(@new)], [reverse(@build)]]
}
| |||||||||||||||||||||||||||||||
| 17 | 2 | my ( %seen, @new, @build ); | |||||||||||||||||||||||||||||
| 18 | 2 | my @possible = ($CLASS); | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | while (@possible) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 20 | 2 | my $c = shift @possible; | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | push @new, $c . '::_NEW' if exists &{ $c . '::_NEW' }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | push @build, $c . '::BUILD' if exists &{ $c . '::BUILD' }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 24 | 2 | $seen{$c}++; | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | if ( exists &{ $c . '::DOES' } ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 26 | 0 | push @possible, grep { not $seen{$_}++ } $c->DOES('*'); | |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||
| 28 | 0 | push @possible, grep { not $seen{$_}++ } @{ $c . '::ISA' }; | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | 2 | [ [ reverse(@new) ], [ reverse(@build) ] ]; | |||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $self = { @_ ? @_ > 1 ? @_ : %{ $_[0] } : () }; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 33 | 31 | bless $self, $CLASS; | |||||||||||||||||||||||||||||
| 34 | 31 | my $attrs = { map { ( $_ => 1 ) } keys %$self }; | |||||||||||||||||||||||||||||
| 35 | 31 | map { $self->$_($attrs) } @{ $_NEW{$CLASS}->[0] }; | |||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||
| 37 | 31 | local $Carp::CarpLevel = 3; | |||||||||||||||||||||||||||||
| 38 | Carp::carp("Sys::Cmd::Process: unexpected argument '$_'") | ||||||||||||||||||||||||||||||
| 39 | 31 | for keys %$attrs | |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | 0 | map { $self->$_ } @{ $_NEW{$CLASS}->[1] }; | |||||||||||||||||||||||||||||
| 42 | 31 | $self; | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 31 | ▶ | sub _NEW { | ||||||||||||||||||||||||||||
|
Subroutine
_NEW: called CC=9 SCAR=26.5
| |||||||||||||||||||||||||||||||
| 46 | 31 | CORE::state $fix_FIELDS = do { | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | $_FIELDS = { @_CLASS > 1 ? @_CLASS : %{ $_CLASS[0] } }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $_FIELDS = $_FIELDS->{'FIELDS'} if exists $_FIELDS->{'FIELDS'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||||
| 50 | 31 | ▶ | if ( my @missing = grep { not exists $_[0]->{$_} } 'cmd', 'pid', 'stderr', | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 51 | 'stdin', 'stdout' ) | ||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||
| 53 | 0 | Carp::croak( 'Sys::Cmd::Process required initial argument(s): ' | |||||||||||||||||||||||||||||
| 54 | . join( ', ', @missing ) ); | ||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||
| 56 | 0 | $_[0]{'_ret'} = eval { $_FIELDS->{'_ret'}->{'isa'}->( $_[0]{'_ret'} ) } | |||||||||||||||||||||||||||||
| 57 | 31 | ▶ | if exists $_[0]{'_ret'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 58 | 31 | ▶ | delete $_[0]{'_ret'} || Carp::confess( 'Sys::Cmd::Process _ret: ' . $@ ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$@ && (delete $_[0]{'_ret'} || Carp::confess('Sys::Cmd::Process _ret: ' . $@))
delete $_[0]{"_ret"} or Carp::confess('Sys::Cmd::Process _ret: ' . $@)
MC/DC0%0/2
$@ && (delete $_[0]{'_ret'} || Carp::confess('Sys::Cmd::Process _ret: ' . $@))
$@
delete $_[0]{"_ret"}
Truth table33%1/3
A && B
A= $@B= delete $_[0]{"_ret"}
| |||||||||||||||||||||||||||||||
| 59 | if $@; | ||||||||||||||||||||||||||||||
| 60 | 31 | $_[0]{'cmd'} = eval { $_FIELDS->{'cmd'}->{'isa'}->( $_[0]{'cmd'} ) }; | |||||||||||||||||||||||||||||
| 61 | 31 | ▶ | delete $_[0]{'cmd'} || Carp::confess( 'Sys::Cmd::Process cmd: ' . $@ ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$@ && (delete $_[0]{'cmd'} || Carp::confess('Sys::Cmd::Process cmd: ' . $@))
delete $_[0]{"cmd"} or Carp::confess('Sys::Cmd::Process cmd: ' . $@)
MC/DC0%0/2
$@ && (delete $_[0]{'cmd'} || Carp::confess('Sys::Cmd::Process cmd: ' . $@))
$@
delete $_[0]{"cmd"}
Truth table33%1/3
A && B
A= $@B= delete $_[0]{"cmd"}
| |||||||||||||||||||||||||||||||
| 62 | if $@; | ||||||||||||||||||||||||||||||
| 63 | 31 | map { delete $_[1]->{$_} } 'cmd', 'on_exit', 'pid', 'status', 'stderr', | |||||||||||||||||||||||||||||
| 64 | 'stdin', 'stdout'; | ||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub __RO { | ||||||||||||||||||||||||||||
|
Subroutine
__RO: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 68 | 0 | my ( undef, undef, undef, $sub ) = caller(1); | |||||||||||||||||||||||||||||
| 69 | 0 | Carp::confess("attribute $sub is read-only"); | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 117 | ▶ | sub _ret { | ||||||||||||||||||||||||||||
|
Subroutine
_ret: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||
| 73 | 117 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 74 | 31 | $_[0]{'_ret'} = eval { $_FIELDS->{'_ret'}->{'isa'}->( $_[1] ) }; | |||||||||||||||||||||||||||||
| 75 | 31 | ▶ | delete $_[0]{'_ret'} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$@ && (delete $_[0]{'_ret'} || Carp::confess('invalid (Sys::Cmd::Process::_ret) value: ' . $@))
delete $_[0]{"_ret"} or Carp::confess('invalid (Sys::Cmd::Process::_ret) value: ' . $@)
MC/DC0%0/2
$@ && (delete $_[0]{'_ret'} || Carp::confess('invalid (Sys::Cmd::Process::_ret) value: ' . $@))
$@
delete $_[0]{"_ret"}
Truth table33%1/3
A && B
A= $@B= delete $_[0]{"_ret"}
| |||||||||||||||||||||||||||||||
| 76 | || Carp::confess( 'invalid (Sys::Cmd::Process::_ret) value: ' . $@ ) | ||||||||||||||||||||||||||||||
| 77 | if $@; | ||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | 117 | ▶ | $_[0]{'_ret'} //= eval { | ||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{"_ret"} //= eval {
do {
$Sys::Cmd::Process::_FIELDS->{"_ret"}{"isa"}->($Sys::Cmd::Process::_FIELDS->{"_ret"}{"default"}->($_[0]))
}
}
MC/DC50%1/2
$_[0]{"_ret"} //= eval {
do {
$Sys::Cmd::Process::_FIELDS->{"_ret"}{"isa"}->($Sys::Cmd::Process::_FIELDS->{"_ret"}{"default"}->($_[0]))
}
}
$_[0]{"_ret"}
eval {
do {
$Sys::Cmd::Process::_FIELDS->{"_ret"}{"isa"}->($Sys::Cmd::Process::_FIELDS->{"_ret"}{"default"}->($_[0]))
}
}
Truth table66%2/3
A //= B
A= $_[0]{"_ret"}B= eval {
do {
$Sys::Cmd::Process::_FIELDS->{"_ret"}{"isa"}->($Sys::Cmd::Process::_FIELDS->{"_ret"}{"default"}->($_[0]))
}
}
| |||||||||||||||||||||||||||||||
| 80 | $_FIELDS->{'_ret'}->{'isa'} | ||||||||||||||||||||||||||||||
| 81 | 1 | ->( $_FIELDS->{'_ret'}->{'default'}->( $_[0] ) ); | |||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||
| 83 | 117 | ▶ | delete $_[0]{'_ret'} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$@ && (delete $_[0]{'_ret'} || Carp::confess('invalid (Sys::Cmd::Process::_ret) default: ' . $@))
delete $_[0]{"_ret"} or Carp::confess('invalid (Sys::Cmd::Process::_ret) default: ' . $@)
MC/DC0%0/2
$@ && (delete $_[0]{'_ret'} || Carp::confess('invalid (Sys::Cmd::Process::_ret) default: ' . $@))
$@
delete $_[0]{"_ret"}
Truth table66%2/3
A && B
A= $@B= delete $_[0]{"_ret"}
| |||||||||||||||||||||||||||||||
| 84 | || Carp::confess( 'invalid (Sys::Cmd::Process::_ret) default: ' . $@ ) | ||||||||||||||||||||||||||||||
| 85 | if $@; | ||||||||||||||||||||||||||||||
| 86 | 116 | $_[0]{'_ret'}; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | 62 | ▶ | sub has__ret { exists $_[0]{'_ret'} } | ||||||||||||||||||||||||||||
|
Subroutine
has__ret: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | sub cmd { __RO() if @_ > 1; $_[0]{'cmd'} // undef } | ||||||||||||||||||||||||||||
|
Subroutine
cmd: called CC=3 SCAR=12.0
Pod
undocumented
Branch: 1 branch
Condition50%1/2
$_[0]{"cmd"} // undef
MC/DC0%0/1
$_[0]{"cmd"} // undef
$_[0]{"cmd"}
Truth table50%1/2
A
A= $_[0]{"cmd"}
| |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 24 | ▶ | sub core { | ||||||||||||||||||||||||||||
|
Subroutine
core: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 92 | 24 | ▶ | __RO() if @_ > 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | 24 | ▶ | $_[0]{'core'} //= $_FIELDS->{'core'}->{'default'}->( $_[0] ); | ||||||||||||||||||||||||||||
|
Condition33%1/3
$_[0]{"core"} //= $Sys::Cmd::Process::_FIELDS->{"core"}{"default"}->($_[0])
MC/DC0%0/2
$_[0]{"core"} //= $Sys::Cmd::Process::_FIELDS->{"core"}{"default"}->($_[0])
$_[0]{"core"}
$Sys::Cmd::Process::_FIELDS->{"core"}{"default"}->($_[0])
Truth table33%1/3
A //= B
A= $_[0]{"core"}B= $Sys::Cmd::Process::_FIELDS->{"core"}{"default"}->($_[0])
| |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 117 | ▶ | sub exit { | ||||||||||||||||||||||||||||
|
Subroutine
exit: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 97 | 117 | ▶ | __RO() if @_ > 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 98 | 117 | ▶ | $_[0]{'exit'} //= $_FIELDS->{'exit'}->{'default'}->( $_[0] ); | ||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{"exit"} //= $Sys::Cmd::Process::_FIELDS->{"exit"}{"default"}->($_[0])
MC/DC0%0/2
$_[0]{"exit"} //= $Sys::Cmd::Process::_FIELDS->{"exit"}{"default"}->($_[0])
$_[0]{"exit"}
$Sys::Cmd::Process::_FIELDS->{"exit"}{"default"}->($_[0])
Truth table66%2/3
A //= B
A= $_[0]{"exit"}B= $Sys::Cmd::Process::_FIELDS->{"exit"}{"default"}->($_[0])
| |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub has_exit { exists $_[0]{'exit'} } | ||||||||||||||||||||||||||||
|
Subroutine
has_exit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | 31 | ▶ | sub on_exit { | ||||||||||||||||||||||||||||
|
Subroutine
on_exit: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( @_ > 1 ) { $_[0]{'on_exit'} = $_[1] } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 104 | 31 | ▶ | $_[0]{'on_exit'} // undef; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0]{"on_exit"} // undef
MC/DC100%1/1
$_[0]{"on_exit"} // undef
$_[0]{"on_exit"}
Truth table100%2/2
A
A= $_[0]{"on_exit"}
| |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||
| 106 | 160 | ▶ | sub pid { __RO() if @_ > 1; $_[0]{'pid'} // undef } | ||||||||||||||||||||||||||||
|
Subroutine
pid: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
Condition50%1/2
$_[0]{"pid"} // undef
MC/DC0%0/1
$_[0]{"pid"} // undef
$_[0]{"pid"}
Truth table50%1/2
A
A= $_[0]{"pid"}
| |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 86 | ▶ | sub signal { | ||||||||||||||||||||||||||||
|
Subroutine
signal: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 109 | 86 | ▶ | __RO() if @_ > 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | 86 | ▶ | $_[0]{'signal'} //= $_FIELDS->{'signal'}->{'default'}->( $_[0] ); | ||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{"signal"} //= $Sys::Cmd::Process::_FIELDS->{"signal"}{"default"}->($_[0])
MC/DC0%0/2
$_[0]{"signal"} //= $Sys::Cmd::Process::_FIELDS->{"signal"}{"default"}->($_[0])
$_[0]{"signal"}
$Sys::Cmd::Process::_FIELDS->{"signal"}{"default"}->($_[0])
Truth table66%2/3
A //= B
A= $_[0]{"signal"}B= $Sys::Cmd::Process::_FIELDS->{"signal"}{"default"}->($_[0])
| |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 31 | ▶ | sub status { | ||||||||||||||||||||||||||||
|
Subroutine
status: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 114 | 31 | ▶ | if ( @_ > 1 ) { $_[0]{'status'} = $_[1] } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 115 | 31 | ▶ | $_[0]{'status'} //= $_FIELDS->{'status'}->{'default'}; | ||||||||||||||||||||||||||||
|
Condition33%1/3
$_[0]{"status"} //= $Sys::Cmd::Process::_FIELDS->{"status"}{"default"}
MC/DC0%0/2
$_[0]{"status"} //= $Sys::Cmd::Process::_FIELDS->{"status"}{"default"}
$_[0]{"status"}
$Sys::Cmd::Process::_FIELDS->{"status"}{"default"}
Truth table33%1/3
A //= B
A= $_[0]{"status"}B= $Sys::Cmd::Process::_FIELDS->{"status"}{"default"}
| |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||
| 117 | 166 | ▶ | sub stderr { __RO() if @_ > 1; $_[0]{'stderr'} // undef } | ||||||||||||||||||||||||||||
|
Subroutine
stderr: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
Condition50%1/2
$_[0]{"stderr"} // undef
MC/DC0%0/1
$_[0]{"stderr"} // undef
$_[0]{"stderr"}
Truth table50%1/2
A
A= $_[0]{"stderr"}
| |||||||||||||||||||||||||||||||
| 118 | 179 | ▶ | sub stdin { __RO() if @_ > 1; $_[0]{'stdin'} // undef } | ||||||||||||||||||||||||||||
|
Subroutine
stdin: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
Condition50%1/2
$_[0]{"stdin"} // undef
MC/DC0%0/1
$_[0]{"stdin"} // undef
$_[0]{"stdin"}
Truth table50%1/2
A
A= $_[0]{"stdin"}
| |||||||||||||||||||||||||||||||
| 119 | 152 | ▶ | sub stdout { __RO() if @_ > 1; $_[0]{'stdout'} // undef } | ||||||||||||||||||||||||||||
|
Subroutine
stdout: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
Condition50%1/2
$_[0]{"stdout"} // undef
MC/DC0%0/1
$_[0]{"stdout"} // undef
$_[0]{"stdout"}
Truth table50%1/2
A
A= $_[0]{"stdout"}
| |||||||||||||||||||||||||||||||
| 120 | @_CLASS = grep 1, ### END Class::Inline ### | ||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||
| 122 | cmd => { | ||||||||||||||||||||||||||||||
| 123 | 31 | ▶ | isa => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||
| 124 | 31 | ▶ | ref $_[0] eq 'ARRAY' || Sys::Cmd::_croak("cmd must be ARRAYREF"); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 125 | 31 | ▶ | @{ $_[0] } || Sys::Cmd::_croak("Missing cmd elements"); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 126 | 31 | ▶ | if ( grep { !defined $_ } @{ $_[0] } ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 127 | 0 | Sys::Cmd::_croak('cmd array cannot contain undef elements'); | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||
| 129 | 31 | $_[0]; | |||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||||
| 131 | required => 1, | ||||||||||||||||||||||||||||||
| 132 | }, | ||||||||||||||||||||||||||||||
| 133 | pid => { | ||||||||||||||||||||||||||||||
| 134 | is => 'ro', | ||||||||||||||||||||||||||||||
| 135 | required => 1, | ||||||||||||||||||||||||||||||
| 136 | }, | ||||||||||||||||||||||||||||||
| 137 | stdin => { | ||||||||||||||||||||||||||||||
| 138 | is => 'ro', | ||||||||||||||||||||||||||||||
| 139 | required => 1, | ||||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||||
| 141 | stdout => { | ||||||||||||||||||||||||||||||
| 142 | is => 'ro', | ||||||||||||||||||||||||||||||
| 143 | required => 1, | ||||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||||
| 145 | stderr => { | ||||||||||||||||||||||||||||||
| 146 | is => 'ro', | ||||||||||||||||||||||||||||||
| 147 | required => 1, | ||||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||||
| 149 | _ret => { | ||||||||||||||||||||||||||||||
| 150 | is => 'rw', | ||||||||||||||||||||||||||||||
| 151 | 31 | ▶ | isa => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||
| 152 | 31 | ▶ | defined( $_[0] ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 153 | or die Data::Dumper::Dumper( \@_ ) . "_ret must be defined! @_"; | ||||||||||||||||||||||||||||||
| 154 | 31 | $_[0]; | |||||||||||||||||||||||||||||
| 155 | }, | ||||||||||||||||||||||||||||||
| 156 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 157 | predicate => 1, | ||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 159 | 1 | Sys::Cmd::_croak( | |||||||||||||||||||||||||||||
| 160 | 'Process status values invalid before wait_child()'); | ||||||||||||||||||||||||||||||
| 161 | }, | ||||||||||||||||||||||||||||||
| 162 | }, | ||||||||||||||||||||||||||||||
| 163 | exit => { | ||||||||||||||||||||||||||||||
| 164 | is => 'ro', | ||||||||||||||||||||||||||||||
| 165 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 166 | predicate => 1, | ||||||||||||||||||||||||||||||
| 167 | 31 | ▶ | default => sub { my $r = $_[0]->_ret; $r < 0 ? $r : $r >> 8 }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 168 | }, | ||||||||||||||||||||||||||||||
| 169 | signal => { | ||||||||||||||||||||||||||||||
| 170 | is => 'ro', | ||||||||||||||||||||||||||||||
| 171 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 172 | 31 | ▶ | default => sub { $_[0]->_ret & 127 }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 173 | }, | ||||||||||||||||||||||||||||||
| 174 | core => { | ||||||||||||||||||||||||||||||
| 175 | is => 'ro', | ||||||||||||||||||||||||||||||
| 176 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 177 | 24 | ▶ | default => sub { $_[0]->_ret & 128 }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 178 | }, | ||||||||||||||||||||||||||||||
| 179 | 2 | status => { | |||||||||||||||||||||||||||||
| 180 | is => 'rw', | ||||||||||||||||||||||||||||||
| 181 | default => 'Running', | ||||||||||||||||||||||||||||||
| 182 | }, | ||||||||||||||||||||||||||||||
| 183 | on_exit => { is => 'rw', }, | ||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | 18 | ▶ | sub cmdline { | ||||||||||||||||||||||||||||
|
Subroutine
cmdline: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 187 | 18 | my $self = shift; | |||||||||||||||||||||||||||||
| 188 | 18 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 189 | 18 | return @{ $self->cmd }; | |||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||||||||||||
| 192 | 0 | return join( ' ', @{ $self->cmd } ); | |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | 50 | ▶ | sub close { | ||||||||||||||||||||||||||||
|
Subroutine
close: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 197 | 50 | my $self = shift; | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | 50 | foreach my $h (qw/stdin stdout stderr/) { | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | # may not be defined during global destruction | ||||||||||||||||||||||||||||||
| 202 | 150 | ▶ | my $fh = $self->$h or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 203 | 150 | ▶ | $fh->opened or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 204 | 64 | ▶ | if ( $h eq 'stderr' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 205 | warn sprintf( '[%d] uncollected stderr: %s', $self->pid // -1, $_ ) | ||||||||||||||||||||||||||||||
| 206 | 24 | ▶ | for $self->stderr->getlines; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->pid // -1
MC/DC0%0/1
$self->pid // -1
$self->pid
Truth table0%0/2
A
A= $self->pid
| |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||
| 208 | 64 | ▶ | $fh->close || Carp::carp "error closing $h: $!"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | 50 | return; | |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||
| 214 | 62 | ▶ | sub wait_child { | ||||||||||||||||||||||||||||
|
Subroutine
wait_child: called CC=10 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 215 | 62 | my $self = shift; | |||||||||||||||||||||||||||||
| 216 | 62 | ▶ | my $pid = $self->pid // return; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->pid // (return)
MC/DC0%0/1
$self->pid // (return)
$self->pid
Truth table50%1/2
A
A= $self->pid
| |||||||||||||||||||||||||||||||
| 217 | 62 | ▶ | return $self->exit if $self->has__ret; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | 31 | my $ret = -1; # default means: bad execution for some reasons | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||
| 221 | 31 | ▶ | if ( $pid > 0 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | 31 | local $?; | |||||||||||||||||||||||||||||
| 224 | 31 | local $!; | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||
| 226 | 31 | my $pid = waitpid $self->pid, 0; | |||||||||||||||||||||||||||||
| 227 | 31 | $ret = $?; | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 31 | ▶ | if ( $pid != $self->pid ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 230 | 0 | warn | |||||||||||||||||||||||||||||
| 231 | sprintf( 'Could not reap child process %d (waitpid returned: %d)', | ||||||||||||||||||||||||||||||
| 232 | $self->pid, $pid ); | ||||||||||||||||||||||||||||||
| 233 | 0 | $ret = 0; | |||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||
| 236 | 31 | ▶ | if ( $ret == -1 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | # So waitpid returned a PID but then sets $? to this | ||||||||||||||||||||||||||||||
| 239 | # strange value? (Strange in that tests randomly show it to | ||||||||||||||||||||||||||||||
| 240 | # be invalid.) Most likely a perl bug; I think that waitpid | ||||||||||||||||||||||||||||||
| 241 | # got interrupted and when it restarts/resumes the status | ||||||||||||||||||||||||||||||
| 242 | # is lost. | ||||||||||||||||||||||||||||||
| 243 | # | ||||||||||||||||||||||||||||||
| 244 | # See http://www.perlmonks.org/?node_id=641620 for a | ||||||||||||||||||||||||||||||
| 245 | # possibly related discussion. | ||||||||||||||||||||||||||||||
| 246 | # | ||||||||||||||||||||||||||||||
| 247 | # However, since I localised $? and $! above I haven't seen | ||||||||||||||||||||||||||||||
| 248 | # this problem again, so I hope that is a good enough work | ||||||||||||||||||||||||||||||
| 249 | # around. Lets warn any way so that we know when something | ||||||||||||||||||||||||||||||
| 250 | # dodgy is going on. | ||||||||||||||||||||||||||||||
| 251 | 0 | warn __PACKAGE__ | |||||||||||||||||||||||||||||
| 252 | . ' received invalid child exit status for pid ' | ||||||||||||||||||||||||||||||
| 253 | . $self->pid | ||||||||||||||||||||||||||||||
| 254 | . ' Setting to 0'; | ||||||||||||||||||||||||||||||
| 255 | 0 | $ret = 0; | |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||
| 260 | 31 | $self->_ret($ret); | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||
| 262 | 31 | ▶ | if ( my $subref = $self->on_exit ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 263 | 2 | $subref->($self); | |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||
| 266 | $self->status( | ||||||||||||||||||||||||||||||
| 267 | 31 | do { | |||||||||||||||||||||||||||||
| 268 | 31 | ▶ | if ( $self->signal != 0 ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 269 | 4 | $log->warn( | |||||||||||||||||||||||||||||
| 270 | 'Killed', | ||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||
| 272 | pid => $self->pid, | ||||||||||||||||||||||||||||||
| 273 | signal => $self->signal, | ||||||||||||||||||||||||||||||
| 274 | core => $self->core | ||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||
| 278 | elsif ( $self->exit != 0 ) { | ||||||||||||||||||||||||||||||
| 279 | 2 | $log->warn( | |||||||||||||||||||||||||||||
| 280 | 'Non-zero exit', | ||||||||||||||||||||||||||||||
| 281 | { | ||||||||||||||||||||||||||||||
| 282 | pid => $self->pid, | ||||||||||||||||||||||||||||||
| 283 | exit => $self->exit | ||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||
| 285 | ); | ||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||
| 287 | else { | ||||||||||||||||||||||||||||||
| 288 | 25 | 'Terminated'; | |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||
| 293 | 31 | ▶ | not( $self->exit or $self->signal ); | ||||||||||||||||||||||||||||
|
Condition100%3/3
$self->exit || $self->signal
MC/DC100%2/2
$self->exit || $self->signal
$self->exit
$self->signal
Truth table100%3/3
A || B
A= $self->exitB= $self->signal
| |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | 31 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 297 | 31 | my $self = shift; | |||||||||||||||||||||||||||||
| 298 | 31 | $self->close; | |||||||||||||||||||||||||||||
| 299 | 31 | $self->wait_child; | |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||
| 302 | 2 | 1; | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||
| 304 | __END__ | ||||||||||||||||||||||||||||||