line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
12
|
|
|
12
|
|
178329
|
use strict; |
|
12
|
|
|
|
|
62
|
|
|
12
|
|
|
|
|
291
|
|
2
|
12
|
|
|
12
|
|
100
|
use warnings; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
484
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::CommandRunner; |
5
|
|
|
|
|
|
|
$Footprintless::CommandRunner::VERSION = '1.29'; |
6
|
|
|
|
|
|
|
# ABSTRACT: A contract for an command runner |
7
|
|
|
|
|
|
|
# PODNAME: Footprintless::CommandRunner |
8
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
64
|
use Carp; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
741
|
|
10
|
12
|
|
|
12
|
|
8383
|
use Footprintless::CommandRunner::ExecutionException; |
|
12
|
|
|
|
|
31
|
|
|
12
|
|
|
|
|
324
|
|
11
|
12
|
|
|
12
|
|
488
|
use Log::Any; |
|
12
|
|
|
|
|
7639
|
|
|
12
|
|
|
|
|
84
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
25
|
|
|
25
|
1
|
67992
|
return bless( {}, shift )->_init(@_); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init { |
20
|
25
|
|
|
25
|
|
122
|
my ( $self, @options ) = @_; |
21
|
25
|
|
|
|
|
118
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get_command { |
25
|
43
|
|
|
43
|
1
|
234
|
return $_[0]->{last_call}{command}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_exception { |
29
|
1
|
|
|
1
|
1
|
7
|
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
|
13
|
return $_[0]->{last_call}{stderr}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_stdout { |
41
|
2
|
|
|
2
|
1
|
376
|
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
|
3234
|
my ( $self, $command, @runner_options ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
82
|
|
|
|
|
440
|
$self->{last_call} = { command => $command }; |
52
|
|
|
|
|
|
|
|
53
|
82
|
|
|
|
|
446
|
$logger->debugf( 'running [%s]', $command ); |
54
|
82
|
|
|
|
|
1254
|
$logger->tracef( 'with options %s', \@runner_options ); |
55
|
82
|
|
|
|
|
683
|
my $exit_code; |
56
|
82
|
|
|
|
|
227
|
eval { |
57
|
82
|
|
|
|
|
278
|
$exit_code = $self->_run( $command, @runner_options ); |
58
|
81
|
|
|
|
|
790
|
$self->{last_call}{exit_code} = $exit_code; |
59
|
|
|
|
|
|
|
}; |
60
|
82
|
100
|
|
|
|
498
|
if ($@) { |
61
|
1
|
|
|
|
|
14
|
$self->{last_call}{exception} = $@; |
62
|
1
|
|
|
|
|
9
|
$exit_code = -1; |
63
|
|
|
|
|
|
|
} |
64
|
82
|
|
|
|
|
431
|
return $exit_code; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run_or_die { |
68
|
76
|
|
|
76
|
1
|
9021
|
my ( $self, $command, @runner_options ) = @_; |
69
|
76
|
|
|
|
|
312
|
my $exit_code = $self->run( $command, @runner_options ); |
70
|
76
|
100
|
|
|
|
236
|
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
|
|
|
|
|
235
|
); |
76
|
|
|
|
|
|
|
} |
77
|
70
|
|
|
|
|
561
|
return $self->{last_call}{stdout}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |