Runner/ExecCommand.pm

filter: Statementstmt 87.5% 21 / 24 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 78.3% 29 / 37 CC 5 SCAR 14.5
CC
5
Cov
78%
run
6.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.3
« Runner/Util.pm ↑ Summary Runner/Command/list.pm »
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
BranchTrueFalseTotal
if (ref $cmd eq 'ARRAY') { } 1 1 2
42 1 $exit = system @$cmd;
43 }
44 else {
45 1 $exit = system $cmd;
46 }
47 2 ▶ if ( $exit == -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exit == -1) { } 0 2 2
elsif ($exit & 127) { } 0 2 2
48 0 ▶ my $name = ref $cmd eq 'ARRAY' ? $cmd->[0] : $cmd;
Branch: 1 branch
BranchTrueFalseTotal
ref $cmd eq 'ARRAY' ? : 0 0 0
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__
« Runner/Util.pm ↑ Summary Runner/Command/list.pm »