blib/lib/Dist/Zilla/Plugin/PromptIfStale.pm

filter: Statementstmt 97.9% 236 / 241 Branchbran 71.8% 79 / 110 Conditioncond 70.6% 41 / 58 MC/DCmcdc 48.2% 14 / 29 Subroutinesub 96.0% 49 / 51 Podpod 16.6% 1 / 6 totaltotal 84.8% 420 / 495 CC 78 SCAR 19.1
CC
78
Cov
87%
stale_modules
13.0
_check_modules
12.9
__ANON__
12.0
CRAP 6.8
« blib/lib/Dist/Zilla/App/Command/stale.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/EnsureNotStale.pm »
1 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::PromptIfStale; # git description: v0.059-2-g70a5978
4 # vim: set ts=8 sts=2 sw=2 tw=115 et :
5 # ABSTRACT: Check at build/release time if modules are out of date
6 # KEYWORDS: prerequisites upstream dependencies modules metadata update stale
7  
8 27 our $VERSION = '0.060';
9  
10 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 with 'Dist::Zilla::Role::BeforeBuild',
12 'Dist::Zilla::Role::AfterBuild',
13 'Dist::Zilla::Role::BeforeRelease';
14  
15 27 ▶use Moose::Util::TypeConstraints 'enum';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 27 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 27 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 27 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 27 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 27 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 27 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 27 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 27 ▶use List::Util 1.45 qw(none any uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 27 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 27 ▶use Moose::Util 'find_meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 27 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 27 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 27 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 27 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 27 ▶use Module::Metadata 1.000023;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 27 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 41 ▶sub mvp_multivalue_args { qw(modules skip) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
35 41 ▶sub mvp_aliases { {
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
36 41 module => 'modules',
37 check_all => 'check_all_plugins',
38 } }
39  
40 27 has phase => (
41 is => 'ro',
42 isa => enum([qw(build release)]),
43 default => 'release',
44 );
45  
46 has modules => (
47 isa => 'ArrayRef[Str]',
48 traits => [ 'Array' ],
49 handles => { _raw_modules => 'elements' },
50 lazy => 1,
51 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 27 );
53  
54 27 has check_authordeps => (
55 is => 'ro', isa => 'Bool',
56 default => 0,
57 );
58  
59 27 has check_all_plugins => (
60 is => 'ro', isa => 'Bool',
61 default => 0,
62 );
63  
64 27 has check_all_prereqs => (
65 is => 'ro', isa => 'Bool',
66 default => 0,
67 );
68  
69 has skip => (
70 isa => 'ArrayRef[Str]',
71 traits => [ 'Array' ],
72 handles => { skip => 'elements' },
73 lazy => 1,
74 34 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 27 );
76  
77 27 has fatal => (
78 is => 'ro', isa => 'Bool',
79 default => 0,
80 );
81  
82 27 has index_base_url => (
83 is => 'ro', isa => 'Str',
84 );
85  
86 27 has run_under_travis => (
87 is => 'ro', isa => 'Bool',
88 default => 0,
89 );
90  
91 0 ▶around dump_config => sub ($orig, $self) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
92 0 my $config = $self->$orig;
93  
94 0 ▶ $config->{+__PACKAGE__} = {
Branch: 2 branches
BranchTrueFalseTotal
$self->$_ ? : 0 0 0
builtin::blessed($self) ne __PACKAGE__ ? : 0 0 0
95 (map +($_ => $self->$_ ? 1 : 0), qw(check_all_plugins check_all_prereqs run_under_travis)),
96 phase => $self->phase,
97 skip => [ sort $self->skip ],
98 modules => [ sort $self->_raw_modules ],
99 blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
100 };
101  
102 0 return $config;
103 27 };
104  
105 26 ▶sub before_build ($self) {
Subroutine before_build: called CC=11 SCAR=24.0
Pod undocumented
106 26 ▶ if (not $ENV{PROMPTIFSTALE_REALLY_RUN_TESTS}
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis) 1 25 26
Condition83%5/6
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis
!ll&&!rl&&r
2411
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"}
!ll&&!rl&&r
0242
MC/DC66%2/3
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} $ENV{"CONTINUOUS_INTEGRATION"} not $self->run_under_travis
Truth table75%3/4
not(A) and B and not(C)
A= not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"}B= $ENV{"CONTINUOUS_INTEGRATION"}C= not $self->run_under_travis
ABCresult
0XX0
10X0
1100
1111
107 and $ENV{CONTINUOUS_INTEGRATION} and not $self->run_under_travis)
108 {
109 1 $self->log_debug('travis detected: skipping checks...');
110 1 return;
111 }
112  
113 25 ▶ if ($self->phase eq 'build')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->phase eq "build") 22 3 25
114 {
115 22 my @extra_modules = $self->_modules_extra;
116 22 ▶ my @modules = (
Branch: 2 branches
BranchTrueFalseTotal
$self->check_authordeps ? : 1 21 22
$self->check_all_plugins ? : 2 20 22
117 @extra_modules,
118 $self->check_authordeps ? $self->_authordeps : (),
119 $self->check_all_plugins ? $self->_modules_plugin : (),
120 );
121  
122 22 ▶ $self->log([ 'checking for stale %s...', join(', ',
Branch: 3 branches
BranchTrueFalseTotal
@extra_modules ? : 20 2 22
$self->check_authordeps ? : 1 21 22
$self->check_all_plugins ? : 2 20 22
123 @extra_modules ? 'modules' : (),
124 $self->check_authordeps ? 'authordeps' : (),
125 $self->check_all_plugins ? 'plugins' : ())
126 ]);
127 22 ▶ $self->_check_modules(sort(uniq(@modules))) if @modules;
Branch: 1 branch
BranchTrueFalseTotal
if @modules 21 1 22
128 }
129 }
130  
131 19 ▶sub after_build ($self, @) {
Subroutine after_build: called CC=7 SCAR=19.5
Pod undocumented
132 return if not $ENV{PROMPTIFSTALE_REALLY_RUN_TESTS}
133 19 ▶ and $ENV{CONTINUOUS_INTEGRATION} and not $self->run_under_travis;
Branch: 1 branch
BranchTrueFalseTotal
if not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis 1 18 19
Condition83%5/6
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis
!ll&&!rl&&r
1711
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"}
!ll&&!rl&&r
0172
MC/DC66%2/3
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} and $ENV{"CONTINUOUS_INTEGRATION"} and not $self->run_under_travis
not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"} $ENV{"CONTINUOUS_INTEGRATION"} not $self->run_under_travis
Truth table75%3/4
not(A) and B and not(C)
A= not $ENV{"PROMPTIFSTALE_REALLY_RUN_TESTS"}B= $ENV{"CONTINUOUS_INTEGRATION"}C= not $self->run_under_travis
ABCresult
0XX0
10X0
1100
1111
134  
135 18 ▶ if ($self->phase eq 'build' and $self->check_all_prereqs)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->phase eq "build" and $self->check_all_prereqs) 5 13 18
Condition100%3/3
$self->phase eq "build" and $self->check_all_prereqs
!ll&&!rl&&r
3105
MC/DC100%2/2
$self->phase eq "build" and $self->check_all_prereqs
$self->phase eq "build" $self->check_all_prereqs
Truth table100%3/3
A and B
A= $self->phase eq "build"B= $self->check_all_prereqs
ABresult
0X0
100
111
136 {
137 5 ▶ if (my @modules = $self->_modules_prereq) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@modules) = $self->_modules_prereq) 5 0 5
138 5 $self->log('checking for stale prerequisites...');
139 5 $self->_check_modules(sort(uniq(@modules)));
140 }
141 }
142 }
143  
144 4 ▶sub before_release ($self, @) {
Subroutine before_release: called CC=10 SCAR=24.7
Pod undocumented
145 4 ▶ if ($self->phase eq 'release')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->phase eq "release") 3 1 4
146 {
147 3 my @extra_modules = $self->_modules_extra;
148 3 ▶ my @modules = (
Branch: 3 branches
BranchTrueFalseTotal
$self->check_authordeps ? : 0 3 3
$self->check_all_plugins ? : 0 3 3
$self->check_all_prereqs ? : 1 2 3
149 @extra_modules,
150 $self->check_authordeps ? $self->_authordeps : (),
151 $self->check_all_plugins ? $self->_modules_plugin : (),
152 $self->check_all_prereqs ? $self->_modules_prereq : (),
153 );
154  
155 3 ▶ $self->log([ 'checking for stale %s...', join(', ',
Branch: 4 branches
BranchTrueFalseTotal
@extra_modules ? : 3 0 3
$self->check_authordeps ? : 0 3 3
$self->check_all_plugins ? : 0 3 3
$self->check_all_prereqs ? : 1 2 3
156 @extra_modules ? 'modules' : (),
157 $self->check_authordeps ? 'authordeps' : (),
158 $self->check_all_plugins ? 'plugins' : (),
159 $self->check_all_prereqs ? 'prerequisites' : ())
160 ]);
161  
162 3 ▶ $self->_check_modules(sort(uniq(@modules))) if @modules;
Branch: 1 branch
BranchTrueFalseTotal
if @modules 3 0 3
163 }
164 }
165  
166 # a package-scoped singleton variable that tracks the module names that have
167 # already been checked for, so other instances of this plugin do not duplicate
168 # the check.
169 25 my %already_checked;
170 33 ▶sub __clear_already_checked { %already_checked = () } # for testing
Subroutine __clear_already_checked: called CC=1 SCAR=0.0
171  
172 # module name to absolute filename where the file can be found
173 my %module_to_filename;
174  
175 54 ▶sub stale_modules ($self, @modules) {
Subroutine stale_modules: called CC=13 SCAR=25.7
Pod documented
176 54 require Module::CoreList;
177 54 Module::CoreList->VERSION('5.20151213');
178  
179 54 my $root = $self->zilla->root;
180 54 my $root_volume = path($root)->volume;
181  
182 54 my (@stale_modules, @errors);
183 54 foreach my $module (sort(uniq(@modules)))
184 {
185 199 ▶ $already_checked{$module}++ if $module eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "perl" 2 197 199
186 199 ▶ next if $already_checked{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $already_checked{$module} 11 188 199
187  
188 # these core modules should be indexed, but aren't
189 188 ▶ if (any { $module eq $_ } qw(Config DB DynaLoader Errno Pod::Functions))
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $module eq $_; } , "Config", "DB", "DynaLoader", "Errno", "Pod::Functions")) 4 184 188
190 {
191 4 $self->log_debug([ 'skipping core module: %s', $module ]);
192 4 $already_checked{$module}++;
193 4 next;
194 }
195  
196 184 my $path = do {
197 184 local @INC = @INC; push @INC, "$root";
198 184 Module::Metadata->find_module_by_name($module);
199 };
200  
201 184 ▶ if (not $path)
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 104 80 184
202 {
203 104 $already_checked{$module}++;
204 104 push @stale_modules, $module;
205 104 push @errors, $module . ' is not installed.';
206 104 next;
207 }
208  
209 80 $module_to_filename{$module} = $path;
210  
211 # ignore modules in the distribution currently being built
212 80 ▶ if (path($path)->volume eq $root_volume)
Branch: 1 branch
BranchTrueFalseTotal
if (path($path)->volume eq $root_volume) 80 0 80
213 {
214 80 my $relative_path = path($path)->relative($root);
215 80 ▶ if ($relative_path !~ m/^\.\./)
Branch: 1 branch
BranchTrueFalseTotal
unless ($relative_path =~ /^\.\./) 3 77 80
216 {
217 3 $already_checked{$module}++;
218 3 $self->log_debug([ '%s provided locally (at %s); skipping version check',
219 $module, $relative_path->stringify ]);
220 3 next;
221 }
222 }
223  
224 77 my $indexed_version = $self->_indexed_version($module, !!(@modules > 5));
225 77 my $local_version = Module::Metadata->new_from_file($module_to_filename{$module})->version;
226  
227 $self->log_debug([ 'comparing indexed vs. local version for %s: indexed=%s; local version=%s',
228 77 ▶ $module, sub { ($indexed_version // 'undef') . '' }, sub { ($local_version // 'undef') . '' } ]);
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition75%3/4
$indexed_version // "undef"
l!l
2622
$local_version // "undef"
l!l
480
MC/DC100%1/1
$indexed_version // "undef"
$indexed_version
MC/DC0%0/1
$local_version // "undef"
$local_version
Truth table100%2/2
A
A= $indexed_version
Aresult
11
00
Truth table50%1/2
A
A= $local_version
Aresult
11
00
229  
230 77 ▶ if (not defined $indexed_version)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $indexed_version) 38 39 77
231 {
232 38 $already_checked{$module}++;
233 38 push @stale_modules, $module;
234 38 push @errors, $module . ' is not indexed.';
235 38 next;
236 }
237  
238 39 ▶ if (defined $local_version
Branch: 1 branch
BranchTrueFalseTotal
if (defined $local_version and $local_version < $indexed_version) 15 24 39
Condition66%2/3
defined $local_version and $local_version < $indexed_version
!ll&&!rl&&r
02415
MC/DC50%1/2
defined $local_version and $local_version < $indexed_version
defined $local_version $local_version < $indexed_version
Truth table66%2/3
A and B
A= defined $local_versionB= $local_version < $indexed_version
ABresult
0X0
100
111
239 and $local_version < $indexed_version)
240 {
241 15 $already_checked{$module}++;
242  
243 15 ▶ if (Module::CoreList::is_core($module) and not $self->_is_duallifed($module))
Branch: 1 branch
BranchTrueFalseTotal
if (Module::CoreList::is_core($module) and not $self->_is_duallifed($module)) { } 4 11 15
Condition100%3/3
Module::CoreList::is_core($module) and not $self->_is_duallifed($module)
!ll&&!rl&&r
654
MC/DC100%2/2
Module::CoreList::is_core($module) and not $self->_is_duallifed($module)
Module::CoreList::is_core($module) not $self->_is_duallifed($module)
Truth table100%3/3
A and not(B)
A= Module::CoreList::is_core($module)B= not $self->_is_duallifed($module)
ABresult
0X0
100
111
244 {
245 $self->log_debug([ 'core module %s is indexed at version %s but you only have %s installed. You need to update your perl to get the latest version.',
246 4 ▶ $module, sub { ($indexed_version // 'undef') . '' }, sub { ($local_version // 'undef') . '' } ]);
Subroutine __ANON__: called CC=2 SCAR=7.4
Subroutine __ANON__: called CC=2 SCAR=7.4
Condition50%2/4
$indexed_version // "undef"
l!l
30
$local_version // "undef"
l!l
30
MC/DC0%0/1
$indexed_version // "undef"
$indexed_version
MC/DC0%0/1
$local_version // "undef"
$local_version
Truth table50%1/2
A
A= $indexed_version
Aresult
11
00
Truth table50%1/2
A
A= $local_version
Aresult
11
00
247 }
248 else
249 {
250 11 push @stale_modules, $module;
251 11 push @errors,
252 $module . ' is indexed at version ' . $indexed_version
253 . ' but you only have ' . $local_version . ' installed.';
254 }
255  
256 15 next;
257 }
258 }
259  
260 54 return [ sort @stale_modules ], [ sort @errors ];
261 }
262  
263 29 ▶sub _check_modules ($self, @modules) {
Subroutine _check_modules: called CC=12 SCAR=25.6
264 29 my ($stale_modules, $errors) = $self->stale_modules(@modules);
265  
266 29 ▶ return if not @$errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @$errors 7 22 29
267  
268 22 ▶ my $message = @$errors > 1
Branch: 1 branch
BranchTrueFalseTotal
@$errors > 1 ? : 11 11 22
269 ? join("\n ", 'Issues found:', @$errors)
270 : $errors->[0];
271  
272 # just issue a warning if not being run interactively (e.g. |cpanm, travis)
273 22 ▶ if (($ENV{CONTINUOUS_INTEGRATION} and not $ENV{HARNESS_ACTIVE})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CONTINUOUS_INTEGRATION"} and not $ENV{"HARNESS_ACTIVE"} or not -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))) 1 21 22
Condition53%8/15
$ENV{"CONTINUOUS_INTEGRATION"} and not $ENV{"HARNESS_ACTIVE"} or not -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
l!l&&r!l&&!r
0121
$ENV{"CONTINUOUS_INTEGRATION"} and not $ENV{"HARNESS_ACTIVE"}
!ll&&!rl&&r
2110
-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
!ll&&!rl&&r
1021
-t STDOUT or not -f STDOUT || -c STDOUT
l!l&&r!l&&!r
0210
-f STDOUT || -c STDOUT
l!l&&r!l&&!r
0021
MC/DC16%1/6
$ENV{"CONTINUOUS_INTEGRATION"} and not $ENV{"HARNESS_ACTIVE"} or not -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
$ENV{"CONTINUOUS_INTEGRATION"} not $ENV{"HARNESS_ACTIVE"} -t STDIN -t STDOUT -f STDOUT -c STDOUT
Truth table27%3/11
A and not(B) or not(C && D or not(E || F))
A= $ENV{"CONTINUOUS_INTEGRATION"}B= not $ENV{"HARNESS_ACTIVE"}C= -t STDIND= -t STDOUTE= -f STDOUTF= -c STDOUT
ABCDEFresult
11XXXX1
0X0XXX1
0X101X1
0X10011
100XXX1
10101X1
1010011
0X11XX0
0X10000
1011XX0
1010000
274 or not (-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))))
275 {
276 1 $self->log($message . "\n" . 'To remedy, do: cpanm ' . join(' ', @$stale_modules));
277 1 return;
278 }
279  
280 21 my $continue;
281 21 ▶ if ($self->fatal)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 3 18 21
282 {
283 3 $self->log($message);
284 }
285 else
286 {
287 18 ▶ $continue = $self->zilla->chrome->prompt_yn(
Branch: 1 branch
BranchTrueFalseTotal
@$errors > 1 ? : 10 8 18
288 $message . (@$errors > 1 ? "\n" : ' ') . 'Continue anyway?',
289 { default => 0 },
290 );
291 }
292  
293 21 ▶ $self->log_fatal('Aborting ' . $self->phase . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if not $continue 11 10 21
294 . 'To remedy, do: cpanm ' . join(' ', @$stale_modules)) if not $continue;
295 }
296  
297 has _authordeps => (
298 isa => 'ArrayRef[Str]',
299 traits => ['Array'],
300 handles => { _authordeps => 'elements' },
301 lazy => 1,
302 3 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
303 3 require Dist::Zilla::Util::AuthorDeps;
304 3 Dist::Zilla::Util::AuthorDeps->VERSION(5.021);
305 3 my @skip = $self->skip;
306 [
307 3 ▶ grep { my $module = $_; none { $module eq $_ } @skip }
Subroutine __ANON__: called CC=1 SCAR=0.0
308 uniq(
309 map +($_->%*)[0],
310 Dist::Zilla::Util::AuthorDeps::extract_author_deps($self->zilla->root)->@*
311 )
312 ];
313 },
314 25 );
315  
316 has _modules_plugin => (
317 isa => 'ArrayRef[Str]',
318 traits => ['Array'],
319 handles => { _modules_plugin => 'elements' },
320 lazy => 1,
321 5 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=2 SCAR=7.0
322 5 my @skip = $self->skip;
323 [
324 # we look on disk since it is too early to check $zilla->files
325 # TODO: do this properly by moving the caller to after_build
326 13 grep { (my $filename = $_) =~ s{::}{/}g; !-f "${filename}.pm" }
327 18 ▶ grep { my $module = $_; none { $module eq $_ } @skip }
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'Dist::Zilla'->VERSION('7.000') } } ? : 0 5 5
328 uniq
329 map find_meta($_)->name,
330 5 eval { Dist::Zilla->VERSION('7.000') } ? $self->zilla->plugins : $self->zilla->plugins->@*
331 ];
332 },
333 25 );
334  
335 has _modules_prereq => (
336 isa => 'ArrayRef[Str]',
337 traits => ['Array'],
338 handles => { _modules_prereq => 'elements' },
339 lazy => 1,
340 15 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
341 15 my $prereqs = $self->zilla->prereqs->as_string_hash;
342 15 my @skip = $self->skip;
343 [
344 75 ▶ grep { my $module = $_; none { $module eq $_ } @skip }
Subroutine __ANON__: called CC=1 SCAR=0.0
345 map keys $_->%*,
346 grep defined,
347 15 map $_->@{qw(requires recommends suggests)},
348 grep defined,
349 values $prereqs->%*
350 ];
351 },
352 25 );
353  
354 54 ▶sub _modules_extra ($self) {
Subroutine _modules_extra: called CC=1 SCAR=0.0
355 54 my @skip = $self->skip;
356 54 ▶ grep { my $module = $_; none { $module eq $_ } @skip } $self->_raw_modules;
Subroutine __ANON__: called CC=1 SCAR=0.0
357 }
358  
359 # this ought to be in Module::CoreList -- TODO :)
360 6 ▶sub _is_duallifed ($self, $module) {
Subroutine _is_duallifed: called CC=6 SCAR=18.8
361 6 ▶ return if not Module::CoreList::is_core($module);
Branch: 1 branch
BranchTrueFalseTotal
unless Module::CoreList::is_core($module) 0 6 6
362  
363 # Module::CoreList doesn't tell us this information at all right now - for
364 # blead-upstream dual-lifed modules, and non-dual-lifed modules, it
365 # returns all the same data points. :( Right now all we can do is query
366 # the index and see what distribution it belongs to -- luckily, it still lists the
367 # cpan distribution for dual-lifed modules that are more recent in core than on
368 # CPAN (e.g. Carp in June 2014 is 1.34 in 5.20.0 but 1.3301 on cpan).
369  
370 6 my $url = 'http://cpanmetadb.plackperl.org/v1.0/package/' . $module;
371 6 $self->log_debug([ 'fetching %s', $url ]);
372 6 my $res = HTTP::Tiny->new->get($url);
373 6 ▶ $self->log('could not query the index?'), return undef if not $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 6 6
374  
375 6 my $data = $res->{content};
376  
377 6 require HTTP::Headers;
378 6 ▶ if (my $charset = HTTP::Headers->new($res->{headers}->%*)->content_type_charset)
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = "HTTP::Headers"->new(%{$$res{"headers"}})->content_type_charset) 0 6 6
379 {
380 0 $data = Encode::decode($charset, $data, Encode::FB_CROAK);
381 }
382 6 $self->log_debug([ 'got response: %s', $data ]);
383  
384 6 my $payload = YAML::Tiny->read_string($data);
385  
386 6 ▶ $self->log('invalid payload returned?'), return undef unless $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless $payload 0 6 6
387 6 ▶ $self->log_debug([ '%s not indexed', $module ]), return undef if not defined $payload->[0]{distfile};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload->[0]{"distfile"} 0 6 6
388 6 return CPAN::DistnameInfo->new($payload->[0]{distfile})->dist ne 'perl';
389 }
390  
391 25 my $packages;
392 42 ▶sub _indexed_version ($self, $module, $combined) {
Subroutine _indexed_version: called CC=4 SCAR=13.9
393 # we download 02packages if we have several modules to query at once, or
394 # if we were given a different URL to use -- otherwise, we perform an API
395 # hit for just this one module's data
396 42 ▶ return $combined || $packages || $self->_has_index_base_url
Branch: 1 branch
BranchTrueFalseTotal
$combined || $packages || $self->_has_index_base_url ? : 34 8 42
Condition83%5/6
$combined or $packages or $self->_has_index_base_url
l!l&&r!l&&!r
3408
$combined or $packages
l!l&&r!l&&!r
3228
MC/DC66%2/3
$combined or $packages or $self->_has_index_base_url
$combined $packages $self->_has_index_base_url
Truth table75%3/4
A or B or C
A= $combinedB= $packagesC= $self->_has_index_base_url
ABCresult
1XX1
01X1
0011
0000
397 ? $self->_indexed_version_via_02packages($module)
398 : $self->_indexed_version_via_query($module);
399 }
400  
401 # I bet this is available somewhere as a module?
402 8 ▶sub _indexed_version_via_query ($self, $module) {
Subroutine _indexed_version_via_query: called CC=7 SCAR=20.6
403 8 ▶ die 'should not be here - get 02packages instead' if $self->_has_index_base_url;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_index_base_url 0 8 8
404 8 ▶ die 'no module?' if not $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 8 8
405  
406 8 my $url = 'http://cpanmetadb.plackperl.org/v1.0/package/' . $module;
407 8 $self->log_debug([ 'fetching %s', $url ]);
408 8 my $res = HTTP::Tiny->new->get($url);
409 8 ▶ $self->log('could not query the index?'), return undef if not $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 8 8
410  
411 8 my $data = $res->{content};
412  
413 8 require HTTP::Headers;
414 8 ▶ if (my $charset = HTTP::Headers->new($res->{headers}->%*)->content_type_charset)
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = "HTTP::Headers"->new(%{$$res{"headers"}})->content_type_charset) 0 8 8
415 {
416 0 $data = Encode::decode($charset, $data, Encode::FB_CROAK);
417 }
418 8 $self->log_debug([ 'got response: %s', $data ]);
419  
420 8 my $payload = YAML::Tiny->read_string($data);
421  
422 8 ▶ $self->log('invalid payload returned?'), return undef unless $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless $payload 0 8 8
423 8 ▶ $self->log_debug([ '%s not indexed', $module ]), return undef if not defined $payload->[0]{version};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload->[0]{"version"} 0 8 8
424 8 version->parse($payload->[0]{version});
425 }
426  
427 # TODO: it would be AWESOME to provide this to multiple plugins via a role
428 # even better would be to save the file somewhere semi-permanent and
429 # keep it refreshed with a Last-Modified header - or share cpanm's copy?
430 34 ▶sub _get_packages ($self) {
Subroutine _get_packages: called CC=5 SCAR=16.1
431 34 ▶ return $packages if $packages;
Branch: 1 branch
BranchTrueFalseTotal
if $packages 32 2 34
432  
433 2 my $tempdir = Path::Tiny->tempdir(CLEANUP => 1);
434 2 my $filename = '02packages.details.txt.gz';
435 2 my $path = $tempdir->child($filename);
436  
437 # We don't set this via an attribute default because we want to
438 # distinguish the case where this was not set at all.
439 2 ▶ my $base = $self->index_base_url || $ENV{CPAN_INDEX_BASE_URL} || 'http://www.cpan.org';
Condition80%4/5
$self->index_base_url || $ENV{'CPAN_INDEX_BASE_URL'} || 'http://www.cpan.org'
l!l
11
$self->index_base_url or $ENV{"CPAN_INDEX_BASE_URL"}
l!l&&r!l&&!r
101
MC/DC50%1/2
$self->index_base_url || $ENV{'CPAN_INDEX_BASE_URL'} || 'http://www.cpan.org'
$self->index_base_url $ENV{"CPAN_INDEX_BASE_URL"}
Truth table66%2/3
A or B
A= $self->index_base_urlB= $ENV{"CPAN_INDEX_BASE_URL"}
ABresult
1X1
011
000
440  
441 2 my $url = $base . '/modules/' . $filename;
442 2 $self->log_debug([ 'fetching %s', $url ]);
443 2 my $response = HTTP::Tiny->new->mirror($url, $path);
444 2 ▶ $self->log('could not fetch the index - network down?'), return undef if not $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 2 2
445  
446 2 require Parse::CPAN::Packages::Fast;
447 2 $packages = Parse::CPAN::Packages::Fast->new($path->stringify);
448 }
449  
450 16 ▶sub _has_index_base_url ($self) {
Subroutine _has_index_base_url: called CC=2 SCAR=9.2
451 16 ▶ return $self->index_base_url || $ENV{CPAN_INDEX_BASE_URL};
Condition33%1/3
$self->index_base_url || $ENV{'CPAN_INDEX_BASE_URL'}
l!l&&r!l&&!r
0016
MC/DC0%0/2
$self->index_base_url || $ENV{'CPAN_INDEX_BASE_URL'}
$self->index_base_url $ENV{'CPAN_INDEX_BASE_URL'}
Truth table33%1/3
A || B
A= $self->index_base_urlB= $ENV{'CPAN_INDEX_BASE_URL'}
ABresult
1X1
011
000
452 }
453  
454 0 ▶sub _indexed_version_via_02packages ($self, $module) {
Subroutine _indexed_version_via_02packages: not called CC=4 SCAR=17.9
455 2 ▶ die 'no module?' if not $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
456 2 my $packages = $self->_get_packages;
457 2 ▶ return undef if not $packages;
Branch: 1 branch
BranchTrueFalseTotal
unless $packages 0 0 0
458 2 my $package = $packages->package($module);
459 2 ▶ return undef if not $package;
Branch: 1 branch
BranchTrueFalseTotal
unless $package 0 0 0
460 2 version->parse($package->version);
461 }
462  
463 25 __PACKAGE__->meta->make_immutable;
464  
465 __END__
« blib/lib/Dist/Zilla/App/Command/stale.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/EnsureNotStale.pm »