Footprintless/CommandRunner.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.6% 13 / 15 Podpod 100% 8 / 8 totaltotal 94.3% 67 / 71 CC 3 SCAR 3.0
CC
3
Cov
96%
get_exit_code
2.0
_run
2.0
run
2.0
CRAP 1.4
« Footprintless/App/Command/log/cat.pm ↑ Summary Footprintless/Resource/Url.pm »
1 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::CommandRunner;
5 12 $Footprintless::CommandRunner::VERSION = '1.29';
6 # ABSTRACT: A contract for an command runner
7 # PODNAME: Footprintless::CommandRunner
8  
9 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Footprintless::CommandRunner::ExecutionException;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 my $logger = Log::Any->get_logger();
14  
15 25 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 25 return bless( {}, shift )->_init(@_);
17 }
18  
19 25 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
20 25 my ( $self, @options ) = @_;
21 25 return $self;
22 }
23  
24 43 ▶sub get_command {
Subroutine get_command: called CC=1 SCAR=0.0
Pod documented
25 43 return $_[0]->{last_call}{command};
26 }
27  
28 1 ▶sub get_exception {
Subroutine get_exception: called CC=1 SCAR=0.0
Pod documented
29 1 return $_[0]->{last_call}{exception};
30 }
31  
32 0 ▶sub get_exit_code {
Subroutine get_exit_code: not called CC=1 SCAR=6.9
Pod documented
33 0 return $_[0]->{last_call}{exit_code};
34 }
35  
36 1 ▶sub get_stderr {
Subroutine get_stderr: called CC=1 SCAR=0.0
Pod documented
37 1 return $_[0]->{last_call}{stderr};
38 }
39  
40 2 ▶sub get_stdout {
Subroutine get_stdout: called CC=1 SCAR=0.0
Pod documented
41 2 return $_[0]->{last_call}{stdout};
42 }
43  
44 0 ▶sub _run {
Subroutine _run: not called CC=1 SCAR=6.9
45 0 croak("must use an implementation class");
46 }
47  
48 82 ▶sub run {
Subroutine run: called CC=2 SCAR=6.9
Pod documented
49 82 my ( $self, $command, @runner_options ) = @_;
50  
51 82 $self->{last_call} = { command => $command };
52  
53 82 $logger->debugf( 'running [%s]', $command );
54 82 $logger->tracef( 'with options %s', \@runner_options );
55 82 my $exit_code;
56 82 eval {
57 82 $exit_code = $self->_run( $command, @runner_options );
58 81 $self->{last_call}{exit_code} = $exit_code;
59 };
60 82 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 81 82
61 1 $self->{last_call}{exception} = $@;
62 1 $exit_code = -1;
63 }
64 82 return $exit_code;
65 }
66  
67 76 ▶sub run_or_die {
Subroutine run_or_die: called CC=2 SCAR=6.9
Pod documented
68 76 my ( $self, $command, @runner_options ) = @_;
69 76 my $exit_code = $self->run( $command, @runner_options );
70 76 ▶ if ($exit_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_code) 6 70 76
71 die(Footprintless::CommandRunner::ExecutionException->new(
72 $command, $exit_code,
73 $self->{last_call}{exception}, $self->{last_call}{stderr}
74 )
75 6 );
76 }
77 70 return $self->{last_call}{stdout};
78 }
79  
80 12 1;
81  
82 __END__
« Footprintless/App/Command/log/cat.pm ↑ Summary Footprintless/Resource/Url.pm »