blib/lib/Dist/Zilla/App/Command/stale.pm

filter: Statementstmt 97.8% 93 / 95 Branchbran 71.4% 30 / 42 Conditioncond 75.0% 21 / 28 MC/DCmcdc 50.0% 9 / 18 Subroutinesub 95.0% 19 / 20 Podpod 75.0% 3 / 4 totaltotal 84.5% 175 / 207 CC 40 SCAR 26.7
CC
40
Cov
87%
stale_modules
26.8
__ANON__
10.9
execute
5.2
CRAP 14.5
↑ Summary blib/lib/Dist/Zilla/Plugin/PromptIfStale.pm »
1 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::App::Command::stale;
4 # vim: set ts=8 sts=2 sw=2 tw=115 et :
5 # ABSTRACT: print your distribution's prerequisites and plugins that are out of date
6  
7 26 our $VERSION = '0.060';
8  
9 26 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 26 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 26 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶use Dist::Zilla::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub abstract { "print your distribution's stale prerequisites and plugins" }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
19  
20 10 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
21 10 [ 'root=s' => 'the root of the distribution; defaults to .' ],
22 [ 'all' , 'check all plugins and prerequisites, regardless of plugin configuration' ]
23 # TODO?
24 # [ 'plugins', 'check all plugins' ],
25 # [ 'prereqs', 'check all prerequisites' ],
26 }
27  
28 28 ▶sub stale_modules ($self, $zilla, $all = undef) {
Subroutine stale_modules: called CC=26 SCAR=32.9
Pod undocumented
29 28 my $dzil7 = eval { Dist::Zilla::App->VERSION('7.000') };
30  
31 28 ▶ my @plugins = grep $_->isa('Dist::Zilla::Plugin::PromptIfStale'),
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 28 28
32 $dzil7 ? $zilla->plugins : $zilla->plugins->@*;
33  
34 28 ▶ if (not @plugins)
Branch: 1 branch
BranchTrueFalseTotal
unless (@plugins) 3 25 28
35 {
36 3 require Dist::Zilla::Plugin::PromptIfStale;
37 3 push @plugins,
38 Dist::Zilla::Plugin::PromptIfStale->new(zilla => $zilla, plugin_name => 'stale_command');
39 }
40  
41 28 my @modules;
42  
43 # ugh, we need to do nearly a full build to get the prereqs
44 # (this really should be abstracted better in Dist::Zilla::Dist::Builder)
45 28 ▶ if ($all or do { require List::Util; List::Util->VERSION('1.33'); List::Util::any(sub { $_->check_all_prereqs }, @plugins) })
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if ($all or do { require List::Util; "List::Util"->VERSION("1.33"); &List::Util::any(sub { $_->check_all_prereqs; } , @plugins) }) 10 18 28
Condition100%3/3
$all or do { require List::Util; "List::Util"->VERSION("1.33"); &List::Util::any(sub { $_->check_all_prereqs; } , @plugins) }
l!l&&r!l&&!r
2818
MC/DC100%2/2
$all or do { require List::Util; "List::Util"->VERSION("1.33"); &List::Util::any(sub { $_->check_all_prereqs; } , @plugins) }
$all do { require List::Util; "List::Util"->VERSION("1.33"); &List::Util::any(sub { $_->check_all_prereqs; } , @plugins) }
Truth table100%3/3
A or B
A= $allB= do { require List::Util; "List::Util"->VERSION("1.33"); &List::Util::any(sub { $_->check_all_prereqs; } , @plugins) }
ABresult
1X1
011
000
46 {
47 10 ▶ $_->before_build for grep !$_->isa('Dist::Zilla::Plugin::PromptIfStale'),
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 10 10
48 $dzil7 ? $zilla->plugins_with(-BeforeBuild) : $zilla->plugins_with(-BeforeBuild)->@*;
49 9 ▶ $_->gather_files for $dzil7 ? $zilla->plugins_with(-FileGatherer) : $zilla->plugins_with(-FileGatherer)->@*;
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 9 9
50 9 ▶ $_->set_file_encodings for $dzil7 ? $zilla->plugins_with(-EncodingProvider) : $zilla->plugins_with(-EncodingProvider)->@*;
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 9 9
51 9 ▶ $_->prune_files for $dzil7 ? $zilla->plugins_with(-FilePruner) : $zilla->plugins_with(-FilePruner)->@*;
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 9 9
52 9 ▶ $_->munge_files for $dzil7 ? $zilla->plugins_with(-FileMunger) : $zilla->plugins_with(-FileMunger)->@*;
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 9 9
53 9 ▶ $_->register_prereqs for $dzil7 ? $zilla->plugins_with(-PrereqSource) : $zilla->plugins_with(-PrereqSource)->@*;
Branch: 1 branch
BranchTrueFalseTotal
$dzil7 ? : 0 9 9
54  
55 9 ▶ push @modules, map
Branch: 1 branch
BranchTrueFalseTotal
$all || $_->check_all_prereqs ? : 9 2 11
Condition100%3/3
$all or $_->check_all_prereqs
l!l&&r!l&&!r
182
MC/DC100%2/2
$all or $_->check_all_prereqs
$all $_->check_all_prereqs
Truth table100%3/3
A or B
A= $allB= $_->check_all_prereqs
ABresult
1X1
011
000
56 $all || $_->check_all_prereqs ? $_->_modules_prereq : (),
57 @plugins;
58 }
59  
60 27 foreach my $plugin (@plugins)
61 {
62 29 ▶ push @modules,
Branch: 2 branches
BranchTrueFalseTotal
$all || $plugin->check_authordeps ? : 3 26 29
$all || $plugin->check_all_plugins ? : 4 25 29
Condition100%6/6
$all or $plugin->check_authordeps
l!l&&r!l&&!r
1226
$all or $plugin->check_all_plugins
l!l&&r!l&&!r
1325
MC/DC100%2/2
$all or $plugin->check_authordeps
$all $plugin->check_authordeps
MC/DC100%2/2
$all or $plugin->check_all_plugins
$all $plugin->check_all_plugins
Truth table100%3/3
A or B
A= $allB= $plugin->check_authordeps
ABresult
1X1
011
000
Truth table100%3/3
A or B
A= $allB= $plugin->check_all_plugins
ABresult
1X1
011
000
63 ( $all || $plugin->check_authordeps ? $plugin->_authordeps : () ),
64 $plugin->_modules_extra,
65 ( $all || $plugin->check_all_plugins ? $plugin->_modules_plugin : () );
66 }
67  
68 27 ▶ return if not @modules;
Branch: 1 branch
BranchTrueFalseTotal
unless @modules 2 25 27
69  
70 25 require List::Util; List::Util->VERSION(1.45);
71 25 my ($stale_modules, undef) = $plugins[0]->stale_modules(List::Util::uniq(@modules));
72 25 return @$stale_modules;
73 }
74  
75 10 ▶sub execute ($self, $opt, @) {
Subroutine execute: called CC=5 SCAR=16.5
Pod documented
76 10 ▶ $self->app->chrome->logger->mute unless $self->app->global_options->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->app->global_options->verbose 10 0 10
77  
78 10 require Try::Tiny;
79 10 ▶ my $zilla = Try::Tiny::try {
Subroutine __ANON__: called CC=1 SCAR=0.0
80 # parse dist.ini and load, instantiate all plugins
81 10 $self->zilla;
82 }
83 6 ▶ Try::Tiny::catch {
Subroutine __ANON__: called CC=10 SCAR=23.9
84 6 my @authordeps;
85  
86 # a plugin or bundle tried to loads another module that isn't installed
87 6 ▶ if (/^Can't locate (\S+) .+ at \S+ line/
Branch: 2 branches
BranchTrueFalseTotal
if (/^Can't locate (\S+) .+ at \S+ line/ or /^Compilation failed in require at (\S+) line/) { } 2 4 6
elsif (/^(\S+) version \S+ required--this is only version \S+ at \S+ line/) { } 1 3 4
Condition66%2/3
/^Can't locate (\S+) .+ at \S+ line/ or /^Compilation failed in require at (\S+) line/
l!l&&r!l&&!r
204
MC/DC50%1/2
/^Can't locate (\S+) .+ at \S+ line/ or /^Compilation failed in require at (\S+) line/
/^Can't locate (\S+) .+ at \S+ line/ /^Compilation failed in require at (\S+) line/
Truth table66%2/3
A or B
A= /^Can't locate (\S+) .+ at \S+ line/B= /^Compilation failed in require at (\S+) line/
ABresult
1X1
011
000
88 or /^Compilation failed in require at (\S+) line/)
89 {
90 2 ▶ my $module = $1 || $2;
Condition33%1/3
$1 || $2
l!l&&r!l&&!r
200
MC/DC0%0/2
$1 || $2
$1 $2
Truth table33%1/3
A || B
A= $1B= $2
ABresult
1X1
011
000
91 2 $module =~ s{/}{::}g;
92 2 $module =~ s{\.pm$}{};
93 2 push @authordeps, $module;
94 }
95 # ...or at the wrong version
96 elsif (/^(\S+) version \S+ required--this is only version \S+ at \S+ line/)
97 {
98 1 push @authordeps, $1;
99 }
100 else
101 {
102 # a plugin was referenced in dist.ini or a bundle
103 3 ▶ push @authordeps, $1 if /Required plugin(?: bundle)? \[?(\S+)\]? isn't installed\./;
Branch: 1 branch
BranchTrueFalseTotal
if /Required plugin(?: bundle)? \[?(\S+)\]? isn't installed\./ 2 1 3
104  
105 # some plugins are not installed; need to run authordeps --missing
106 3 ▶ die $_ unless
Branch: 1 branch
BranchTrueFalseTotal
unless /Run 'dzil authordeps' to see a list of all required plugins/m or / version \(.+\) (does )?not match required version: /m 0 3 3
Condition66%2/3
/Run 'dzil authordeps' to see a list of all required plugins/m or / version \(.+\) (does )?not match required version: /m
l!l&&r!l&&!r
210
MC/DC0%0/2
/Run 'dzil authordeps' to see a list of all required plugins/m or / version \(.+\) (does )?not match required version: /m
/Run 'dzil authordeps' to see a list of all required plugins/m / version \(.+\) (does )?not match required version: /m
Truth table66%2/3
A or B
A= /Run 'dzil authordeps' to see a list of all required plugins/mB= / version \(.+\) (does )?not match required version: /m
ABresult
1X1
011
000
107 m/Run 'dzil authordeps' to see a list of all required plugins/m
108 or m/ version \(.+\) (does )?not match required version: /m;
109 }
110  
111 6 ▶ push @authordeps, $self->_missing_authordeps($opt->root // '.');
Condition50%1/2
$opt->root // "."
l!l
06
MC/DC0%0/1
$opt->root // "."
$opt->root
Truth table50%1/2
A
A= $opt->root
Aresult
11
00
112  
113 6 $self->app->chrome->logger->unmute;
114 6 $self->log(join("\n", sort(List::Util::uniq(@authordeps))));
115  
116 6 ▶ if (@authordeps)
Branch: 1 branch
BranchTrueFalseTotal
if (@authordeps) 6 0 6
117 {
118 6 require Term::ANSIColor;
119 6 Term::ANSIColor->VERSION('3.00');
120 6 print STDERR Term::ANSIColor::colored("Some authordeps were missing. Run the stale command again to check for regular dependencies.\n", 'bright_yellow');
121 6 exit 1;
122 }
123  
124 0 undef; # ensure $zilla = undef
125 10 };
126  
127 4 ▶ exit 2 if not $zilla;
Branch: 1 branch
BranchTrueFalseTotal
unless $zilla 0 4 4
128  
129 4 my $error;
130 4 ▶ my @stale_modules = Try::Tiny::try {
Subroutine __ANON__: called CC=1 SCAR=0.0
131 4 $self->stale_modules($zilla, $opt->all);
132 }
133 1 ▶ Try::Tiny::catch {
Subroutine __ANON__: called CC=2 SCAR=7.2
134 1 $error = $_;
135  
136 # if there was an error during the build, fall back to fetching
137 # authordeps, in the hopes that we can report something helpful
138 1 ▶ $self->_missing_authordeps($opt->root // '.');
Condition50%1/2
$opt->root // "."
l!l
01
MC/DC0%0/1
$opt->root // "."
$opt->root
Truth table50%1/2
A
A= $opt->root
Aresult
11
00
139 4 };
140  
141 4 $self->app->chrome->logger->unmute;
142 4 $self->log(join("\n", @stale_modules)); # this might be just a blank line
143 4 ▶ $self->log([ 'got error from stale_modules check: %s', $error ]) if $error and not @stale_modules;
Branch: 1 branch
BranchTrueFalseTotal
if $error and not @stale_modules 0 4 4
Condition66%2/3
$error and not @stale_modules
!ll&&!rl&&r
310
MC/DC0%0/2
$error and not @stale_modules
$error not @stale_modules
Truth table66%2/3
A and not(B)
A= $errorB= not @stale_modules
ABresult
0X0
100
111
144 }
145  
146 # as in Dist::Zilla::App::Command::alldeps
147 7 ▶sub _missing_authordeps ($self, $root) {
Subroutine _missing_authordeps: called CC=1 SCAR=0.0
148 7 require Dist::Zilla::Util::AuthorDeps;
149 7 Dist::Zilla::Util::AuthorDeps->VERSION(5.021);
150 7 my @authordeps = map +($_->%*)[0],
151 Dist::Zilla::Util::AuthorDeps::extract_author_deps(
152 $root, # repository root
153 1, # --missing
154 )
155 ->@*;
156 }
157  
158 26 1;
159  
160 __END__
↑ Summary blib/lib/Dist/Zilla/Plugin/PromptIfStale.pm »