lib/CPANPLUS/Dist.pm

filter: Statementstmt 90.2% 269 / 298 Branchbran 68.1% 75 / 110 Conditioncond 67.3% 33 / 49 MC/DCmcdc 40.7% 11 / 27 Subroutinesub 100% 26 / 26 Podpod 85.7% 6 / 7 totaltotal 81.2% 420 / 517 CC 84 SCAR 31.9
CC
84
Cov
82%
_resolve_prereqs
55.2
_prereqs_from_meta_json
8.7
_stash_metadata
8.5
CRAP 24.2
« blib/lib/CPANPLUS/Internals.pm ↑ Summary lib/CPANPLUS/Internals/Fetch.pm »
1 package CPANPLUS::Dist;
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use CPANPLUS::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use CPANPLUS::Internals::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use Object::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use Parse::CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 ▶use IPC::Cmd qw[run];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use Params::Check qw[check];
Subroutine BEGIN: called CC=1 SCAR=0.0
14 20 ▶use Module::Load::Conditional qw[can_load check_install];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 20 ▶use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 20 ▶use vars qw[$VERSION];
Subroutine BEGIN: called CC=1 SCAR=0.0
18 20 $VERSION = "0.9914";
19  
20 20 ▶use base 'Object::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 20 local $Params::Check::VERBOSE = 1;
23  
24 =pod
25  
26 =head1 NAME
27  
28 CPANPLUS::Dist - base class for plugins
29  
30 =head1 SYNOPSIS
31  
32 my $dist = CPANPLUS::Dist::YOUR_DIST_TYPE_HERE->new(
33 module => $modobj,
34 );
35  
36 =head1 DESCRIPTION
37  
38 C<CPANPLUS::Dist> is a base class for C<CPANPLUS::Dist::MM>
39 and C<CPANPLUS::Dist::Build>. Developers of other C<CPANPLUS::Dist::*>
40 plugins should look at C<CPANPLUS::Dist::Base>.
41  
42 =head1 ACCESSORS
43  
44 =over 4
45  
46 =item parent()
47  
48 Returns the C<CPANPLUS::Module> object that parented this object.
49  
50 =item status()
51  
52 Returns the C<Object::Accessor> object that keeps the status for
53 this module.
54  
55 =back
56  
57 =head1 STATUS ACCESSORS
58  
59 All accessors can be accessed as follows:
60 $deb->status->ACCESSOR
61  
62 =over 4
63  
64 =item created()
65  
66 Boolean indicating whether the dist was created successfully.
67 Explicitly set to C<0> when failed, so a value of C<undef> may be
68 interpreted as C<not yet attempted>.
69  
70 =item installed()
71  
72 Boolean indicating whether the dist was installed successfully.
73 Explicitly set to C<0> when failed, so a value of C<undef> may be
74 interpreted as C<not yet attempted>.
75  
76 =item uninstalled()
77  
78 Boolean indicating whether the dist was uninstalled successfully.
79 Explicitly set to C<0> when failed, so a value of C<undef> may be
80 interpreted as C<not yet attempted>.
81  
82 =item dist()
83  
84 The location of the final distribution. This may be a file or
85 directory, depending on how your distribution plug in of choice
86 works. This will be set upon a successful create.
87  
88 =cut
89  
90 =back
91  
92 =head2 $dist = CPANPLUS::Dist::YOUR_DIST_TYPE_HERE->new( module => MODOBJ );
93  
94 Create a new C<CPANPLUS::Dist::YOUR_DIST_TYPE_HERE> object based on the
95 provided C<MODOBJ>.
96  
97 *** DEPRECATED ***
98 The optional argument C<format> is used to indicate what type of dist
99 you would like to create (like C<CPANPLUS::Dist::MM> or
100 C<CPANPLUS::Dist::Build> and so on ).
101  
102 C<< CPANPLUS::Dist->new >> is exclusively meant as a method to be
103 inherited by C<CPANPLUS::Dist::MM|Build>.
104  
105 Returns a C<CPANPLUS::Dist::YOUR_DIST_TYPE_HERE> object on success
106 and false on failure.
107  
108 =cut
109  
110 sub new {
111 44 ▶ my $self = shift;
Subroutine new: called CC=7 SCAR=19.7
Pod documented
112 44 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0440
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
113 44 my %hash = @_;
114  
115 ### first verify we got a module object ###
116 44 my( $mod, $format );
117 44 my $tmpl = {
118 module => { required => 1, allow => IS_MODOBJ, store => \$mod },
119 ### for backwards compatibility
120 format => { default => $class, store => \$format,
121 allow => [ __PACKAGE__->dist_types ],
122 },
123 };
124 44 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 44 44
125  
126 44 ▶ unless( can_load( modules => { $format => '0.0' }, verbose => 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (can_load("modules", {$format, "0.0"}, "verbose", 1)) 0 44 44
127 0 error(loc("'%1' not found -- you need '%2' version '%3' or higher ".
128 "to detect plugins", $format, 'Module::Pluggable','2.4'));
129 0 return;
130 }
131  
132 ### get an empty o::a object for this class
133 44 my $obj = $format->SUPER::new;
134  
135 44 $obj->mk_accessors( qw[parent status] );
136  
137 ### set the parent
138 44 $obj->parent( $mod );
139  
140 ### create a status object ###
141 44 { my $acc = Object::Accessor->new;
142 44 $obj->status($acc);
143  
144 ### add minimum supported accessors
145 44 $acc->mk_accessors( qw[prepared created installed uninstalled
146 distdir dist _metadata] );
147 }
148  
149 ### get the conf object ###
150 44 my $conf = $mod->parent->configure_object();
151  
152 ### check if the format is available in this environment ###
153 44 ▶ if( $conf->_get_build('sanity_check') and not $obj->format_available ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->_get_build("sanity_check") and not $obj->format_available) 1 43 44
Condition100%3/3
$conf->_get_build("sanity_check") and not $obj->format_available
!ll&&!rl&&r
1421
MC/DC100%2/2
$conf->_get_build("sanity_check") and not $obj->format_available
$conf->_get_build("sanity_check") not $obj->format_available
Truth table100%3/3
A and not(B)
A= $conf->_get_build("sanity_check")B= not $obj->format_available
ABresult
0X0
100
111
154 1 error( loc( "Format '%1' is not available", $format) );
155 1 return;
156 }
157  
158 ### now initialize it or admit failure
159 43 ▶ unless( $obj->init ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->init) 1 42 43
160 1 error(loc("Dist initialization of '%1' failed for '%2'",
161 $format, $mod->module));
162 1 return;
163 }
164  
165 ### return the object
166 42 return $obj;
167 }
168  
169 =head2 @dists = CPANPLUS::Dist->dist_types;
170  
171 Returns a list of the CPANPLUS::Dist::* classes available
172  
173 =cut
174  
175 ### returns a list of dist_types we support
176 ### will get overridden by Module::Pluggable if loaded
177 ### XXX add support for 'plugin' dir in config as well
178 20 { my $Loaded;
179 20 my @Dists = (INSTALLER_MM);
180 20 my @Ignore = ();
181  
182 ### backdoor method to add more dist types
183 1 ▶ sub _add_dist_types { my $self = shift; push @Dists, @_ };
Subroutine _add_dist_types: called CC=1 SCAR=0.0
184  
185 ### backdoor method to exclude dist types
186 1 ▶ sub _ignore_dist_types { my $self = shift; push @Ignore, @_ };
Subroutine _ignore_dist_types: called CC=1 SCAR=0.0
187 1 ▶ sub _reset_dist_ignore { @Ignore = () };
Subroutine _reset_dist_ignore: called CC=1 SCAR=0.0
188  
189 ### locally add the plugins dir to @INC, so we can find extra plugins
190 #local @INC = @INC, File::Spec->catdir(
191 # $conf->get_conf('base'),
192 # $conf->_get_build('plugins') );
193  
194 ### load any possible plugins
195 sub dist_types {
196  
197 99 ▶ if ( !$Loaded++ and check_install( module => 'Module::Pluggable',
Subroutine dist_types: called CC=4 SCAR=13.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (not $Loaded++ and check_install("module", "Module::Pluggable", "version", "2.4")) 5 94 99
Condition66%2/3
not $Loaded++ and check_install("module", "Module::Pluggable", "version", "2.4")
!ll&&!rl&&r
9405
MC/DC50%1/2
not $Loaded++ and check_install("module", "Module::Pluggable", "version", "2.4")
not $Loaded++ check_install("module", "Module::Pluggable", "version", "2.4")
Truth table66%2/3
not(A) and B
A= not $Loaded++B= check_install("module", "Module::Pluggable", "version", "2.4")
ABresult
0X0
100
111
198 version => '2.4')
199 ) {
200 5 require Module::Pluggable;
201  
202 5 my $only_re = __PACKAGE__ . '::\w+$';
203 5 my %except = map { $_ => 1 }
204 INSTALLER_SAMPLE,
205 INSTALLER_BASE;
206  
207 5 Module::Pluggable->import(
208 sub_name => '_dist_types',
209 search_path => __PACKAGE__,
210 only => qr/$only_re/,
211 require => 1,
212 except => [ keys %except ]
213 );
214 5 my %ignore = map { $_ => $_ } @Ignore;
215  
216 5 ▶ push @Dists, grep { not $ignore{$_} and not $except{$_} }
Condition66%2/3
$ignore{$_} || $except{$_}
l!l&&r!l&&!r
1012
MC/DC50%1/2
$ignore{$_} || $except{$_}
$ignore{$_} $except{$_}
Truth table66%2/3
A || B
A= $ignore{$_}B= $except{$_}
ABresult
1X1
011
000
217 __PACKAGE__->_dist_types;
218 }
219  
220 99 return @Dists;
221 }
222  
223 =head2 $bool = CPANPLUS::Dist->rescan_dist_types;
224  
225 Rescans C<@INC> for available dist types. Useful if you've installed new
226 C<CPANPLUS::Dist::*> classes and want to make them available to the
227 current process.
228  
229 =cut
230  
231 sub rescan_dist_types {
232 1 ▶ my $dist = shift;
Subroutine rescan_dist_types: called CC=1 SCAR=0.0
Pod documented
233 1 $Loaded = 0; # reset the flag;
234 1 return $dist->dist_types;
235 }
236 }
237  
238 =head2 $bool = CPANPLUS::Dist->has_dist_type( $type )
239  
240 Returns true if distribution type C<$type> is loaded/supported.
241  
242 =cut
243  
244 20 sub has_dist_type {
245 21 ▶ my $dist = shift;
Subroutine has_dist_type: called CC=2 SCAR=7.0
Pod documented
246 21 ▶ my $type = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $type = shift() or return 0 21 21
247  
248 21 return scalar grep { $_ eq $type } CPANPLUS::Dist->dist_types;
249 }
250  
251 =head2 $bool = $dist->prereq_satisfied( modobj => $modobj, version => $version_spec )
252  
253 Returns true if this prereq is satisfied. Returns false if it's not.
254 Also issues an error if it seems "unsatisfiable," i.e. if it can't be
255 found on CPAN or the latest CPAN version doesn't satisfy it.
256  
257 =cut
258  
259 sub prereq_satisfied {
260 30 ▶ my $dist = shift;
Subroutine prereq_satisfied: called CC=4 SCAR=13.9
Pod documented
261 30 my $cb = $dist->parent->parent;
262 30 my %hash = @_;
263  
264 30 my($mod,$ver);
265 30 my $tmpl = {
266 version => { required => 1, store => \$ver },
267 modobj => { required => 1, store => \$mod, allow => IS_MODOBJ },
268 };
269  
270 30 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 30 30
271  
272 30 ▶ return 1 if $mod->is_uptodate( version => $ver );
Branch: 1 branch
BranchTrueFalseTotal
if $mod->is_uptodate("version", $ver) 11 19 30
273  
274 19 ▶ if ( $cb->_vcmp( $ver, $mod->version ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb->_vcmp($ver, $mod->version) > 0) 15 4 19
275  
276 15 error(loc(
277 "This distribution depends on %1, but the latest version".
278 " of %2 on CPAN (%3) doesn't satisfy the specific version".
279 " dependency (%4). You may have to resolve this dependency ".
280 "manually.",
281 $mod->module, $mod->module, $mod->version, $ver ));
282  
283 }
284  
285 19 return;
286 }
287  
288 =head2 $configure_requires = $dist->find_configure_requires( [file => /path/to/META.yml] )
289  
290 Reads the configure_requires for this distribution from the META.yml or META.json
291 file in the root directory and returns a hashref with module names
292 and versions required.
293  
294 =cut
295  
296 sub find_configure_requires {
297 10 ▶ my $self = shift;
Subroutine find_configure_requires: called CC=7 SCAR=19.5
Pod documented
298 10 my $mod = $self->parent;
299 10 my %hash = @_;
300  
301 10 my ($meta);
302 10 my $href = {};
303  
304 10 my $tmpl = {
305 file => { store => \$meta },
306 };
307  
308 10 $self->_stash_metadata(); # Okay hacks.
309  
310 10 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 10 10
311  
312 10 my $meth = 'configure_requires';
313  
314 {
315  
316 ### the prereqs as we have them now
317 10 ▶ my @args = (
Condition100%2/2
$mod->status->$meth || {}
l!l
55
MC/DC100%1/1
$mod->status->$meth || {}
$mod->status->$meth
Truth table100%2/2
A
A= $mod->status->$meth
Aresult
11
00
318 defaults => $mod->status->$meth || {},
319 );
320  
321 10 ▶ my @possibles = do { defined $mod->status->extract
Branch: 1 branch
BranchTrueFalseTotal
defined $mod->status->extract ? : 9 1 10
322 ? ( META_JSON->( $mod->status->extract ),
323 META_YML->( $mod->status->extract ) )
324 : ()
325 };
326  
327 10 ▶ unshift @possibles, $meta if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 1 9 10
328  
329 10 META: foreach my $mfile ( grep { -e } @possibles ) {
330 10 push @args, ( file => $mfile );
331 10 ▶ if ( $mfile =~ /\.json/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mfile =~ /\.json/) { } 0 10 10
332 0 $href = $self->_prereqs_from_meta_json( @args, keys => [ 'configure' ] );
333 }
334 else {
335 10 $href = $self->_prereqs_from_meta_file( @args, keys => [ $meth ] );
336 }
337 10 last META;
338 }
339  
340 }
341  
342 ### and store it in the module
343 10 $mod->status->$meth( $href );
344  
345 10 return { %$href };
346 }
347  
348 sub find_mymeta_requires {
349 3 ▶ my $self = shift;
Subroutine find_mymeta_requires: called CC=7 SCAR=19.9
Pod undocumented
350 3 my $mod = $self->parent;
351 3 my %hash = @_;
352  
353 3 my ($meta);
354 3 my $href = {};
355  
356 3 my $tmpl = {
357 file => { store => \$meta },
358 };
359  
360 3 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 3 3
361  
362 3 my $meth = 'prereqs';
363  
364 {
365  
366 ### the prereqs as we have them now
367 3 ▶ my @args = (
Condition50%1/2
$mod->status->$meth || {}
l!l
03
MC/DC0%0/1
$mod->status->$meth || {}
$mod->status->$meth
Truth table50%1/2
A
A= $mod->status->$meth
Aresult
11
00
368 defaults => $mod->status->$meth || {},
369 );
370  
371 3 ▶ my @possibles = do { defined $mod->status->extract
Branch: 1 branch
BranchTrueFalseTotal
defined $mod->status->extract ? : 3 0 3
372 ? ( MYMETA_JSON->( $mod->status->extract ),
373 MYMETA_YML->( $mod->status->extract ) )
374 : ()
375 };
376  
377 3 ▶ unshift @possibles, $meta if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 0 3 3
378  
379 3 META: foreach my $mfile ( grep { -e } @possibles ) {
380 3 push @args, ( file => $mfile );
381 3 ▶ if ( $mfile =~ /\.json/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mfile =~ /\.json/) { } 3 0 3
382 3 $href = $self->_prereqs_from_meta_json( @args,
383 keys => [ qw|build test runtime| ] );
384 }
385 else {
386 0 $href = $self->_prereqs_from_meta_file( @args,
387 keys => [ qw|build_requires requires| ] );
388 }
389 3 last META;
390 }
391  
392 }
393  
394 ### and store it in the module
395 3 $mod->status->$meth( $href );
396  
397 3 return { %$href };
398 }
399  
400 sub _prereqs_from_meta_file {
401 10 ▶ my $self = shift;
Subroutine _prereqs_from_meta_file: called CC=7 SCAR=20.1
402 10 my $mod = $self->parent;
403 10 my %hash = @_;
404  
405 10 my( $meta, $defaults, $keys );
406 my $tmpl = { ### check if we have an extract path. if not, we
407 ### get 'undef value' warnings from file::spec
408 10 ▶ file => { default => do { defined $mod->status->extract
Branch: 1 branch
BranchTrueFalseTotal
defined $mod->status->extract ? : 9 1 10
409 ? META_YML->( $mod->status->extract )
410 : '' },
411 store => \$meta,
412 },
413 defaults => { required => 1, default => {}, strict_type => 1,
414 store => \$defaults },
415 keys => { required => 1, default => [], strict_type => 1,
416 store => \$keys },
417 };
418  
419 10 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 10 10
420  
421 ### if there's a meta file, we read it;
422 10 ▶ if( -e $meta ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $meta) 10 0 10
423  
424 ### Parse::CPAN::Meta uses exceptions for errors
425 ### hash returned in list context!!!
426  
427 10 local $ENV{PERL_YAML_BACKEND};
428  
429 10 my ($doc) = eval { Parse::CPAN::Meta::LoadFile( $meta ) };
430  
431 10 ▶ unless( $doc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc) 0 10 10
432 0 error(loc( "Could not read %1: '%2'", $meta, $@ ));
433 0 return $defaults;
434 }
435  
436 ### read the keys now, make sure not to throw
437 ### away anything that was already added
438 10 for my $key ( @$keys ) {
439 $defaults = {
440 %$defaults,
441 10 %{ $doc->{$key} },
442 10 ▶ } if $doc->{ $key };
Branch: 1 branch
BranchTrueFalseTotal
if $doc->{$key} 10 0 10
443 }
444 }
445  
446 ### and return a copy
447 10 return \%{ $defaults };
448 }
449  
450 sub _prereqs_from_meta_json {
451 3 ▶ my $self = shift;
Subroutine _prereqs_from_meta_json: called CC=8 SCAR=21.6
452 3 my $mod = $self->parent;
453 3 my %hash = @_;
454  
455 3 my( $meta, $defaults, $keys );
456 my $tmpl = { ### check if we have an extract path. if not, we
457 ### get 'undef value' warnings from file::spec
458 3 ▶ file => { default => do { defined $mod->status->extract
Branch: 1 branch
BranchTrueFalseTotal
defined $mod->status->extract ? : 3 0 3
459 ? META_JSON->( $mod->status->extract )
460 : '' },
461 store => \$meta,
462 },
463 defaults => { required => 1, default => {}, strict_type => 1,
464 store => \$defaults },
465 keys => { required => 1, default => [], strict_type => 1,
466 store => \$keys },
467 };
468  
469 3 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 3 3
470  
471 ### if there's a meta file, we read it;
472 3 ▶ if( -e $meta ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $meta) 3 0 3
473  
474 ### Parse::CPAN::Meta uses exceptions for errors
475 ### hash returned in list context!!!
476  
477 3 local $ENV{PERL_JSON_BACKEND};
478  
479 3 my ($doc) = eval { Parse::CPAN::Meta->load_file( $meta ) };
480  
481 3 ▶ unless( $doc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc) 0 3 3
482 0 error(loc( "Could not read %1: '%2'", $meta, $@ ));
483 0 return $defaults;
484 }
485  
486 ### read the keys now, make sure not to throw
487 ### away anything that was already added
488 #for my $key ( @$keys ) {
489 # $defaults = {
490 # %$defaults,
491 # %{ $doc->{$key} },
492 # } if $doc->{ $key };
493 #}
494 3 ▶ my $prereqs = $doc->{prereqs} || {};
Condition50%1/2
$doc->{'prereqs'} || {}
l!l
30
MC/DC0%0/1
$doc->{'prereqs'} || {}
$doc->{'prereqs'}
Truth table50%1/2
A
A= $doc->{'prereqs'}
Aresult
11
00
495 3 for my $key ( @$keys ) {
496 $defaults = {
497 %$defaults,
498 3 %{ $prereqs->{$key}->{requires} },
499 9 ▶ } if $prereqs->{ $key }->{requires};
Branch: 1 branch
BranchTrueFalseTotal
if $prereqs->{$key}{"requires"} 3 6 9
500 }
501 }
502  
503 ### and return a copy
504 3 return \%{ $defaults };
505 }
506  
507 sub _stash_metadata {
508 10 ▶ my $self = shift;
Subroutine _stash_metadata: called CC=6 SCAR=21.4
509 10 my $mod = $self->parent;
510  
511 10 ▶ my @possibles = do { defined $mod->status->extract
Branch: 1 branch
BranchTrueFalseTotal
defined $mod->status->extract ? : 9 1 10
512 ? ( META_JSON->( $mod->status->extract ),
513 META_YML->( $mod->status->extract ) )
514 : ()
515 };
516  
517 10 $self->mk_accessors( qw[_metadata] );
518 10 $self->status->_metadata( {} );
519  
520 10 META: foreach my $mfile ( grep { -e } @possibles ) {
521 9 ▶ if ( $mfile =~ /\.json/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mfile =~ /\.json/) { } 0 9 9
522 0 local $ENV{PERL_JSON_BACKEND};
523 0 my ($doc) = eval { Parse::CPAN::Meta->load_file( $mfile ) };
524 0 ▶ unless( $doc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc) 0 0 0
525 0 error(loc( "Could not read %1: '%2'", $mfile, $@ ));
526 0 return;
527 }
528 0 $self->status->_metadata( $doc );
529 0 return $doc;
530 }
531 else {
532 9 local $ENV{PERL_YAML_BACKEND};
533 9 my ($doc) = eval { Parse::CPAN::Meta->load_file( $mfile ) };
534 9 ▶ unless( $doc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc) 0 9 9
535 0 error(loc( "Could not read %1: '%2'", $mfile, $@ ));
536 0 return;
537 }
538 9 $self->status->_metadata( $doc );
539 9 return $doc;
540 }
541 }
542 1 return;
543 }
544  
545  
546 =head2 $bool = $dist->_resolve_prereqs( ... )
547  
548 Makes sure prerequisites are resolved
549  
550 format The dist class to use to make the prereqs
551 (ie. CPANPLUS::Dist::MM)
552  
553 prereqs Hash of the prerequisite modules and their versions
554  
555 target What to do with the prereqs.
556 create => Just build them
557 install => Install them
558 ignore => Ignore them
559  
560 prereq_build If true, always build the prereqs even if already
561 resolved
562  
563 verbose Be verbose
564  
565 force Force the prereq to be built, even if already resolved
566  
567 =cut
568  
569 sub _resolve_prereqs {
570 31 ▶ my $dist = shift;
Subroutine _resolve_prereqs: called CC=41 SCAR=40.1
571 31 my $self = $dist->parent;
572 31 my $cb = $self->parent;
573 31 my $conf = $cb->configure_object;
574 31 my %hash = @_;
575  
576 31 my ($prereqs, $format, $verbose, $target, $force, $prereq_build,$tolerant);
577 31 my $tmpl = {
578 ### XXX perhaps this should not be required, since it may not be
579 ### packaged, just installed...
580 ### Let it be empty as well -- that means the $modobj->install
581 ### routine will figure it out, which is fine if we didn't have any
582 ### very specific wishes (it will even detect the favourite
583 ### dist_type).
584 format => { required => 1, store => \$format,
585 allow => ['',__PACKAGE__->dist_types], },
586 prereqs => { required => 1, default => { },
587 strict_type => 1, store => \$prereqs },
588 verbose => { default => $conf->get_conf('verbose'),
589 store => \$verbose },
590 force => { default => $conf->get_conf('force'),
591 store => \$force },
592 ### make sure allow matches with $mod->install's list
593 target => { default => '', store => \$target,
594 allow => ['',qw[create ignore install]] },
595 prereq_build => { default => 0, store => \$prereq_build },
596 tolerant => { default => $conf->get_conf('allow_unknown_prereqs'),
597 store => \$tolerant },
598 };
599  
600 31 ▶ check( $tmpl, \%hash ) or return;
Branch: 1 branch
BranchTrueFalseTotal
check($tmpl, \%hash) or return 0 31 31
601  
602 ### so there are no prereqs? then don't even bother
603 31 ▶ return 1 unless keys %$prereqs;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$prereqs 0 31 31
604  
605 ### Make sure we wound up where we started.
606 31 my $original_wd = Cwd::cwd;
607  
608 ### so you didn't provide an explicit target.
609 ### maybe your config can tell us what to do.
610 $target ||= {
611 PREREQ_ASK, TARGET_INSTALL, # we'll bail out if the user says no
612 PREREQ_BUILD, TARGET_CREATE,
613 PREREQ_IGNORE, TARGET_IGNORE,
614 PREREQ_INSTALL, TARGET_INSTALL,
615 31 ▶ }->{ $conf->get_conf('prereqs') } || '';
Condition60%3/5
$target ||= {2, "install", 3, "create", 0, "ignore", 1, "install"}->{$conf->get_conf("prereqs")} || ""
l!l&&r!l&&!r
15160
{2, 'install', 3, 'create', 0, 'ignore', 1, 'install'}->{$conf->get_conf('prereqs')} || ''
l!l
160
MC/DC0%0/2
$target ||= {2, "install", 3, "create", 0, "ignore", 1, "install"}->{$conf->get_conf("prereqs")} || ""
$target {2, 'install', 3, 'create', 0, 'ignore', 1, 'install'}->{$conf->get_conf('prereqs')}
Truth table66%2/3
A ||= B
A= $targetB= {2, 'install', 3, 'create', 0, 'ignore', 1, 'install'}->{$conf->get_conf('prereqs')}
ABresult
1X1
011
000
616  
617 ### XXX BIG NASTY HACK XXX FIXME at some point.
618 ### when installing Bundle::CPANPLUS::Dependencies, we want to
619 ### install all packages matching 'cpanplus' to be installed last,
620 ### as all CPANPLUS' prereqs are being installed as well, but are
621 ### being loaded for bootstrapping purposes. This means CPANPLUS
622 ### can find them, but for example cpanplus::dist::build won't,
623 ### which gets messy FAST. So, here we sort our prereqs only IF
624 ### the parent module is Bundle::CPANPLUS::Dependencies.
625 ### Really, we would want some sort of sorted prereq mechanism,
626 ### but Bundle:: doesn't support it, and we flatten everything
627 ### to a hash internally. A sorted hash *might* do the trick if
628 ### we got a transparent implementation.. that would mean we would
629 ### just have to remove the 'sort' here, and all will be well
630 31 my @sorted_prereqs;
631  
632 ### use regex, could either be a module name, or a package name
633 31 ▶ if( $self->module =~ /^Bundle(::|-)CPANPLUS(::|-)Dependencies/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->module =~ /^Bundle(::|-)CPANPLUS(::|-)Dependencies/) { } 0 31 31
634 0 my (@first, @last);
635 0 for my $mod ( sort keys %$prereqs ) {
636 0 ▶ $mod =~ /CPANPLUS/
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ /CPANPLUS/ ? : 0 0 0
637 ? push @last, $mod
638 : push @first, $mod;
639 }
640 0 @sorted_prereqs = (@first, @last);
641 } else {
642 31 @sorted_prereqs = sort keys %$prereqs;
643 }
644  
645 ### first, transfer this key/value pairing into a
646 ### list of module objects + desired versions
647 31 my @install_me;
648  
649 my $flag;
650  
651 31 for my $mod ( @sorted_prereqs ) {
652 31 ( my $version = $prereqs->{$mod} ) =~ s#[^0-9\._]+##g;
653  
654 ### 'perl' is a special case, there's no mod object for it
655 31 ▶ if( $mod eq PERL_CORE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod eq "perl") 2 29 31
656  
657 2 ▶ unless( $cb->_vcmp( sprintf('v%vd',$^V), $version ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cb->_vcmp(sprintf("v%vd", $^V), $version) >= 0) 1 1 2
658 1 error(loc( "Module '%1' needs perl version '%2', but you ".
659 "only have version '%3' -- can not proceed",
660 $self->module, $version,
661 $cb->_perl_version( perl => $^X ) ) );
662 1 return;
663 }
664  
665 1 next;
666 }
667  
668 29 my $modobj = $cb->module_tree($mod);
669  
670 #### XXX we ignore the version, and just assume that the latest
671 #### version from cpan will meet your requirements... dodgy =/
672 29 ▶ unless( $modobj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($modobj) 3 26 29
673 # Check if it is a core module
674 3 my $sub = CPANPLUS::Module->can(
675 'module_is_supplied_with_perl_core' );
676 3 my $core = $sub->( $mod );
677 3 ▶ unless ( defined $core ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $core) 0 3 3
678 0 error( loc( "No such module '%1' found on CPAN", $mod ) );
679 0 ▶ $flag++ unless $tolerant;
Branch: 1 branch
BranchTrueFalseTotal
unless $tolerant 0 0 0
680 0 next;
681 }
682 3 ▶ if ( $cb->_vcmp( $version, $core ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb->_vcmp($version, $core) > 0) 0 3 3
683 0 error(loc( "Version of core module '%1' ('%2') is too low for ".
684 "'%3' (needs '%4') -- carrying on but this may be a problem",
685 $mod, $core,
686 $self->module, $version ));
687 }
688 3 next;
689 }
690  
691 ### it's not uptodate, we need to install it
692 26 ▶ if( !$dist->prereq_satisfied(modobj => $modobj, version => $version)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $dist->prereq_satisfied('modobj', $modobj, 'version', $version)) { } 15 11 26
elsif (sub { package CPANPLUS::Internals::Constants; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM'; } ->($format) and not $modobj->package_is_perl_core and $target ne 'ignore') { } 0 22 22
693 15 msg(loc("Module '%1' requires '%2' version '%3' to be installed ",
694 $self->module, $modobj->module, $version), $verbose );
695  
696 15 push @install_me, [$modobj, $version];
697  
698 ### it's not an MM or Build format, that means it's a package
699 ### manager... we'll need to install it as well, via the PM
700 ▶ } elsif ( INSTALL_VIA_PACKAGE_MANAGER->($format) and
Condition33%2/6
sub { package CPANPLUS::Internals::Constants; use strict; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM';}->($format) and not $modobj->package_is_perl_core and $target ne "ignore"
!ll&&!rl&&r
1100
sub { package CPANPLUS::Internals::Constants; use strict; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM';}->($format) and not $modobj->package_is_perl_core
!ll&&!rl&&r
1100
MC/DC0%0/3
sub { package CPANPLUS::Internals::Constants; use strict; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM';}->($format) and not $modobj->package_is_perl_core and $target ne "ignore"
sub { package CPANPLUS::Internals::Constants; use strict; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM';}->($format) not $modobj->package_is_perl_core $target ne "ignore"
Truth table25%1/4
A and not(B) and C
A= sub { package CPANPLUS::Internals::Constants; use strict; my $fmt = $_[0] or return; return 1 if $fmt ne 'CPANPLUS::Dist::Build' and $fmt ne 'CPANPLUS::Dist::MM';}->($format)B= not $modobj->package_is_perl_coreC= $target ne "ignore"
ABCresult
0XX0
10X0
1100
1111
701 !$modobj->package_is_perl_core and
702 ($target ne TARGET_IGNORE)
703 ) {
704 0 msg(loc("Module '%1' depends on '%2', may need to build a '%3' ".
705 "package for it as well", $self->module, $modobj->module,
706 $format));
707 0 push @install_me, [$modobj, $version];
708 }
709 }
710  
711  
712  
713 ### so you just want to ignore prereqs? ###
714 30 ▶ if( $target eq TARGET_IGNORE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "ignore") 2 28 30
715  
716 ### but you have modules you need to install
717 2 ▶ if( @install_me ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@install_me) { } 2 0 2
718 2 msg(loc("Ignoring prereqs, this may mean your install will fail"),
719 $verbose);
720 2 msg(loc("'%1' listed the following dependencies:", $self->module),
721 $verbose);
722  
723 2 for my $aref (@install_me) {
724 2 my ($mod,$version) = @$aref;
725  
726 2 my $str = sprintf "\t%-35s %8s\n", $mod->module, $version;
727 2 msg($str,$verbose);
728 }
729  
730 2 return;
731  
732 ### ok, no problem, you have all needed prereqs anyway
733 } else {
734 0 return 1;
735 }
736 }
737  
738 28 for my $aref (@install_me) {
739 13 my($modobj,$version) = @$aref;
740  
741 ### another prereq may have already installed this one...
742 ### so don't ask again if the module turns out to be uptodate
743 ### see bug [#11840]
744 ### if either force or prereq_build are given, the prereq
745 ### should be built anyway
746 13 ▶ next if (!$force and !$prereq_build) &&
Branch: 1 branch
BranchTrueFalseTotal
if not $force || $prereq_build and $dist->prereq_satisfied("modobj", $modobj, "version", $version) 0 13 13
Condition66%4/6
not $force || $prereq_build and $dist->prereq_satisfied("modobj", $modobj, "version", $version)
!ll&&!rl&&r
1210
$force || $prereq_build
l!l&&r!l&&!r
1201
MC/DC0%0/3
not $force || $prereq_build and $dist->prereq_satisfied("modobj", $modobj, "version", $version)
$force $prereq_build $dist->prereq_satisfied("modobj", $modobj, "version", $version)
Truth table50%2/4
not(A || B) and C
A= $forceB= $prereq_buildC= $dist->prereq_satisfied("modobj", $modobj, "version", $version)
ABCresult
1XX0
01X0
0000
0011
747 $dist->prereq_satisfied(modobj => $modobj, version => $version);
748  
749 ### either we're told to ignore the prereq,
750 ### or the user wants us to ask him
751 13 ▶ if( ( $conf->get_conf('prereqs') == PREREQ_ASK and not
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->get_conf("prereqs") == 2 and not $cb->_callbacks->install_prerequisite->($self, $modobj)) 1 12 13
Condition100%3/3
$conf->get_conf("prereqs") == 2 and not $cb->_callbacks->install_prerequisite->($self, $modobj)
!ll&&!rl&&r
841
MC/DC100%2/2
$conf->get_conf("prereqs") == 2 and not $cb->_callbacks->install_prerequisite->($self, $modobj)
$conf->get_conf("prereqs") == 2 not $cb->_callbacks->install_prerequisite->($self, $modobj)
Truth table100%3/3
A and not(B)
A= $conf->get_conf("prereqs") == 2B= not $cb->_callbacks->install_prerequisite->($self, $modobj)
ABresult
0X0
100
111
752 $cb->_callbacks->install_prerequisite->($self, $modobj)
753 )
754 ) {
755 1 msg(loc("Will not install prerequisite '%1' -- Note " .
756 "that the overall install may fail due to this",
757 $modobj->module), $verbose);
758 1 next;
759 }
760  
761 ### value set and false -- means failure ###
762 12 ▶ if( defined $modobj->status->installed
Branch: 1 branch
BranchTrueFalseTotal
if (defined $modobj->status->installed and not $modobj->status->installed) 1 11 12
Condition66%2/3
defined $modobj->status->installed and not $modobj->status->installed
!ll&&!rl&&r
1101
MC/DC50%1/2
defined $modobj->status->installed and not $modobj->status->installed
defined $modobj->status->installed not $modobj->status->installed
Truth table66%2/3
A and not(B)
A= defined $modobj->status->installedB= not $modobj->status->installed
ABresult
0X0
100
111
763 && !$modobj->status->installed
764 ) {
765 1 error( loc( "Prerequisite '%1' failed to install before in " .
766 "this session", $modobj->module ) );
767 1 $flag++;
768 1 last;
769 }
770  
771 ### part of core?
772 11 ▶ if( $modobj->package_is_perl_core ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modobj->package_is_perl_core) 1 10 11
773 1 error(loc("Prerequisite '%1' is perl-core (%2) -- not ".
774 "installing that. -- Note that the overall ".
775 "install may fail due to this.",
776 $modobj->module, $modobj->package ) );
777 1 next;
778 }
779  
780 ### circular dependency code ###
781 10 ▶ my $pending = $cb->_status->pending_prereqs || {};
Condition100%2/2
$cb->_status->pending_prereqs || {}
l!l
28
MC/DC100%1/1
$cb->_status->pending_prereqs || {}
$cb->_status->pending_prereqs
Truth table100%2/2
A
A= $cb->_status->pending_prereqs
Aresult
11
00
782  
783 ### recursive dependency ###
784 10 ▶ if ( $pending->{ $modobj->module } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$pending{$modobj->module}) 1 9 10
785 1 error( loc( "Recursive dependency detected (%1) -- skipping",
786 $modobj->module ) );
787 1 next;
788 }
789  
790 ### register this dependency as pending ###
791 9 $pending->{ $modobj->module } = $modobj;
792 9 $cb->_status->pending_prereqs( $pending );
793  
794 ### call $modobj->install rather than doing
795 ### CPANPLUS::Dist->new and the like ourselves,
796 ### since ->install will take care of fetch &&
797 ### extract as well
798 9 ▶ my $pa = $dist->status->_prepare_args || {};
Condition100%2/2
$dist->status->_prepare_args || {}
l!l
18
MC/DC100%1/1
$dist->status->_prepare_args || {}
$dist->status->_prepare_args
Truth table100%2/2
A
A= $dist->status->_prepare_args
Aresult
11
00
799 9 ▶ my $ca = $dist->status->_create_args || {};
Condition100%2/2
$dist->status->_create_args || {}
l!l
18
MC/DC100%1/1
$dist->status->_create_args || {}
$dist->status->_create_args
Truth table100%2/2
A
A= $dist->status->_create_args
Aresult
11
00
800 9 ▶ my $ia = $dist->status->_install_args || {};
Condition50%1/2
$dist->status->_install_args || {}
l!l
09
MC/DC0%0/1
$dist->status->_install_args || {}
$dist->status->_install_args
Truth table50%1/2
A
A= $dist->status->_install_args
Aresult
11
00
801  
802 9 ▶ unless( $modobj->install( %$pa, %$ca, %$ia,
Branch: 1 branch
BranchTrueFalseTotal
unless ($modobj->install(%$pa, %$ca, %$ia, "force", $force, "verbose", $verbose, "format", $format, "target", $target)) 3 6 9
803 force => $force,
804 verbose => $verbose,
805 format => $format,
806 target => $target )
807 ) {
808 3 error(loc("Failed to install '%1' as prerequisite " .
809 "for '%2'", $modobj->module, $self->module ) );
810 3 $flag++;
811 }
812  
813 ### unregister the pending dependency ###
814 9 $pending->{ $modobj->module } = 0;
815 9 $cb->_status->pending_prereqs( $pending );
816  
817 9 ▶ last if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 3 6 9
818  
819 ### don't want us to install? ###
820 6 ▶ if( $target ne TARGET_INSTALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target ne "install") 3 3 6
821 3 ▶ my $dir = $modobj->status->extract
Branch: 1 branch
BranchTrueFalseTotal
my $dir = $modobj->status->extract or error(loc("No extraction dir for '%1' found -- weird", $modobj->module)) 0 3 3
822 or error(loc("No extraction dir for '%1' found ".
823 "-- weird", $modobj->module));
824  
825 3 $modobj->add_to_includepath();
826  
827 3 next;
828 }
829 }
830  
831 ### reset the $prereqs iterator, in case we bailed out early ###
832 28 keys %$prereqs;
833  
834 ### chdir back to where we started
835 28 $cb->_chdir( dir => $original_wd );
836  
837 28 ▶ return 1 unless $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless $flag 24 4 28
838 4 return;
839 }
840  
841 20 1;
842  
843 # Local variables:
844 # c-indentation-style: bsd
845 # c-basic-offset: 4
846 # indent-tabs-mode: nil
847 # End:
848 # vim: expandtab shiftwidth=4:
« blib/lib/CPANPLUS/Internals.pm ↑ Summary lib/CPANPLUS/Internals/Fetch.pm »