| 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
| |||||||||||||||||||||||||||||
| 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)
MC/DC100%1/1
$runner_options->{'in_handle'} || \(undef)
$runner_options->{'in_handle'}
Truth table100%2/2
A
A= $runner_options->{'in_handle'}
| |||||||||||||||||||||||||||||
| 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'}
$runner_options->{"out_handle"} or $runner_options->{"out_callback"}
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"}
| |||||||||||||||||||||||||||||
| 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'}
$runner_options->{"err_handle"} or $runner_options->{"err_callback"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$runner_options->{"out_callback"} or $runner_options->{"err_callback"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | local $runner_options->{err_callback} = \$err if ($err_callback); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | 11 | ▶ | if ($out_callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 8 | my @lines = split( /\r?\n/, $last_part_out . $out, -1 ); | |||||||||||||||||||||||||||
| 54 | 8 | ▶ | $last_part_out = pop(@lines) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
pop @lines || ''
MC/DC100%1/1
pop @lines || ''
pop @lines
Truth table100%2/2
A
A= pop @lines
| |||||||||||||||||||||||||||||
| 55 | 8 | &$out_callback($_) foreach (@lines); | |||||||||||||||||||||||||||
| 56 | 7 | $out = ''; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 10 | ▶ | if ($err_callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 7 | my @lines = split( /\r?\n/, $last_part_err . $err, -1 ); | |||||||||||||||||||||||||||
| 61 | 7 | ▶ | $last_part_err = pop(@lines) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
pop @lines || ''
MC/DC100%1/1
pop @lines || ''
pop @lines
Truth table100%2/2
A
A= pop @lines
| |||||||||||||||||||||||||||||
| 62 | 7 | &$err_callback($_) foreach (@lines); | |||||||||||||||||||||||||||
| 63 | 7 | $err = ''; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3 | ▶ | &$out_callback($last_part_out) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$out_callback and length $last_part_out > 0
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
| |||||||||||||||||||||||||||||
| 68 | if ( $out_callback && length($last_part_out) > 0 ); | ||||||||||||||||||||||||||||
| 69 | 3 | ▶ | &$err_callback($last_part_err) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$err_callback and length $last_part_err > 0
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
| |||||||||||||||||||||||||||||
| 70 | if ( $err_callback && length($last_part_err) > 0 ); | ||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||
| 72 | 4 | my $error = $@; | |||||||||||||||||||||||||||
| 73 | 4 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||