blib/lib/Dist/Zilla/Plugin/Prereqs/MatchInstalled.pm

filter: Statementstmt 94.7% 90 / 95 Branchbran 61.1% 11 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 94.7% 18 / 19 Podpod 100% 4 / 4 totaltotal 89.2% 124 / 139 CC 16 SCAR 13.3
CC
16
Cov
89%
register_prereqs
8.2
current_version_of
5.6
_build__applyto_list
3.1
CRAP 3.8
↑ Summary
1 2 ▶use 5.008; # 8 = utf8, 6 = pragmas , our, noparam varmethod, 4 = __PACKAGE__
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Dist::Zilla::Plugin::Prereqs::MatchInstalled;
7  
8 2 our $VERSION = '1.001003';
9  
10 # ABSTRACT: Depend on versions of modules the same as you have installed
11  
12 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13  
14 2 ▶use Moose qw( has around with );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use MooseX::Types::Moose qw( HashRef ArrayRef Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 with 'Dist::Zilla::Role::PrereqSource';
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44 has applyto_phase => (
45 is => ro =>,
46 isa => ArrayRef [Str] =>,
47 lazy => 1,
48 1 ▶ default => sub { [qw(build test runtime configure develop)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 2 );
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64 has applyto_relation => (
65 is => 'ro',
66 isa => ArrayRef [Str],
67 lazy => 1,
68 1 ▶ default => sub { [qw(requires recommends suggests)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
69 2 );
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83 2 has applyto => (
84 is => ro =>,
85 isa => ArrayRef [Str] =>,
86 lazy => 1,
87 builder => _build_applyto =>,
88 );
89  
90  
91  
92  
93  
94  
95  
96  
97  
98 2 has _applyto_list => (
99 is => ro =>,
100 isa => ArrayRef [ ArrayRef [Str] ],
101 lazy => 1,
102 builder => _build__applyto_list =>,
103 );
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119 has modules => (
120 is => ro =>,
121 isa => ArrayRef [Str],
122 lazy => 1,
123 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 2 );
125  
126  
127  
128  
129  
130  
131  
132 2 has _modules_hash => (
133 is => ro =>,
134 isa => HashRef,
135 lazy => 1,
136 builder => _build__modules_hash =>,
137 );
138  
139  
140  
141  
142  
143 1 ▶sub _build_applyto {
Subroutine _build_applyto: called CC=3 SCAR=11.0
144 1 my $self = shift;
145 1 my @out;
146 1 for my $phase ( @{ $self->applyto_phase } ) {
147 5 for my $relation ( @{ $self->applyto_relation } ) {
148 15 push @out, $phase . q[.] . $relation;
149 }
150 }
151 1 return \@out;
152 }
153  
154  
155  
156  
157  
158 1 ▶sub _build__applyto_list {
Subroutine _build__applyto_list: called CC=3 SCAR=11.2
159 1 my $self = shift;
160 1 my @out;
161 1 for my $type ( @{ $self->applyto } ) {
162 15 ▶ if ( $type =~ /^ ([^.]+) [.] ([^.]+) $/msx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^ ([^.]+) [.] ([^.]+) $/msx) 15 0 15
163 15 push @out, [ "$1", "$2" ];
164 15 next;
165 }
166 0 return $self->log_fatal( [ q[<<%s>> does not match << <phase>.<relation> >>], $type ] );
167 }
168 1 return \@out;
169 }
170  
171  
172  
173  
174  
175 1 ▶sub _build__modules_hash {
Subroutine _build__modules_hash: called CC=1 SCAR=0.0
176 1 my $self = shift;
177 1 return { map { ( $_, 1 ) } @{ $self->modules } };
178 }
179  
180  
181  
182  
183  
184 1 ▶sub _user_wants_upgrade_on {
Subroutine _user_wants_upgrade_on: called CC=1 SCAR=0.0
185 1 my ( $self, $module ) = @_;
186 1 return exists $self->_modules_hash->{$module};
187 }
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207 1 ▶sub mvp_multivalue_args { return qw(applyto applyto_relation applyto_phase modules) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod documented
208  
209  
210  
211  
212  
213  
214  
215 1 ▶sub mvp_aliases { return { 'module' => 'modules' } }
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod documented
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227 1 ▶sub current_version_of {
Subroutine current_version_of: called CC=5 SCAR=17.3
Pod documented
228 1 my ( undef, $package ) = @_;
229 1 ▶ if ( 'perl' eq $package ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("perl" eq $package) 0 1 1
230  
231 # Thats not going to work, Dave.
232 0 return $];
233 }
234 1 require Module::Data;
235 1 my $module_data = Module::Data->new($package);
236 1 ▶ return if not $module_data;
Branch: 1 branch
BranchTrueFalseTotal
unless $module_data 0 1 1
237 1 ▶ return if not -e $module_data->path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $module_data->path 0 1 1
238 1 ▶ return if -d $module_data->path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $module_data->path 0 1 1
239 1 return $module_data->_version_emulate;
240 }
241 2 around dump_config => config_dumper( __PACKAGE__, qw( applyto_phase applyto_relation applyto modules ) );
242  
243  
244  
245  
246  
247  
248  
249  
250 1 ▶sub register_prereqs {
Subroutine register_prereqs: called CC=8 SCAR=21.1
Pod documented
251 1 my ($self) = @_;
252 1 my $zilla = $self->zilla;
253 1 my $prereqs = $zilla->prereqs;
254 1 ▶ my $guts = $prereqs->cpan_meta_prereqs->{prereqs} || {};
Condition50%1/2
$prereqs->cpan_meta_prereqs->{'prereqs'} || {}
l!l
10
MC/DC0%0/1
$prereqs->cpan_meta_prereqs->{'prereqs'} || {}
$prereqs->cpan_meta_prereqs->{'prereqs'}
Truth table50%1/2
A
A= $prereqs->cpan_meta_prereqs->{'prereqs'}
Aresult
11
00
255  
256 1 my $failmsg = q[];
257 1 $failmsg .= q[You asked for the installed version of %s, ];
258 1 $failmsg .= q[and it is a dependency but it is apparently not installed];
259 1 for my $applyto ( @{ $self->_applyto_list } ) {
260 15 my ( $phase, $rel ) = @{$applyto};
261 15 ▶ next if not exists $guts->{$phase};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $guts->{$phase} 12 3 15
262 3 ▶ next if not exists $guts->{$phase}->{$rel};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $guts->{$phase}{$rel} 2 1 3
263 1 my $reqs = $guts->{$phase}->{$rel}->as_string_hash;
264 1 for my $module ( keys %{$reqs} ) {
265 1 ▶ next unless $self->_user_wants_upgrade_on($module);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_user_wants_upgrade_on($module) 0 1 1
266 1 my $latest = $self->current_version_of($module);
267 1 ▶ if ( not defined $latest ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $latest) 0 1 1
268 0 $self->log( [ $failmsg, $module ] );
269 0 next;
270 }
271 1 $zilla->register_prereqs( { phase => $phase, type => $rel }, $module, $latest );
272 }
273 }
274 1 return $prereqs;
275 }
276 2 __PACKAGE__->meta->make_immutable;
277 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
278  
279 2 1;
280  
281 __END__
↑ Summary