lib/CPAN/FindDependencies.pm

filter: Statementstmt 95.9% 234 / 244 Branchbran 87.7% 93 / 106 Conditioncond 82.1% 46 / 56 MC/DCmcdc 67.7% 21 / 31 Subroutinesub 96.8% 31 / 32 Podpod 100% 1 / 1 totaltotal 90.6% 426 / 470 CC 76 SCAR 23.5
CC
76
Cov
92%
finddeps
22.2
_get_cached
15.1
_getreqs
11.2
CRAP 10.5
↑ Summary lib/CPAN/FindDependencies/MakeMaker.pm »
1 package CPAN::FindDependencies;
2  
3 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use vars qw(@net_log $VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶use Archive::Tar;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 ▶use Archive::Zip;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 34 ▶use Env::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 34 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 34 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 34 ▶use File::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 34 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 34 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 34 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 34 ▶use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 34 ▶use CPAN::FindDependencies::Dependency;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 34 ▶use CPAN::FindDependencies::MakeMaker qw(getreqs_from_mm);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use Parse::CPAN::Packages;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 34 require Exporter;
23 34 @ISA = qw(Exporter);
24 34 @EXPORT_OK = qw(finddeps);
25  
26 34 $VERSION = '3.14';
27  
28 34 ▶use constant MAXINT => ~0;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 34 ▶eval 'use LWP::Protocol::https';
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 =head1 NAME
33  
34 CPAN::FindDependencies - find dependencies for modules on the CPAN
35  
36 =head1 SYNOPSIS
37  
38 use CPAN::FindDependencies;
39 my @dependencies = CPAN::FindDependencies::finddeps("CPAN");
40 foreach my $dep (@dependencies) {
41 print ' ' x $dep->depth();
42 print $dep->name().' ('.$dep->distribution().")\n";
43 }
44  
45 =head1 INCOMPATIBLE CHANGES
46  
47 Up to version 2.49 you used the C<02packages> argument to specify where a
48 cached C<02packages.details.txt.gz> could be found. That argument no longer
49 exists as of version 3.00, use the C<mirror> argument instead.
50  
51 Up to version 2.49, C<maxdepth =E<gt> 0> would incorrectly return the whole
52 tree. From version 3.00 it cuts the tree off at its root so will only return
53 the module that you asked about. Not very useful, but correct.
54  
55 In version 2.49 you used the C<configreqs> argument to specify that you were
56 interested in configure-time requirements as well as build- and run-time
57 requirements. That option no longer exists as of version 3.00, it will always
58 report on configure, build, test, and run-time requirements.
59  
60  
61 =head1 HOW IT WORKS
62  
63 The module uses the CPAN packages index to map modules to distributions and
64 vice versa, and then fetches distributions' metadata or Makefile.PL files from
65 a CPAN mirror to determine pre-requisites. This means that a
66 working interwebnet connection is required.
67  
68 =head1 FUNCTIONS
69  
70 There is just one function, which is not exported by default
71 although you can make that happen in the usual fashion.
72  
73 =head2 finddeps
74  
75 Takes a single compulsory parameter, the name of a module
76 (ie Some::Module); and the following optional
77 named parameters:
78  
79 =over
80  
81 =item nowarnings
82  
83 Warnings about modules where we can't find their META.yml or Makefile.PL, and
84 so can't divine their pre-requisites, will be suppressed. Other warnings may
85 still be emitted though, such as those telling you about modules which have
86 dodgy (but still understandable) metadata;
87  
88 =item fatalerrors
89  
90 Failure to get a module's dependencies will be a fatal error
91 instead of merely emitting a warning;
92  
93 =item perl
94  
95 Use this version of perl to figure out what's in core. If not
96 specified, it defaults to 5.005. Three part version numbers
97 (eg 5.8.8) are supported but discouraged.
98  
99 =item cachedir
100  
101 A directory to use for caching. It defaults to no caching. Even if
102 caching is turned on, this is only for META.yml or Makefile.PL files.
103 The cache is never automatically cleared out. It is your responsibility
104 to clear out old data.
105  
106 If the directory doesn't exist we will try to create it. If we can't,
107 or it exists but isn't readable and writeable, that is a fatal error.
108  
109 =item maxdepth
110  
111 Cuts off the dependency tree at the specified depth. Your specified
112 module is at depth 0, your dependencies at depth 1, their dependencies
113 at depth 2, and so on.
114  
115 If you don't specify any maxdepth at all it will grovel over the
116 entire tree.
117  
118 =item mirror
119  
120 This can be provided more than once, if for example you want to use
121 a private L<Pinto> repository for your own code while using a public
122 CPAN mirror for open source dependencies. The argument comes in two parts
123 separated by a comma - the base URL from which to fetch files, and
124 optionally the URL or a file from which to fetch the index
125 C<02packages.details.txt.gz> file to use with that mirror.
126  
127 mirror https://cpan.mydomain.net,file:///home/me/mycache/02packages.txt.gz
128  
129 If you want to use the default CPAN mirror (https://cpan.metacpan.org/)
130 but also specify an index location you can use C<DEFAULT> for the mirror URL.
131  
132 So for example, to use your own special private mirror, including fetching
133 02packages from it, but also use the default mirror with a cached local
134 copy of its 02packages, specify two mirrors thus:
135  
136 mirror => 'https://cpan.mydomain.net',
137 mirror => 'DEFAULT,file:///home/me/mycache/02packages.txt.gz'
138  
139 The index is cached for three minutes or until your process finishes, whichever is soonest. This is because it is HUMUNGOUS and parsing it takes ages even when it's loaded from a local disk, and I don't want the tests to take forever.
140  
141 =item usemakefilepl
142  
143 If set to true, then for any module that doesn't have a META.yml,
144 try to use its Makefile.PL as well. Note that this involves
145 downloading code from the Internet and running it. This obviously
146 opens you up to all kinds of bad juju, hence why it is disabled
147 by default. NB that this fetches Makefile.PL from
148 L<https://fastapi.metacpan.org> B<only> so will not work for private mirrors.
149 This is a deliberate choice, your own private code ought to be packaged
150 properly with a META file, you should only care about divining dependencies
151 from Makefile.PL if you rely on really old stuff on public CPAN mirrors.
152  
153 =item recommended
154  
155 Adds recommended modules to the list of dependencies, if set to a true value.
156  
157 =item suggested
158  
159 Adds suggested modules to the list of dependencies, if set to a true value.
160  
161  
162 =back
163  
164 Order of arguments is not important.
165  
166 It returns a list of CPAN::FindDependencies::Dependency objects, whose
167 useful methods are:
168  
169 =over
170  
171 =item name
172  
173 The module's name;
174  
175 =item distribution
176  
177 The distribution containing this module;
178  
179 =item version
180  
181 The minimum required version of his module (if specified in the requirer's
182 pre-requisites list);
183  
184 =item depth
185  
186 How deep in the dependency tree this module is;
187  
188 =item warning
189  
190 If any warning was generated (even if suppressed) for the module,
191 it will be recorded here.
192  
193 =back
194  
195 Any modules listed as dependencies but which are in the perl core
196 distribution for the version of perl you specified are suppressed.
197  
198 These objects are returned in a semi-defined order. You can be sure
199 that a module will be immediately followed by one of its dependencies,
200 then that dependency's dependencies, and so on, followed by the 'root'
201 module's next dependency, and so on. You can reconstruct the tree
202 by paying attention to the depth of each object.
203  
204 The ordering of any particular module's immediate 'children' can be
205 assumed to be random - it's actually hash key order.
206  
207 =head1 TREE PRUNING
208  
209 The dependency tree is pruned to remove duplicates. This means that even though
210 C<Test::More>, for example, is a dependency of almost everything on the CPAN,
211 it will only be listed once.
212  
213  
214 =head1 SECURITY
215  
216 If you set C<usemakefilepl> to a true value, this module may download code
217 from the internet and execute it. You should think carefully before enabling
218 that feature.
219  
220 =head1 BUGS/WARNINGS/LIMITATIONS
221  
222 You must have web access to L<http://metacpan.org/> and (unless
223 you tell it where else to look for the index)
224 L<http://www.cpan.org/>, or have all the data cached locally..
225 If any
226 metadata or Makefile.PL files are missing, the distribution's dependencies will
227 not be found and a warning will be spat out.
228  
229 Startup can be slow, especially if it needs to fetch the index from
230 the interweb.
231  
232 Dynamic dependencies - for example, dependencies that only apply on some
233 platforms - can't be reliably resolved. They *may* be resolved if you use the
234 unsafe Makefile.PL, but even that can't be relied on.
235  
236 =head1 FEEDBACK
237  
238 I welcome feedback about my code, including constructive criticism
239 and bug reports. The best bug reports include files that I can add
240 to the test suite, which fail with the current code in my git repo and
241 will pass once I've fixed the bug
242  
243 Feature requests are far more likely to get implemented if you submit
244 a patch yourself.
245  
246 =head1 SOURCE CODE REPOSITORY
247  
248 L<git://github.com/DrHyde/perl-modules-CPAN-FindDependencies.git>
249  
250 =head1 SEE ALSO
251  
252 L<CPAN>
253  
254 L<http://deps.cpantesters.org/>
255  
256 L<http://metacpan.org>
257  
258 =head1 AUTHOR, LICENCE and COPYRIGHT
259  
260 Copyright 2007 - 2026 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
261  
262 This software is free-as-in-speech software, and may be used,
263 distributed, and modified under the terms of either the GNU
264 General Public Licence version 2 or the Artistic Licence. It's
265 up to you which one you use. The full text of the licences can
266 be found in the files GPL2.txt and ARTISTIC.txt, respectively.
267  
268 =head1 THANKS TO
269  
270 Stephan Loyd (for fixing problems with some META.yml files)
271  
272 Alexandr Ciornii (for a patch to stop it segfaulting on Windows)
273  
274 Brian Phillips (for the code to report on required versions of modules)
275  
276 Ian Tegebo (for the code to extract deps from Makefile.PL)
277  
278 Georg Oechsler (for the code to also list 'recommended' modules)
279  
280 Jonathan Stowe (for making it work through HTTP proxies)
281  
282 Kenneth Olwing (for support for 'configure_requires')
283  
284 =head1 CONSPIRACY
285  
286 This module is also free-as-in-mason software.
287  
288 =cut
289  
290 34 my $default_mirror = 'https://cpan.metacpan.org/';
291 34 my @valid_params = qw(
292 nowarnings
293 fatalerrors
294 perl
295 cachedir
296 maxdepth
297 mirror
298 usemakefilepl
299 recommended
300 suggested
301 );
302  
303 38 ▶sub finddeps {
Subroutine finddeps: called CC=22 SCAR=31.0
Pod documented
304 38 @net_log = ();
305 38 my $module = '';
306 38 my @args = @_;
307  
308 38 my $self = bless({ indices => [], mirrors => [], seen => {} }, __PACKAGE__);
309  
310 38 ▶ while(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 171 36 207
311 171 my $option = shift(@args);
312 # print STDERR "found argument $option. Remaining args [".join(', ', @args)."]\n";
313 171 ▶ if($option eq 'mirror') {
Branch: 3 branches
BranchTrueFalseTotal
if ($option eq 'mirror') { } 37 134 171
elsif (grep {$_ eq $option;} @valid_params) { } 95 39 134
elsif (not $module) { } 38 1 39
314 37 my($mirror, $packages) = split(/,/, shift(@args));
315 37 ▶ $mirror = $default_mirror if($mirror eq 'DEFAULT');
Branch: 1 branch
BranchTrueFalseTotal
if $mirror eq "DEFAULT" 26 11 37
316 37 ▶ $mirror .= '/' unless($mirror =~ m{/$});
Branch: 1 branch
BranchTrueFalseTotal
unless $mirror =~ m[/$] 11 26 37
317 37 ▶ $packages = "${mirror}modules/02packages.details.txt.gz"
Branch: 1 branch
BranchTrueFalseTotal
unless $packages 14 23 37
318 unless($packages);
319 ($mirror, $packages) = map {
320 37 ▶ $_ =~ /^https?:\/\// ? $_ : ''.URI::file->new_abs($_);
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ m[^https?://] ? : 29 45 74
321 } ($mirror, $packages);
322 37 push @{$self->{mirrors}}, {
323 mirror => $mirror,
324 packages => $packages
325 };
326 1206 } elsif(grep { $_ eq $option } @valid_params) {
327 95 $self->{$option} = shift(@args);
328 95 ▶ if($option eq 'cachedir' && !(-d $self->{$option} && -r $self->{$option} && -w $self->{$option}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq "cachedir" and not -d $self->{$option} && -r $self->{$option} && -w $self->{$option}) 3 92 95
Condition77%7/9
$option eq "cachedir" and not -d $self->{$option} && -r $self->{$option} && -w $self->{$option}
!ll&&!rl&&r
63293
-d $self->{$option} && -r $self->{$option} && -w $self->{$option}
!ll&&!rl&&r
3029
-d $self->{$option} and -r $self->{$option}
!ll&&!rl&&r
3029
MC/DC50%2/4
$option eq "cachedir" and not -d $self->{$option} && -r $self->{$option} && -w $self->{$option}
$option eq "cachedir" -d $self->{$option} -r $self->{$option} -w $self->{$option}
Truth table60%3/5
A and not(B and C && D)
A= $option eq "cachedir"B= -d $self->{$option}C= -r $self->{$option}D= -w $self->{$option}
ABCDresult
0XXX0
11110
10XX1
110X1
11101
329 # bad cachedir, try to create
330 3 eval { path($self->{$option})->mkdir(); };
331 die("Bad cachedir: $self->{$option}\n")
332 3 ▶ unless(-d $self->{$option} && -r $self->{$option} && -w $self->{$option});
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{$option} and -r $self->{$option} and -w $self->{$option} 1 2 3
Condition66%4/6
-d $self->{$option} and -r $self->{$option} and -w $self->{$option}
!ll&&!rl&&r
102
-d $self->{$option} and -r $self->{$option}
!ll&&!rl&&r
102
MC/DC33%1/3
-d $self->{$option} and -r $self->{$option} and -w $self->{$option}
-d $self->{$option} -r $self->{$option} -w $self->{$option}
Truth table50%2/4
A and B and C
A= -d $self->{$option}B= -r $self->{$option}C= -w $self->{$option}
ABCresult
0XX0
10X0
1100
1111
333 }
334 } elsif(!$module) {
335 38 $module = $option
336 } else {
337 1 die("Can't look for dependencies for '$option', already looking for deps for '$module'\n");
338 }
339 }
340 36 ▶ unless(@{$self->{mirrors}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"mirrors"};}) 5 31 36
341 5 push @{$self->{mirrors}}, {
342 mirror => $default_mirror,
343 packages => "${default_mirror}modules/02packages.details.txt.gz"
344 }
345 }
346  
347 36 ▶ $self->{maxdepth} = MAXINT unless(defined($self->{maxdepth}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"maxdepth"} 30 6 36
348  
349 36 ▶ $self->{perl} ||= 5.005;
Condition100%2/2
$self->{"perl"} ||= "5.005"
l!l
1620
MC/DC100%1/1
$self->{"perl"} ||= "5.005"
$self->{"perl"}
Truth table100%2/2
A
A= $self->{"perl"}
Aresult
11
00
350 die(__PACKAGE__.": $self->{perl} is a broken version number\n")
351 36 ▶ if($self->{perl} =~ /[^0-9.]/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"perl"} =~ /[^0-9.]/ 0 36 36
352 36 ▶ if($self->{perl} =~ /\..*\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"perl"} =~ /\..*\./) 11 25 36
353 11 my @parts = split(/\./, $self->{perl});
354 11 $self->{perl} = $parts[0] + $parts[1] / 1000 + $parts[2] / 1000000;
355 }
356  
357 36 my $first_found = $self->_first_found($module);
358 36 ▶ return $self->_finddeps(
Branch: 1 branch
BranchTrueFalseTotal
$first_found ? : 36 0 36
359 module => $module,
360 version => ($first_found ? $first_found->version() : 0)
361 );
362 }
363  
364 # indices are cached for performance, cos even if the
365 # file is fetched from disk uncompressing/parsing take ages.
366 # the cache lasts three minutes.
367 34 our %_parsed_index_cache = ();
368 684 ▶sub _indices {
Subroutine _indices: called CC=5 SCAR=16.1
369 684 my $self = shift;
370 684 ▶ if(!@{$self->{indices}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"indices"};}) 36 648 684
371 36 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
372 $self->{indices} = [map {
373 41 my $url = $_->{packages};
374 41 ▶ if(!(exists($_parsed_index_cache{$url}) && $_parsed_index_cache{$url}->{expiry} > time())) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $CPAN::FindDependencies::_parsed_index_cache{$url} and $CPAN::FindDependencies::_parsed_index_cache{$url}{"expiry"} > time) 31 10 41
Condition100%3/3
exists $CPAN::FindDependencies::_parsed_index_cache{$url} and $CPAN::FindDependencies::_parsed_index_cache{$url}{"expiry"} > time
!ll&&!rl&&r
30110
MC/DC100%2/2
exists $CPAN::FindDependencies::_parsed_index_cache{$url} and $CPAN::FindDependencies::_parsed_index_cache{$url}{"expiry"} > time
exists $CPAN::FindDependencies::_parsed_index_cache{$url} $CPAN::FindDependencies::_parsed_index_cache{$url}{"expiry"} > time
Truth table100%3/3
A and B
A= exists $CPAN::FindDependencies::_parsed_index_cache{$url}B= $CPAN::FindDependencies::_parsed_index_cache{$url}{"expiry"} > time
ABresult
0X0
100
111
375 31 $_parsed_index_cache{$url}->{expiry} = time() + 180;
376 31 ▶ $_parsed_index_cache{$url}->{index} = Parse::CPAN::Packages->new(
Condition50%1/2
$self->_get($url) || die('CPAN::FindDependencies' . ": Couldn't fetch 02packages index file from $url\n")
l!l
310
MC/DC0%0/1
$self->_get($url) || die('CPAN::FindDependencies' . ": Couldn't fetch 02packages index file from $url\n")
$self->_get($url)
Truth table50%1/2
A
A= $self->_get($url)
Aresult
11
00
377 $self->_get($url) || die(__PACKAGE__.": Couldn't fetch 02packages index file from $url\n")
378 );
379 }
380 $_parsed_index_cache{$url}->{index}
381 36 } @{$self->{mirrors}}]
382 }
383 684 return @{$self->{indices}};
384 }
385  
386 # look through all the mirrors' 02packages for a module and return a
387 # Parse::CPAN::Packages::Package for the first one it finds
388 432 ▶sub _first_found {
Subroutine _first_found: called CC=1 SCAR=0.0
389 432 my $self = shift;
390 432 my $module = shift;
391 432 return (map { $_->package($module) } grep { $_->package($module) } $self->_indices())[0];
392 }
393  
394 22 ▶sub _yell {
Subroutine _yell: called CC=4 SCAR=13.9
395 22 my $self = shift;
396 22 my $msg = shift;
397 22 $msg = __PACKAGE__.": $msg";
398 22 ▶ $msg = "$msg\n" unless(substr($msg, -1, 1) eq "\n");
Branch: 1 branch
BranchTrueFalseTotal
unless substr($msg, -1, 1) eq "\n" 21 1 22
399 22 ▶ if(!$self->{nowarnings}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"nowarnings"}) 3 19 22
400 3 ▶ if($self->{fatalerrors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'fatalerrors'}) { } 1 2 3
401 1 die('FATAL: '.$msg);
402 } else {
403 2 warn('WARNING: '.$msg);
404 }
405 }
406 }
407  
408 313 ▶sub _get {
Subroutine _get: called CC=6 SCAR=22.6
409 313 my $self = shift;
410 313 my $url = shift;
411  
412 313 push @net_log, $url;
413  
414 313 ▶ if($LWP::Protocol::https::VERSION || $url !~ /^https:/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($LWP::Protocol::https::VERSION or not $url =~ /^https:/) { } 313 0 313
elsif (my($wget) = grep({-x "$_/wget";} 'Env::Path'->PATH->List)) { } 0 0 0
Condition33%1/3
$LWP::Protocol::https::VERSION or not $url =~ /^https:/
l!l&&r!l&&!r
31300
MC/DC0%0/2
$LWP::Protocol::https::VERSION or not $url =~ /^https:/
$LWP::Protocol::https::VERSION not $url =~ /^https:/
Truth table33%1/3
A or not(B)
A= $LWP::Protocol::https::VERSIONB= not $url =~ /^https:/
ABresult
1X1
011
000
415 313 my $ua = LWP::UserAgent->new();
416 313 $ua->env_proxy();
417 313 $ua->agent(__PACKAGE__."/$VERSION");
418 313 my $response = $ua->get($url);
419 313 ▶ if($response->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 135 178 313
420 135 return $response->content();
421 }
422 178 return undef;
423 0 } elsif((my $wget) = grep { -x "$_/wget" } Env::Path->PATH->List) {
424 0 ▶ open(my $wget_fh, '-|', 'wget', '--no-check-certificate', '-qO', '-', $url) || do {
Branch: 1 branch
BranchTrueFalseTotal
open my $wget_fh, "-|", "wget", "--no-check-certificate", "-qO", "-", $url or do { warn "Couldn't wget: $!\n"; return undef } 0 0 0
425 0 warn("Couldn't wget: $!\n");
426 0 return undef;
427 };
428 0 return join('', <$wget_fh>);
429 } else {
430 0 die("Ohnoes! No LWP::Protocol::https and couldn't wget either.\n");
431 }
432 }
433  
434 1921 ▶sub _incore {
Subroutine _incore: called CC=4 SCAR=13.9
435 1921 my $self = shift;
436 1921 my %args = @_;
437 1921 my $core = $Module::CoreList::version{$args{perl}}{$args{module}};
438 1921 ▶ $core =~ s/_/00/g if($core);
Branch: 1 branch
BranchTrueFalseTotal
if $core 1551 370 1921
439 1921 $args{version} =~ s/_/00/g;
440 1921 ▶ return ($core && $core >= $args{version}) ? $core : undef;
Branch: 1 branch
BranchTrueFalseTotal
$core && $core >= $args{'version'} ? : 1525 396 1921
Condition100%3/3
$core and $core >= $args{"version"}
!ll&&!rl&&r
370261525
MC/DC100%2/2
$core and $core >= $args{"version"}
$core $core >= $args{"version"}
Truth table100%3/3
A and B
A= $coreB= $core >= $args{"version"}
ABresult
0X0
100
111
441 }
442  
443 2048 ▶sub _finddeps {
Subroutine _finddeps: called CC=11 SCAR=24.0
444 2048 my $self = shift;
445 2048 my %args = @_;
446 2048 my( $module, $depth, $version) = @args{qw(module depth version)};
447 2048 ▶ $depth ||= 0;
Condition100%2/2
$depth ||= 0
l!l
201236
MC/DC100%1/1
$depth ||= 0
$depth
Truth table100%2/2
A
A= $depth
Aresult
11
00
448  
449 return () if(
450 $module eq 'perl' ||
451 $self->_incore(
452 module => $module,
453 perl => $self->{perl},
454 2048 ▶ version => $version)
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "perl" or $self->_incore("module", $module, "perl", $self->{"perl"}, "version", $version) 1652 396 2048
Condition100%3/3
$module eq "perl" or $self->_incore("module", $module, "perl", $self->{"perl"}, "version", $version)
l!l&&r!l&&!r
1271525396
MC/DC100%2/2
$module eq "perl" or $self->_incore("module", $module, "perl", $self->{"perl"}, "version", $version)
$module eq "perl" $self->_incore("module", $module, "perl", $self->{"perl"}, "version", $version)
Truth table100%3/3
A or B
A= $module eq "perl"B= $self->_incore("module", $module, "perl", $self->{"perl"}, "version", $version)
ABresult
1X1
011
000
455 );
456  
457 396 my $dist = do {
458 396 my $package = $self->_first_found($module);
459 396 ▶ $package ? $package->distribution() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 384 12 396
460 };
461  
462 396 ▶ return () unless(blessed($dist));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($dist) 12 384 396
463  
464 384 my $author = $dist->cpanid();
465 384 my $distname = $dist->distvname();
466  
467 384 ▶ return () if($self->{seen}->{$distname}++);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen"}{$distname}++ 127 257 384
468  
469 257 my %reqs = $self->_getreqs(
470 author => $author,
471 distname => $distname,
472 distfile => $dist->filename(),
473 );
474  
475 return (
476 CPAN::FindDependencies::Dependency->_new(
477 depth => $depth,
478 distribution => $dist,
479 cpanmodule => $module,
480 indices => [$self->_indices()],
481 version => $version || 0,
482 $reqs{'-warning'} ? (warning => $reqs{'-warning'}) : ()
483 ),
484 (!exists($reqs{'-warning'}) && $depth != $self->{maxdepth}) ? (map {
485 # print "Looking at $_\n";
486 252 ▶ $self->_finddeps(
Branch: 2 branches
BranchTrueFalseTotal
$reqs{'-warning'} ? : 12 240 252
!exists $reqs{'-warning'} && $depth != $self->{'maxdepth'} ? : 229 23 252
Condition100%5/5
$version || 0
l!l
147105
not exists $reqs{"-warning"} and $depth != $self->{"maxdepth"}
!ll&&!rl&&r
1211229
MC/DC100%1/1
$version || 0
$version
MC/DC100%2/2
not exists $reqs{"-warning"} and $depth != $self->{"maxdepth"}
not exists $reqs{"-warning"} $depth != $self->{"maxdepth"}
Truth table100%2/2
A
A= $version
Aresult
11
00
Truth table100%3/3
not(A) and B
A= not exists $reqs{"-warning"}B= $depth != $self->{"maxdepth"}
ABresult
0X0
100
111
487 module => $_,
488 depth => $depth + 1,
489 2012 version => $reqs{$_}
490 );
491 } sort keys %reqs) : ()
492 );
493 }
494  
495 # caching wrapper around _get
496 # can be asked to fetch a .meta, an archive, or a Makefile.PL,
497 # so it knows how to figure out what the cache filename is
498 # for those, based on the URL
499 # can be asked to get whichever first succeeds of multiple options.
500 # currently those are always a metadata file or an archive, which
501 # will resolve to the same cache file.
502 780 ▶sub _get_cached {
Subroutine _get_cached: called CC=15 SCAR=27.1
503 780 my $self = shift;
504 780 my %args = @_;
505 780 my($src, $post_process) = @args{qw(src post_process)};
506 780 my $contents;
507 # asked to check multiple sources? Return the first which has
508 # content (or what's cached)
509 780 ▶ if(ref($src)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src) 336 444 780
510 336 foreach my $this_url (@{$src}) {
511 435 ▶ last if($contents = $self->_get_cached(
Branch: 1 branch
BranchTrueFalseTotal
if $contents = $self->_get_cached("post_process", $post_process, "src", $this_url) 243 192 435
512 post_process => $post_process,
513 src => $this_url
514 ));
515 }
516 336 return $contents;
517 }
518  
519 444 my $cachefile = $src;
520 444 ▶ if($cachefile =~ /Makefile.PL/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cachefile =~ /Makefile.PL/) { } 9 435 444
521 9 $cachefile =~ s{.*/([^/]+)/Makefile.PL$}{$1.MakefilePL};
522 } else {
523 435 $cachefile =~ s{.*/(.*?)\.(meta|zip|tar\.bz2|tar\.gz|tgz)$}{$1.meta};
524 }
525  
526 444 ▶ if($self->{cachedir} && -d $self->{cachedir} && -r $self->{cachedir}."/$cachefile") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cachedir'} and -d $self->{'cachedir'} and -r $self->{'cachedir'} . "/$cachefile") { } 162 282 444
Condition83%5/6
$self->{"cachedir"} and -d $self->{"cachedir"} and -r $self->{"cachedir"} . "/$cachefile"
!ll&&!rl&&r
8274162
$self->{"cachedir"} and -d $self->{"cachedir"}
!ll&&!rl&&r
80436
MC/DC66%2/3
$self->{"cachedir"} and -d $self->{"cachedir"} and -r $self->{"cachedir"} . "/$cachefile"
$self->{"cachedir"} -d $self->{"cachedir"} -r $self->{"cachedir"} . "/$cachefile"
Truth table75%3/4
A and B and C
A= $self->{"cachedir"}B= -d $self->{"cachedir"}C= -r $self->{"cachedir"} . "/$cachefile"
ABCresult
0XX0
10X0
1100
1111
527 open(my $cachefh, $self->{cachedir}."/$cachefile") ||
528 162 ▶ $self->_yell('Error reading '.$self->{cachedir}."/$cachefile: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $cachefh, $self->{"cachedir"} . "/$cachefile" or $self->_yell('Error reading ' . $self->{"cachedir"} . "/${cachefile}: $!") 162 0 162
529 162 local $/ = undef;
530 162 $contents = <$cachefh>;
531 162 close($cachefh);
532 } else {
533 282 $contents = $self->_get($src);
534 282 ▶ if($contents && $post_process ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents and $post_process) 102 180 282
Condition100%3/3
$contents and $post_process
!ll&&!rl&&r
1782102
MC/DC100%2/2
$contents and $post_process
$contents $post_process
Truth table100%3/3
A and B
A= $contentsB= $post_process
ABresult
0X0
100
111
535 102 $contents = $post_process->($contents);
536 }
537 282 ▶ if($contents && $self->{cachedir} && -d $self->{cachedir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents and $self->{"cachedir"} and -d $self->{"cachedir"}) 88 194 282
Condition83%5/6
$contents and $self->{"cachedir"} and -d $self->{"cachedir"}
!ll&&!rl&&r
194088
$contents and $self->{"cachedir"}
!ll&&!rl&&r
192288
MC/DC66%2/3
$contents and $self->{"cachedir"} and -d $self->{"cachedir"}
$contents $self->{"cachedir"} -d $self->{"cachedir"}
Truth table75%3/4
A and B and C
A= $contentsB= $self->{"cachedir"}C= -d $self->{"cachedir"}
ABCresult
0XX0
10X0
1100
1111
538 open(my $cachefh, '>', $self->{cachedir}."/$cachefile") ||
539 88 ▶ $self->_yell('Error writing '.$self->{cachedir}."/$cachefile: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $cachefh, ">", $self->{"cachedir"} . "/$cachefile" or $self->_yell('Error writing ' . $self->{"cachedir"} . "/${cachefile}: $!") 88 0 88
540 88 print $cachefh $contents;
541 88 close($cachefh);
542 }
543 }
544 444 return $contents;
545 }
546  
547 257 ▶sub _getreqs {
Subroutine _getreqs: called CC=11 SCAR=24.1
548 257 my $self = shift;
549 257 my %args = @_;
550 257 my($author, $distname, $distfile) = @args{qw(author distname distfile)};
551  
552 257 my $meta_file;
553 257 foreach my $source (@{$self->{mirrors}}) {
554 $meta_file = $self->_get_cached(
555 src => [
556 $source->{mirror}."authors/id/".
557 substr($author, 0, 1).'/'.
558 substr($author, 0, 2).'/'.
559 "$author/$distname.meta",
560 $source->{mirror}."authors/id/".
561 substr($author, 0, 1).'/'.
562 substr($author, 0, 2).'/'.
563 "$author/$distfile"
564 ],
565 102 ▶ post_process => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
566 # _get_cached normally just returns a file, but we're
567 # asking it to either fetch a metadata file or if that can't be
568 # found fetch an archive from which we want to extract a file,
569 # and then cache that extracted file's contents. This function
570 # takes a blob of data and if it looks like a zip or a tarball
571 # tries to extract a META.json or META.yml and return its content
572 # (or the empty string if not found), otherwise if it doesn't
573 # look like an archive, assume that the input was a valid metadata
574 # file after all and just return it.
575 102 my $file_data = shift;
576 102 my $meta_file_re = qr/^([^\/]+\/)?META\.(json|yml)/;
577 102 my $rval = '';
578  
579 # We should be able to avoid writing to disk by something like
580 # this but it doesn't work, for either zip or tar <shrug>
581 # # my $tar = Archive::Tar->new();
582 # # $tar->read([string opened as file])
583 102 my(undef, $tempfile) = tempfile('CPAN-FindDependencies-XXXXXXXX', TMPDIR => 1, OPEN => 0);
584 102 ▶ open(my $fh, '>', "$tempfile") || die("Can't write $tempfile: $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$tempfile" or die "Can't write ${tempfile}: $!\n" 102 0 102
585 102 binmode($fh); # Windows smells of wee
586 102 print $fh $file_data;
587 102 close($fh);
588  
589 102 ▶ if(File::Type->mime_type($file_data) eq 'application/zip') {
Branch: 2 branches
BranchTrueFalseTotal
if ('File::Type'->mime_type($file_data) eq 'application/zip') { } 2 100 102
elsif ('File::Type'->mime_type($file_data) =~ m[^application/x-(bzip2|gzip|tar)$]) { } 18 82 100
590 2 my $zip = Archive::Zip->new($tempfile);
591 2 ▶ if(my @members = sort { $a cmp $b } $zip->membersMatching($meta_file_re)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@members) = (sort {$a cmp $b;} $zip->membersMatching($meta_file_re))) 2 0 2
592 2 $rval = $zip->contents($members[0])
593 }
594 } elsif(File::Type->mime_type($file_data) =~ m{^application/x-(bzip2|gzip|tar)$}) {
595 18 ▶ $rval = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
596 18 my $tar = Archive::Tar->new(shift());
597 # sort to ensure that we get JSON by preference, META.json
598 # often contains more info
599 18 ▶ if(my @members = sort { $a cmp $b } grep { /$meta_file_re/ } $tar->list_files()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@members) = (sort {$a cmp $b;} grep({/$meta_file_re/;} $tar->list_files))) 4 14 18
600 4 return $tar->get_content($members[0])
601 }
602 18 }->($tempfile);
603 82 } else { $rval = $file_data; } # oh, it must have been a meta file
604  
605 102 unlink $tempfile;
606  
607 102 return $rval;
608 },
609 336 );
610 336 ▶ last if($meta_file);
Branch: 1 branch
BranchTrueFalseTotal
if $meta_file 243 93 336
611 }
612 257 ▶ if ($meta_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_file) { } 243 14 257
613 243 my $meta_data = eval {
614 1 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
615 1 warn(join("\n", "In $distfile, $_[0]", @_[1 .. $#_]));
616 243 };
617 243 CPAN::Meta->load_string($meta_file);
618 };
619 243 ▶ if ($@ || !defined($meta_data)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $meta_data) { } 7 236 243
Condition66%2/3
$@ or not defined $meta_data
l!l&&r!l&&!r
70236
MC/DC50%1/2
$@ or not defined $meta_data
$@ not defined $meta_data
Truth table66%2/3
A or not(B)
A= $@B= not defined $meta_data
ABresult
1X1
011
000
620 7 $self->_yell("$author/$distname: failed to parse metadata")
621 } else {
622 236 my $reqs = $meta_data->effective_prereqs();
623 return %{
624 236 $reqs->merged_requirements(
625 [qw(configure build test runtime)],
626 [
627 'requires',
628 ($self->{recommended} ? 'recommends' : ()),
629 236 ▶ ($self->{suggested} ? 'suggests' : ())
Branch: 2 branches
BranchTrueFalseTotal
$self->{'recommended'} ? : 3 233 236
$self->{'suggested'} ? : 0 236 236
630 ]
631 )->as_string_hash()
632 };
633 }
634 } else {
635 14 $self->_yell("$author/$distname: no metadata");
636 }
637
638 # We could have failed to parse the metadata file, but we still want to try the Makefile.PL
639 20 ▶ if(!$self->{usemakefilepl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'usemakefilepl'}) { } 11 9 20
640 11 return ('-warning', 'no metadata');
641 } else {
642 9 my $makefilepl = $self->_get_cached(
643 src => "https://fastapi.metacpan.org/source/$author/$distname/Makefile.PL",
644 );
645 9 ▶ if($makefilepl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($makefilepl) { } 9 0 9
646 9 my $result = getreqs_from_mm($makefilepl);
647 5 ▶ if ('HASH' eq ref $result) {
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $result) { } 4 1 5
648 4 return %{ $result };
649 } else {
650 1 $self->_yell("$author/$distname: $result");
651 1 return ('-warning', $result);
652 }
653 } else {
654 0 $self->_yell("$author/$distname: no metadata nor Makefile.PL");
655 0 return ('-warning', 'no metadata nor Makefile.PL');
656 }
657 }
658 }
659  
660 34 1;
↑ Summary lib/CPAN/FindDependencies/MakeMaker.pm »