blib/lib/Dist/Zilla/Plugin/Run/Role/Runner.pm

filter: Statementstmt 94.9% 149 / 157 Branchbran 88.8% 64 / 72 Conditioncond 80.7% 21 / 26 MC/DCmcdc 62.5% 10 / 16 Subroutinesub 100% 29 / 29 Podpod 0.0% 0 / 2 totaltotal 90.4% 273 / 302 CC 52 SCAR 19.0
CC
52
Cov
92%
_call_script
15.6
_eval_cmd
10.0
_run_cmd
10.0
CRAP 6.7
↑ Summary blib/lib/Dist/Zilla/Plugin/Run/Clean.pm »
1 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::Run::Role::Runner;
4 # vim: set ts=8 sts=2 sw=2 tw=115 et :
5  
6 12 our $VERSION = '0.050';
7  
8 12 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use File::Spec (); # core
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Config (); # core
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Moose::Util 'find_meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 has perlpath => (
15 is => 'ro',
16 isa => 'Str',
17 lazy => 1,
18 builder => 'current_perl_path',
19 );
20  
21 12 has censor_commands => (
22 is => 'ro',
23 isa => 'Bool',
24 default => 0,
25 );
26  
27 has [ qw(run run_if_trial run_no_trial run_if_release run_no_release) ] => (
28 is => 'ro',
29 isa => 'ArrayRef[Str]',
30 228 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 12 );
32  
33 has eval => (
34 is => 'ro',
35 isa => 'ArrayRef[Str]',
36 36 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 12 );
38  
39 12 has fatal_errors => (
40 is => 'ro',
41 isa => 'Bool',
42 default => 1,
43 );
44  
45 12 has quiet => (
46 is => 'ro',
47 isa => 'Bool',
48 default => 0,
49 );
50  
51 around dump_config => sub
52 52 ▶{
Subroutine __ANON__: called CC=5 SCAR=16.1
53 52 my ($orig, $self) = @_;
54 52 my $config = $self->$orig;
55  
56 $config->{+__PACKAGE__} = {
57 version => $VERSION,
58 (map +($_ => $self->$_ ? 1 : 0), qw(fatal_errors quiet)),
59 map
60 312 ▶ @{ $self->$_ }
Branch: 1 branch
BranchTrueFalseTotal
$self->censor_commands || /\b\w+:[^\@]+\@\b/ ? : 2 70 72
Condition100%3/3
$self->censor_commands or /\b\w+:[^\@]+\@\b/
l!l&&r!l&&!r
1170
MC/DC100%2/2
$self->censor_commands or /\b\w+:[^\@]+\@\b/
$self->censor_commands /\b\w+:[^\@]+\@\b/
Truth table100%3/3
A or B
A= $self->censor_commandsB= /\b\w+:[^\@]+\@\b/
ABresult
1X1
011
000
61 # look for user:password URIs
62 52 ▶ ? ( $_ => [ map $self->censor_commands || /\b\w+:[^@]+@\b/ ? 'REDACTED' : $_, @{ $self->$_ } ] )
Branch: 2 branches
BranchTrueFalseTotal
$self->$_ ? : 49 55 104
@{$self->$_;} ? : 71 241 312
63 : (),
64 qw(run run_if_trial run_no_trial run_if_release run_no_release eval),
65 };
66  
67 52 return $config;
68 12 };
69  
70 57 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
71 57 my ( $orig, $class, @args ) = @_;
72 57 my $built = $class->$orig(@args);
73  
74 57 foreach my $dep (qw( notexist_fatal )) {
75 57 ▶ if ( exists $built->{$dep} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $built->{$dep}) 0 57 57
76 0 warn(" !\n ! $class attribute '$dep' is deprecated and has no effect.\n !\n");
77 0 delete $built->{$dep};
78 }
79 }
80 57 return $built;
81 12 };
82  
83 28 ▶sub _is_trial {
Subroutine _is_trial: called CC=5 SCAR=16.1
84 28 my $self = shift;
85  
86 # we want to avoid provoking other plugins prematurely, but also be as
87 # accurate as we can with this status
88  
89 28 my $release_status_attr = find_meta($self->zilla)->find_attribute_by_name('release_status');
90  
91 28 ▶ return ( $self->zilla->is_trial ? 1 : 0 ) if
Branch: 2 branches
BranchTrueFalseTotal
if not $release_status_attr or $release_status_attr->has_value($self->zilla) 20 8 28
$self->zilla->is_trial ? : 10 10 20
Condition66%2/3
not $release_status_attr or $release_status_attr->has_value($self->zilla)
l!l&&r!l&&!r
0208
MC/DC50%1/2
not $release_status_attr or $release_status_attr->has_value($self->zilla)
not $release_status_attr $release_status_attr->has_value($self->zilla)
Truth table66%2/3
not(A) or B
A= not $release_status_attrB= $release_status_attr->has_value($self->zilla)
ABresult
1X1
011
000
92 not $release_status_attr # legacy (before Dist::Zilla 5.035)
93 or $release_status_attr->has_value($self->zilla);
94  
95 # otherwise, only use the logic that does not require zilla->version
96 # before Dist::Zilla 5.035, this is what $zilla->is_trial returned
97 8 ▶ return eval { $self->zilla->_release_status_from_env =~ /\A(?:testing|unstable)\z/ } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->zilla->_release_status_from_env =~ /\A(?:testing|unstable)\z/ } } ? : 4 4 8
98 }
99  
100 52 ▶sub _call_script {
Subroutine _call_script: called CC=13 SCAR=27.5
101 52 my ( $self, $params ) = @_;
102  
103 52 foreach my $run_cmd (@{$self->run}) {
104 43 $self->_run_cmd($run_cmd, $params);
105 }
106  
107 47 foreach my $run_cmd (@{$self->run_if_trial}) {
108 4 ▶ if ($self->_is_trial) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_trial) { } 2 2 4
109 2 $self->_run_cmd($run_cmd, $params);
110 } else {
111 2 $self->log_debug([ 'not executing, because no trial: %s', $run_cmd ]);
112 }
113 }
114  
115 47 foreach my $run_cmd (@{$self->run_no_trial}) {
116 6 ▶ if ($self->_is_trial) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_trial) { } 3 3 6
117 3 $self->log_debug([ 'not executing, because trial: %s', $run_cmd ]);
118 } else {
119 3 $self->_run_cmd($run_cmd, $params);
120 }
121 }
122  
123 47 ▶ my $is_release = defined $ENV{'DZIL_RELEASING'} && $ENV{'DZIL_RELEASING'} == 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'DZIL_RELEASING'} && $ENV{'DZIL_RELEASING'} == 1 ? : 24 23 47
Condition66%2/3
defined $ENV{"DZIL_RELEASING"} and $ENV{"DZIL_RELEASING"} == 1
!ll&&!rl&&r
23024
MC/DC50%1/2
defined $ENV{"DZIL_RELEASING"} and $ENV{"DZIL_RELEASING"} == 1
defined $ENV{"DZIL_RELEASING"} $ENV{"DZIL_RELEASING"} == 1
Truth table66%2/3
A and B
A= defined $ENV{"DZIL_RELEASING"}B= $ENV{"DZIL_RELEASING"} == 1
ABresult
0X0
100
111
124  
125 47 foreach my $run_cmd (@{$self->run_if_release}) {
126 0 ▶ if ($is_release) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_release) { } 0 0 0
127 0 $self->_run_cmd($run_cmd, $params);
128 } else {
129 0 $self->log_debug([ 'not executing, because no release: %s', $run_cmd ]);
130 }
131 }
132  
133 47 foreach my $run_cmd (@{$self->run_no_release}) {
134 0 ▶ if ($is_release) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_release) { } 0 0 0
135 0 $self->log_debug([ 'not executing, because release: %s', $run_cmd ]);
136 } else {
137 0 $self->_run_cmd($run_cmd, $params);
138 }
139 }
140  
141 47 ▶ if (my @code = @{ $self->eval }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@code) = @{$self->eval;}) 18 29 47
142 18 my $code = join "\n", @code;
143  
144 18 $self->_eval_cmd($code, $params);
145 }
146 }
147  
148 50 ▶sub _run_cmd {
Subroutine _run_cmd: called CC=10 SCAR=23.0
149 50 my ( $self, $run_cmd, $params, $dry_run ) = @_;
150  
151 50 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) 1 49 50
152 1 $self->log_debug([ 'dry run, would run: %s', $run_cmd ]);
153 1 return;
154 }
155  
156 49 ▶ return if not $run_cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $run_cmd 0 49 49
157  
158 49 require IPC::Open3; # core
159  
160 49 my $command = $self->build_formatter($params)->format($run_cmd);
161 49 ▶ $self->${ $self->quiet ? \'log_debug' : \'log' }([ 'executing: %s', $command ]);
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet ? : 6 43 49
162  
163 # autoflush STDOUT so we can see command output right away
164 49 local $| = 1;
165 # allow stderr to remain, for visibility into errors
166 49 my $pid = IPC::Open3::open3(my ($in, $out), '>&STDERR', $command);
167 49 ▶ binmode $out, ':crlf' if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 49 49
168 49 ▶ while(defined(my $line = <$out>)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $out)) 8 49 57
169 8 chomp($line); # logger appends its own newline
170 8 ▶ $self->${ $self->quiet ? \'log_debug' : \'log' }($line);
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet ? : 4 4 8
171 }
172  
173 # zombie repellent
174 49 waitpid($pid, 0);
175  
176 49 ▶ if (my $status = ($? >> 8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $status = $? >> 8) { } 10 39 49
177 10 ▶ $self->${ $self->fatal_errors ? \'log_fatal' : $self->quiet ? \'log_debug' : \'log'}
Branch: 2 branches
BranchTrueFalseTotal
$self->fatal_errors ? : 5 5 10
$self->quiet ? : 2 3 5
178 ([ 'command exited with status %s (%s)', $status, $? ]);
179 }
180 else {
181 39 $self->log_debug('command executed successfully');
182 }
183 }
184  
185 20 ▶sub _eval_cmd {
Subroutine _eval_cmd: called CC=10 SCAR=23.0
186 20 my ( $self, $code, $params, $dry_run ) = @_;
187  
188 20 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) 1 19 20
189 1 $self->log_debug([ 'dry run, would evaluate: %s', $code ]);
190 1 return;
191 }
192  
193 19 $code = $self->build_formatter($params)->format($code);
194 19 ▶ $self->${ $self->quiet ? \'log_debug' : \'log' }([ 'evaluating: %s', $code ]);
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet ? : 5 14 19
195  
196 19 my $sub = __eval_wrapper($code);
197 19 $sub->($self);
198 19 my $error = $@;
199  
200 19 ▶ if (defined $error and $error ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error and $error ne "") 8 11 19
Condition66%2/3
defined $error and $error ne ""
!ll&&!rl&&r
0118
MC/DC50%1/2
defined $error and $error ne ""
defined $error $error ne ""
Truth table66%2/3
A and B
A= defined $errorB= $error ne ""
ABresult
0X0
100
111
201 8 ▶ if ($self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug) 1 7 8
Condition83%5/6
$self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug
!ll&&!rl&&r
701
$self->fatal_errors and $self->quiet
!ll&&!rl&&r
611
MC/DC66%2/3
$self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug
$self->fatal_errors $self->quiet not $self->zilla->logger->get_debug
Truth table75%3/4
A and B and not(C)
A= $self->fatal_errorsB= $self->quietC= not $self->zilla->logger->get_debug
ABCresult
0XX0
10X0
1100
1111
202 1 $self->log([ 'evaluated: %s', $code]);
203 }
204  
205 8 ▶ $self->${ $self->fatal_errors ? \'log_fatal' : $self->quiet ? \'log_debug' : \'log'}
Branch: 2 branches
BranchTrueFalseTotal
$self->fatal_errors ? : 2 6 8
$self->quiet ? : 2 4 6
206 ([ 'evaluation died: %s', $error ]);
207 }
208 }
209  
210 19 ▶sub __eval_wrapper {
Subroutine __eval_wrapper: called CC=1 SCAR=0.0
211 19 my $code = shift;
212 19 ▶ sub { eval $code };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
213 }
214  
215 57 ▶around mvp_multivalue_args => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
216 57 my ($original, $self) = @_;
217  
218 57 my @res = $self->$original();
219  
220 57 push @res, qw( run run_no_trial run_if_trial run_if_release run_no_release eval );
221  
222 57 @res;
223 12 };
224  
225 12 my $path_separator = (File::Spec->catfile(qw(a b)) =~ m/^a(.+?)b$/)[0];
226  
227 70 ▶sub build_formatter {
Subroutine build_formatter: called CC=4 SCAR=13.9
Pod undocumented
228 70 my ( $self, $params ) = @_;
229  
230 70 require String::Formatter;
231 70 String::Formatter->VERSION(0.102082);
232  
233 my $codes = {
234 # not always available
235 # explicitly pass a string (not an object) [rt-72008]
236 26 ▶ a => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
237 26 ▶ return "$params->{archive}" if defined $params->{archive};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"archive"} 14 12 26
238 12 $self->log('attempting to use %a in a non-Release plugin');
239 12 '';
240 },
241  
242 # source dir
243 64 ▶ o => sub {
Subroutine __ANON__: called CC=3 SCAR=11.7
244 64 ▶ my $dir = $params->{source_dir} || $self->zilla->root;
Condition66%2/3
$params->{'source_dir'} || $self->zilla->root
l!l&&r!l&&!r
2620
MC/DC0%0/2
$params->{'source_dir'} || $self->zilla->root
$params->{'source_dir'} $self->zilla->root
Truth table66%2/3
A || B
A= $params->{'source_dir'}B= $self->zilla->root
ABresult
1X1
011
000
245 64 ▶ return $dir ? "$dir" : '';
Branch: 1 branch
BranchTrueFalseTotal
$dir ? : 64 0 64
246 },
247  
248 # build dir or mint dir
249 36 ▶ d => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
250 36 require Path::Tiny;
251 # stringify build directory
252 36 ▶ my $dir = $params->{dir} || $self->zilla->built_in;
Condition100%3/3
$params->{'dir'} || $self->zilla->built_in
l!l&&r!l&&!r
12204
MC/DC100%2/2
$params->{'dir'} || $self->zilla->built_in
$params->{'dir'} $self->zilla->built_in
Truth table100%3/3
A || B
A= $params->{'dir'}B= $self->zilla->built_in
ABresult
1X1
011
000
253 36 ▶ return Path::Tiny::path($dir)->canonpath if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 32 4 36
254 4 $self->log('attempting to use %d in before_build');
255 4 '';
256 },
257  
258 # distribution name
259 30 ▶ n => sub { $self->zilla->name },
Subroutine __ANON__: called CC=1 SCAR=0.0
260  
261 # backward compatibility (don't error)
262 s => '',
263  
264 # portability
265 p => $path_separator,
266 58 ▶ x => sub { $self->perlpath },
Subroutine __ANON__: called CC=1 SCAR=0.0
267 70 };
268  
269 # available during build, not mint
270 70 ▶ unless( $params->{minting} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"minting"}) 68 2 70
271 68 ▶ $codes->{v} = sub { $self->zilla->version };
Subroutine __ANON__: called CC=1 SCAR=0.0
272 68 ▶ $codes->{t} = sub { $self->_is_trial ? '-TRIAL' : '' };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_trial ? : 9 9 18
273 }
274  
275 # positional replacement of %s (backward compatible)
276 70 ▶ if( my @pos = @{ $params->{pos} || [] } ){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@pos) = @{$params->{"pos"} or [];}) 61 9 70
Condition100%2/2
$params->{'pos'} || []
l!l
619
MC/DC100%1/1
$params->{'pos'} || []
$params->{'pos'}
Truth table100%2/2
A
A= $params->{'pos'}
Aresult
11
00
277 # where are you defined-or // operator?
278 41 ▶ $codes->{s} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
279 41 my $s = shift(@pos);
280 41 ▶ $s = $s->() if ref $s eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $s eq "CODE" 12 29 41
281 41 ▶ defined($s) ? $s : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $s ? : 37 4 41
282 61 };
283 }
284  
285 70 return String::Formatter->new({ codes => $codes });
286 }
287  
288 37 ▶sub current_perl_path { $^X }
Subroutine current_perl_path: called CC=1 SCAR=0.0
Pod undocumented
289  
290 12 1;
↑ Summary blib/lib/Dist/Zilla/Plugin/Run/Clean.pm »