| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Beam::Runner::ExecCommand; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.015'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Run an external command |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
#pod |
|
7
|
|
|
|
|
|
|
#pod beam run |
|
8
|
|
|
|
|
|
|
#pod |
|
9
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
10
|
|
|
|
|
|
|
#pod |
|
11
|
|
|
|
|
|
|
#pod This runnable module runs an external command using L. |
|
12
|
|
|
|
|
|
|
#pod |
|
13
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
|
14
|
|
|
|
|
|
|
#pod |
|
15
|
|
|
|
|
|
|
#pod L, L |
|
16
|
|
|
|
|
|
|
#pod |
|
17
|
|
|
|
|
|
|
#pod =cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
97196
|
use Moo; |
|
|
1
|
|
|
|
|
11385
|
|
|
|
1
|
|
|
|
|
5
|
|
|
20
|
1
|
|
|
1
|
|
1579
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
|
|
with 'Beam::Runnable'; |
|
22
|
1
|
|
|
1
|
|
550
|
use Types::Standard qw( Str ArrayRef ); |
|
|
1
|
|
|
|
|
73760
|
|
|
|
1
|
|
|
|
|
9
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#pod =attr command |
|
25
|
|
|
|
|
|
|
#pod |
|
26
|
|
|
|
|
|
|
#pod The command to run. If a string, will execute the command in a subshell. |
|
27
|
|
|
|
|
|
|
#pod If an arrayref, will execute the command directly without a subshell. |
|
28
|
|
|
|
|
|
|
#pod |
|
29
|
|
|
|
|
|
|
#pod =cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has command => ( |
|
32
|
|
|
|
|
|
|
is => 'ro', |
|
33
|
|
|
|
|
|
|
isa => ArrayRef[Str]|Str, |
|
34
|
|
|
|
|
|
|
required => 1, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub run { |
|
38
|
2
|
|
|
2
|
0
|
15571
|
my ( $self, @args ) = @_; |
|
39
|
2
|
|
|
|
|
12
|
my $cmd = $self->command; |
|
40
|
2
|
|
|
|
|
4
|
my $exit; |
|
41
|
2
|
100
|
|
|
|
9
|
if ( ref $cmd eq 'ARRAY' ) { |
|
42
|
1
|
|
|
|
|
2964
|
$exit = system @$cmd; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
else { |
|
45
|
1
|
|
|
|
|
4199
|
$exit = system $cmd; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
2
|
50
|
|
|
|
131
|
if ( $exit == -1 ) { |
|
|
|
50
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
my $name = ref $cmd eq 'ARRAY' ? $cmd->[0] : $cmd; |
|
49
|
0
|
|
|
|
|
0
|
die "Error starting command %s: $!\n", $name; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
elsif ( $exit & 127 ) { |
|
52
|
0
|
|
|
|
|
0
|
die sprintf "Command died with signal %d\n", ( $exit & 127 ); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
2
|
|
|
|
|
189
|
return $exit; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |