Footprintless/CommandRunner/IPCRun.pm

filter: Statementstmt 100% 59 / 59 Branchbran 100% 20 / 20 Conditioncond 92.0% 23 / 25 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 96.8% 121 / 125 CC 23 SCAR 24.4
CC
23
Cov
98%
_run
17.0
_run_options
7.0
BEGIN
1.0
CRAP 11.5
« Footprintless/App/Command/config.pm ↑ Summary Footprintless/Command.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::CommandRunner::IPCRun;
5 7 $Footprintless::CommandRunner::IPCRun::VERSION = '1.29';
6 # ABSTRACT: An implementation of Footprintless::CommandRunner using IPC::Run
7 # PODNAME: Footprintless::CommandRunner::IPCRun
8  
9 7 ▶use parent qw(Footprintless::CommandRunner);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use IPC::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 my $logger = Log::Any->get_logger();
16  
17 26 ▶sub _run_options {
Subroutine _run_options: called CC=7 SCAR=19.5
18 26 my ( $self, $runner_options ) = @_;
19 26 my @timeout;
20 26 ▶ if ( $runner_options->{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runner_options->{"timeout"}) 3 23 26
21 3 @timeout = ( IPC::Run::timeout( $runner_options->{timeout} ) );
22 }
23  
24 26 ▶ my $in = $runner_options->{in_handle} || \undef;
Condition100%2/2
$runner_options->{'in_handle'} || \(undef)
l!l
125
MC/DC100%1/1
$runner_options->{'in_handle'} || \(undef)
$runner_options->{'in_handle'}
Truth table100%2/2
A
A= $runner_options->{'in_handle'}
Aresult
11
00
25 my $out =
26 $runner_options->{out_handle}
27 || $runner_options->{out_callback}
28 26 ▶ || \$self->{last_call}{stdout};
Condition100%5/5
$runner_options->{'out_handle'} || $runner_options->{'out_callback'} || \$self->{'last_call'}{'stdout'}
l!l
422
$runner_options->{"out_handle"} or $runner_options->{"out_callback"}
l!l&&r!l&&!r
1322
MC/DC100%2/2
$runner_options->{'out_handle'} || $runner_options->{'out_callback'} || \$self->{'last_call'}{'stdout'}
$runner_options->{"out_handle"} $runner_options->{"out_callback"}
Truth table100%3/3
A or B
A= $runner_options->{"out_handle"}B= $runner_options->{"out_callback"}
ABresult
1X1
011
000
29 my $err =
30 $runner_options->{err_handle}
31 || $runner_options->{err_callback}
32 26 ▶ || \$self->{last_call}{stderr};
Condition100%5/5
$runner_options->{'err_handle'} || $runner_options->{'err_callback'} || \$self->{'last_call'}{'stderr'}
l!l
323
$runner_options->{"err_handle"} or $runner_options->{"err_callback"}
l!l&&r!l&&!r
1223
MC/DC100%2/2
$runner_options->{'err_handle'} || $runner_options->{'err_callback'} || \$self->{'last_call'}{'stderr'}
$runner_options->{"err_handle"} $runner_options->{"err_callback"}
Truth table100%3/3
A or B
A= $runner_options->{"err_handle"}B= $runner_options->{"err_callback"}
ABresult
1X1
011
000
33  
34 26 return ( '<', $in, '>', $out, '2>', $err, @timeout );
35 }
36  
37 26 ▶sub _run {
Subroutine _run: called CC=17 SCAR=28.3
38 26 my ( $self, $command, $runner_options ) = @_;
39 26 ▶ if ( $runner_options->{out_callback} || $runner_options->{err_callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runner_options->{'out_callback'} or $runner_options->{'err_callback'}) { } 4 22 26
Condition100%3/3
$runner_options->{"out_callback"} or $runner_options->{"err_callback"}
l!l&&r!l&&!r
3122
MC/DC100%2/2
$runner_options->{"out_callback"} or $runner_options->{"err_callback"}
$runner_options->{"out_callback"} $runner_options->{"err_callback"}
Truth table100%3/3
A or B
A= $runner_options->{"out_callback"}B= $runner_options->{"err_callback"}
ABresult
1X1
011
000
40 4 my $out_callback = $runner_options->{out_callback};
41 4 my $err_callback = $runner_options->{err_callback};
42  
43 4 my ( $out, $err );
44 4 ▶ local $runner_options->{out_callback} = \$out if ($out_callback);
Branch: 1 branch
BranchTrueFalseTotal
if $out_callback 3 1 4
45 4 ▶ local $runner_options->{err_callback} = \$err if ($err_callback);
Branch: 1 branch
BranchTrueFalseTotal
if $err_callback 2 2 4
46 4 my $harness =
47 IPC::Run::start( [ 'sh', '-c', $command ], $self->_run_options($runner_options) );
48  
49 4 my ( $last_part_out, $last_part_err ) = ( '', '' );
50 4 eval {
51 4 ▶ while ( $harness->pump() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness->pump) 11 3 14
52 11 ▶ if ($out_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_callback) 8 3 11
53 8 my @lines = split( /\r?\n/, $last_part_out . $out, -1 );
54 8 ▶ $last_part_out = pop(@lines) || '';
Condition100%2/2
pop @lines || ''
l!l
35
MC/DC100%1/1
pop @lines || ''
pop @lines
Truth table100%2/2
A
A= pop @lines
Aresult
11
00
55 8 &$out_callback($_) foreach (@lines);
56 7 $out = '';
57 }
58  
59 10 ▶ if ($err_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_callback) 7 3 10
60 7 my @lines = split( /\r?\n/, $last_part_err . $err, -1 );
61 7 ▶ $last_part_err = pop(@lines) || '';
Condition100%2/2
pop @lines || ''
l!l
25
MC/DC100%1/1
pop @lines || ''
pop @lines
Truth table100%2/2
A
A= pop @lines
Aresult
11
00
62 7 &$err_callback($_) foreach (@lines);
63 7 $err = '';
64 }
65 }
66  
67 3 ▶ &$out_callback($last_part_out)
Branch: 1 branch
BranchTrueFalseTotal
if $out_callback and length $last_part_out > 0 2 1 3
Condition66%2/3
$out_callback and length $last_part_out > 0
!ll&&!rl&&r
102
MC/DC50%1/2
$out_callback and length $last_part_out > 0
$out_callback length $last_part_out > 0
Truth table66%2/3
A and B
A= $out_callbackB= length $last_part_out > 0
ABresult
0X0
100
111
68 if ( $out_callback && length($last_part_out) > 0 );
69 3 ▶ &$err_callback($last_part_err)
Branch: 1 branch
BranchTrueFalseTotal
if $err_callback and length $last_part_err > 0 2 1 3
Condition66%2/3
$err_callback and length $last_part_err > 0
!ll&&!rl&&r
102
MC/DC50%1/2
$err_callback and length $last_part_err > 0
$err_callback length $last_part_err > 0
Truth table66%2/3
A and B
A= $err_callbackB= length $last_part_err > 0
ABresult
0X0
100
111
70 if ( $err_callback && length($last_part_err) > 0 );
71 };
72 4 my $error = $@;
73 4 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 1 3 4
74 1 $logger->debugf( "callback exited early: %s", $error );
75 1 $harness->kill_kill();
76 1 die($error);
77 }
78 }
79 else {
80 22 IPC::Run::run( [ 'sh', '-c', $command ], $self->_run_options($runner_options) );
81 }
82 25 return $? >> 8;
83 }
84  
85 7 1;
86  
87 __END__
« Footprintless/App/Command/config.pm ↑ Summary Footprintless/Command.pm »