blib/lib/Code/TidyAll/Role/RunsCommand.pm

filter: Statementstmt 100% 52 / 52 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 92.3% 72 / 78 CC 5 SCAR 7.5
CC
5
Cov
93%
__ANON__
5.3
_run_or_die
1.0
BEGIN
1.0
CRAP 2.1
« blib/lib/Code/TidyAll/Plugin/PerlCritic.pm ↑ Summary blib/lib/Code/TidyAll/Plugin/CSSUnminifier.pm »
1 package Code::TidyAll::Role::RunsCommand;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use IPC::Run3 qw(run3);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use List::SomeUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Specio::Library::Builtins;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Specio::Library::Numeric;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Text::ParseWords qw(shellwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = '0.85';
16  
17 has ok_exit_codes => (
18 is => 'ro',
19 isa => t( 'ArrayRef', of => t('PositiveOrZeroInt') ),
20 6 ▶ default => sub { [0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 4 );
22  
23 # We will end up getting $self->argv from the Plugin base class.
24  
25 9 ▶sub _run_or_die {
Subroutine _run_or_die: called CC=1 SCAR=0.0
26 9 my $self = shift;
27 9 my @argv = @_;
28  
29 9 my $output;
30 9 my @cmd = ( shellwords( $self->cmd ), shellwords( $self->argv ), @argv );
31 9 ▶ try {
Subroutine __ANON__: called CC=5 SCAR=16.6
32 9 local $?;
33 9 run3( \@cmd, \undef, \$output, \$output );
34 9 my $code = $? >> 8;
35 9 ▶ if ( $self->_is_bad_exit_code($code) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_bad_exit_code($code)) 3 6 9
36 3 my $signal = $? & 127;
37 3 my $msg = "exited with $code";
38 3 ▶ $msg .= " - received signal $signal" if $signal;
Branch: 1 branch
BranchTrueFalseTotal
if $signal 0 3 3
39 3 ▶ $msg .= " - output was:\n$output" if defined $output and length $output;
Branch: 1 branch
BranchTrueFalseTotal
if defined $output and length $output 0 3 3
Condition33%1/3
defined $output and length $output
!ll&&!rl&&r
030
MC/DC0%0/2
defined $output and length $output
defined $output length $output
Truth table33%1/3
A and B
A= defined $outputB= length $output
ABresult
0X0
100
111
40 3 die "$msg\n";
41 }
42 }
43 3 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 3 die sprintf(
45 "Running [%s] failed\n %s",
46 ( join q{ }, @cmd ),
47 $_,
48 );
49 9 };
50  
51 6 return $output;
52 }
53  
54 9 ▶sub _is_bad_exit_code {
Subroutine _is_bad_exit_code: called CC=1 SCAR=0.0
55 9 my $self = shift;
56 9 my $code = shift;
57  
58 9 ▶ return !( any { $code == $_ } @{ $self->ok_exit_codes } );
Subroutine __ANON__: called CC=1 SCAR=0.0
59 }
60  
61 4 1;
62  
63 # ABSTRACT: A role for plugins which run external commands
64  
65 __END__
« blib/lib/Code/TidyAll/Plugin/PerlCritic.pm ↑ Summary blib/lib/Code/TidyAll/Plugin/CSSUnminifier.pm »