File Coverage

blib/lib/Beam/Runner/ExecCommand.pm
Criterion Covered Total %
statement 17 20 85.0
branch 4 8 50.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 25 33 75.7


line stmt bran cond sub pod time code
1             package Beam::Runner::ExecCommand;
2             our $VERSION = '0.016';
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   93905 use Moo;
  1         10986  
  1         12  
20 1     1   1398 use warnings;
  1         3  
  1         37  
21             with 'Beam::Runnable';
22 1     1   620 use Types::Standard qw( Str ArrayRef );
  1         71672  
  1         11  
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 14484 my ( $self, @args ) = @_;
39 2         9 my $cmd = $self->command;
40 2         3 my $exit;
41 2 100       9 if ( ref $cmd eq 'ARRAY' ) {
42 1         2444 $exit = system @$cmd;
43             }
44             else {
45 1         2886 $exit = system $cmd;
46             }
47 2 50       116 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         95 return $exit;
55             }
56              
57             1;
58              
59             __END__