| 1 | package Beam::Runner::ExecCommand; | ||||||||||||||
| 2 | 2 | our $VERSION = '0.016'; | |||||||||||||
| 3 | # ABSTRACT: Run an external command | ||||||||||||||
| 4 | |||||||||||||||
| 5 | #pod =head1 SYNOPSIS | ||||||||||||||
| 6 | #pod | ||||||||||||||
| 7 | #pod beam run <container> <service> | ||||||||||||||
| 8 | #pod | ||||||||||||||
| 9 | #pod =head1 DESCRIPTION | ||||||||||||||
| 10 | #pod | ||||||||||||||
| 11 | #pod This runnable module runs an external command using L<perlfunc/system>. | ||||||||||||||
| 12 | #pod | ||||||||||||||
| 13 | #pod =head1 SEE ALSO | ||||||||||||||
| 14 | #pod | ||||||||||||||
| 15 | #pod L<beam>, L<Beam::Runnable> | ||||||||||||||
| 16 | #pod | ||||||||||||||
| 17 | #pod =cut | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 2 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 2 | with 'Beam::Runnable'; | |||||||||||||
| 22 | 2 | ▶ | use Types::Standard qw( Str ArrayRef ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 | 2 | has command => ( | |||||||||||||
| 32 | is => 'ro', | ||||||||||||||
| 33 | isa => ArrayRef[Str]|Str, | ||||||||||||||
| 34 | required => 1, | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 2 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: called CC=5 SCAR=18.3
Pod
undocumented
| |||||||||||||||
| 38 | 2 | my ( $self, @args ) = @_; | |||||||||||||
| 39 | 2 | my $cmd = $self->command; | |||||||||||||
| 40 | 2 | my $exit; | |||||||||||||
| 41 | 2 | ▶ | if ( ref $cmd eq 'ARRAY' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 1 | $exit = system @$cmd; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | else { | ||||||||||||||
| 45 | 1 | $exit = system $cmd; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | 2 | ▶ | if ( $exit == -1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 48 | 0 | ▶ | my $name = ref $cmd eq 'ARRAY' ? $cmd->[0] : $cmd; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 0 | die "Error starting command %s: $!\n", $name; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | elsif ( $exit & 127 ) { | ||||||||||||||
| 52 | 0 | die sprintf "Command died with signal %d\n", ( $exit & 127 ); | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | 2 | return $exit; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 2 | 1; | |||||||||||||
| 58 | |||||||||||||||
| 59 | __END__ | ||||||||||||||