line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
12
|
|
|
12
|
|
121707
|
use strict; |
|
12
|
|
|
|
|
50
|
|
|
12
|
|
|
|
|
292
|
|
2
|
12
|
|
|
12
|
|
49
|
use warnings; |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
546
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::CommandRunner; |
5
|
|
|
|
|
|
|
$Footprintless::CommandRunner::VERSION = '1.28'; |
6
|
|
|
|
|
|
|
# ABSTRACT: A contract for an command runner |
7
|
|
|
|
|
|
|
# PODNAME: Footprintless::CommandRunner |
8
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
51
|
use Carp; |
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
543
|
|
10
|
12
|
|
|
12
|
|
4327
|
use Footprintless::CommandRunner::ExecutionException; |
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
281
|
|
11
|
12
|
|
|
12
|
|
492
|
use Log::Any; |
|
12
|
|
|
|
|
6102
|
|
|
12
|
|
|
|
|
68
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
25
|
|
|
25
|
1
|
50126
|
return bless( {}, shift )->_init(@_); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init { |
20
|
25
|
|
|
25
|
|
100
|
my ( $self, @options ) = @_; |
21
|
25
|
|
|
|
|
99
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get_command { |
25
|
43
|
|
|
43
|
1
|
625
|
return $_[0]->{last_call}{command}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_exception { |
29
|
1
|
|
|
1
|
1
|
6
|
return $_[0]->{last_call}{exception}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_exit_code { |
33
|
0
|
|
|
0
|
1
|
0
|
return $_[0]->{last_call}{exit_code}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_stderr { |
37
|
1
|
|
|
1
|
1
|
31
|
return $_[0]->{last_call}{stderr}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_stdout { |
41
|
2
|
|
|
2
|
1
|
66
|
return $_[0]->{last_call}{stdout}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _run { |
45
|
0
|
|
|
0
|
|
0
|
croak("must use an implementation class"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub run { |
49
|
82
|
|
|
82
|
1
|
2407
|
my ( $self, $command, @runner_options ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
82
|
|
|
|
|
460
|
$self->{last_call} = { command => $command }; |
52
|
|
|
|
|
|
|
|
53
|
82
|
|
|
|
|
468
|
$logger->debugf( 'running [%s]', $command ); |
54
|
82
|
|
|
|
|
1226
|
$logger->tracef( 'with options %s', \@runner_options ); |
55
|
82
|
|
|
|
|
721
|
my $exit_code; |
56
|
82
|
|
|
|
|
233
|
eval { |
57
|
82
|
|
|
|
|
269
|
$exit_code = $self->_run( $command, @runner_options ); |
58
|
81
|
|
|
|
|
774
|
$self->{last_call}{exit_code} = $exit_code; |
59
|
|
|
|
|
|
|
}; |
60
|
82
|
100
|
|
|
|
590
|
if ($@) { |
61
|
1
|
|
|
|
|
20
|
$self->{last_call}{exception} = $@; |
62
|
1
|
|
|
|
|
13
|
$exit_code = -1; |
63
|
|
|
|
|
|
|
} |
64
|
82
|
|
|
|
|
371
|
return $exit_code; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run_or_die { |
68
|
76
|
|
|
76
|
1
|
6246
|
my ( $self, $command, @runner_options ) = @_; |
69
|
76
|
|
|
|
|
321
|
my $exit_code = $self->run( $command, @runner_options ); |
70
|
76
|
100
|
|
|
|
234
|
if ($exit_code) { |
71
|
|
|
|
|
|
|
die(Footprintless::CommandRunner::ExecutionException->new( |
72
|
|
|
|
|
|
|
$command, $exit_code, |
73
|
|
|
|
|
|
|
$self->{last_call}{exception}, $self->{last_call}{stderr} |
74
|
|
|
|
|
|
|
) |
75
|
6
|
|
|
|
|
240
|
); |
76
|
|
|
|
|
|
|
} |
77
|
70
|
|
|
|
|
315
|
return $self->{last_call}{stdout}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |