blib/lib/App/Cpan.pm

filter: Statementstmt 40.3% 254 / 629 Branchbran 26.4% 56 / 212 Conditioncond 37.9% 22 / 58 MC/DCmcdc 19.4% 7 / 36 Subroutinesub 52.7% 57 / 108 Podpod 100% 1 / 1 totaltotal 38.0% 397 / 1044 CC 159 SCAR 32.1
CC
159
Cov
37%
_guess_at_module_name
133.3
_show_Details
90.0
_parse_version_safely
90.0
CRAP 24.7
« blib/lib/CPAN/HTTP/Client.pm ↑ Summary blib/lib/CPAN/Exception/yaml_process_error.pm »
1 package App::Cpan;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use if $] < 5.008 => 'IO::Scalar';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 15 $VERSION = '1.679';
10  
11 =head1 NAME
12  
13 App::Cpan - easily interact with CPAN from the command line
14  
15 =head1 SYNOPSIS
16  
17 # with arguments and no switches, installs specified modules
18 cpan module_name [ module_name ... ]
19  
20 # with switches, installs modules with extra behavior
21 cpan [-cfFimtTw] module_name [ module_name ... ]
22  
23 # use local::lib
24 cpan -I module_name [ module_name ... ]
25  
26 # one time mirror override for faster mirrors
27 cpan -p ...
28  
29 # with just the dot, install from the distribution in the
30 # current directory
31 cpan .
32  
33 # without arguments, starts CPAN.pm shell
34 cpan
35  
36 # without arguments, but some switches
37 cpan [-ahpruvACDLOPX]
38  
39 =head1 DESCRIPTION
40  
41 This script provides a command interface (not a shell) to CPAN. At the
42 moment it uses CPAN.pm to do the work, but it is not a one-shot command
43 runner for CPAN.pm.
44  
45 =head2 Options
46  
47 =over 4
48  
49 =item -a
50  
51 Creates a CPAN.pm autobundle with CPAN::Shell->autobundle.
52  
53 =item -A module [ module ... ]
54  
55 Shows the primary maintainers for the specified modules.
56  
57 =item -c module
58  
59 Runs a `make clean` in the specified module's directories.
60  
61 =item -C module [ module ... ]
62  
63 Show the F<Changes> files for the specified modules
64  
65 =item -D module [ module ... ]
66  
67 Show the module details. This prints one line for each out-of-date module
68 (meaning, modules locally installed but have newer versions on CPAN).
69 Each line has three columns: module name, local version, and CPAN
70 version.
71  
72 =item -f
73  
74 Force the specified action, when it normally would have failed. Use this
75 to install a module even if its tests fail. When you use this option,
76 -i is not optional for installing a module when you need to force it:
77  
78 % cpan -f -i Module::Foo
79  
80 =item -F
81  
82 Turn off CPAN.pm's attempts to lock anything. You should be careful with
83 this since you might end up with multiple scripts trying to muck in the
84 same directory. This isn't so much of a concern if you're loading a special
85 config with C<-j>, and that config sets up its own work directories.
86  
87 =item -g module [ module ... ]
88  
89 Downloads to the current directory the latest distribution of the module.
90  
91 =item -G module [ module ... ]
92  
93 UNIMPLEMENTED
94  
95 Download to the current directory the latest distribution of the
96 modules, unpack each distribution, and create a git repository for each
97 distribution.
98  
99 If you want this feature, check out Yanick Champoux's C<Git::CPAN::Patch>
100 distribution.
101  
102 =item -h
103  
104 Print a help message and exit. When you specify C<-h>, it ignores all
105 of the other options and arguments.
106  
107 =item -i module [ module ... ]
108  
109 Install the specified modules. With no other switches, this switch
110 is implied.
111  
112 =item -I
113  
114 Load C<local::lib> (think like C<-I> for loading lib paths). Too bad
115 C<-l> was already taken.
116  
117 =item -j Config.pm
118  
119 Load the file that has the CPAN configuration data. This should have the
120 same format as the standard F<CPAN/Config.pm> file, which defines
121 C<$CPAN::Config> as an anonymous hash.
122  
123 If the file does not exist, C<cpan> dies.
124  
125 =item -J
126  
127 Dump the configuration in the same format that CPAN.pm uses. This is useful
128 for checking the configuration as well as using the dump as a starting point
129 for a new, custom configuration.
130  
131 =item -l
132  
133 List all installed modules with their versions
134  
135 =item -L author [ author ... ]
136  
137 List the modules by the specified authors.
138  
139 =item -m
140  
141 Make the specified modules.
142  
143 =item -M mirror1,mirror2,...
144  
145 A comma-separated list of mirrors to use for just this run. The C<-P>
146 option can find them for you automatically.
147  
148 =item -n
149  
150 Do a dry run, but don't actually install anything. (unimplemented)
151  
152 =item -O
153  
154 Show the out-of-date modules.
155  
156 =item -p
157  
158 Ping the configured mirrors and print a report
159  
160 =item -P
161  
162 Find the best mirrors you could be using and use them for the current
163 session.
164  
165 =item -r
166  
167 Recompiles dynamically loaded modules with CPAN::Shell->recompile.
168  
169 =item -s
170  
171 Drop in the CPAN.pm shell. This command does this automatically if you don't
172 specify any arguments.
173  
174 =item -t module [ module ... ]
175  
176 Run a `make test` on the specified modules.
177  
178 =item -T
179  
180 Do not test modules. Simply install them.
181  
182 =item -u
183  
184 Upgrade all installed modules. Blindly doing this can really break things,
185 so keep a backup.
186  
187 =item -v
188  
189 Print the script version and CPAN.pm version then exit.
190  
191 =item -V
192  
193 Print detailed information about the cpan client.
194  
195 =item -w
196  
197 UNIMPLEMENTED
198  
199 Turn on cpan warnings. This checks various things, like directory permissions,
200 and tells you about problems you might have.
201  
202 =item -x module [ module ... ]
203  
204 Find close matches to the named modules that you think you might have
205 mistyped. This requires the optional installation of Text::Levenshtein or
206 Text::Levenshtein::Damerau.
207  
208 =item -X
209  
210 Dump all the namespaces to standard output.
211  
212 =back
213  
214 =head2 Examples
215  
216 # print a help message
217 cpan -h
218  
219 # print the version numbers
220 cpan -v
221  
222 # create an autobundle
223 cpan -a
224  
225 # recompile modules
226 cpan -r
227  
228 # upgrade all installed modules
229 cpan -u
230  
231 # install modules ( sole -i is optional )
232 cpan -i Netscape::Booksmarks Business::ISBN
233  
234 # force install modules ( must use -i )
235 cpan -fi CGI::Minimal URI
236  
237 # install modules but without testing them
238 cpan -Ti CGI::Minimal URI
239  
240 =head2 Environment variables
241  
242 There are several components in CPAN.pm that use environment variables.
243 The build tools, L<ExtUtils::MakeMaker> and L<Module::Build> use some,
244 while others matter to the levels above them. Some of these are specified
245 by the Perl Toolchain Gang:
246  
247 Lancaster Consensus: L<https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>
248  
249 Oslo Consensus: L<https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/oslo-consensus.md>
250  
251 =over 4
252  
253 =item NONINTERACTIVE_TESTING
254  
255 Assume no one is paying attention and skips prompts for distributions
256 that do that correctly. C<cpan(1)> sets this to C<1> unless it already
257 has a value (even if that value is false).
258  
259 =item PERL_MM_USE_DEFAULT
260  
261 Use the default answer for a prompted questions. C<cpan(1)> sets this
262 to C<1> unless it already has a value (even if that value is false).
263  
264 =item CPAN_OPTS
265  
266 As with C<PERL5OPT>, a string of additional C<cpan(1)> options to
267 add to those you specify on the command line.
268  
269 =item CPANSCRIPT_LOGLEVEL
270  
271 The log level to use, with either the embedded, minimal logger or
272 L<Log::Log4perl> if it is installed. Possible values are the same as
273 the C<Log::Log4perl> levels: C<TRACE>, C<DEBUG>, C<INFO>, C<WARN>,
274 C<ERROR>, and C<FATAL>. The default is C<INFO>.
275  
276 =item GIT_COMMAND
277  
278 The path to the C<git> binary to use for the Git features. The default
279 is C</usr/local/bin/git>.
280  
281 =back
282  
283 =head2 Methods
284  
285 =over 4
286  
287 =cut
288  
289 15 ▶use autouse Carp => qw(carp croak cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
290 15 ▶use CPAN 1.80 (); # needs no test
Subroutine BEGIN: called CC=1 SCAR=0.0
291 15 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
292 15 ▶use autouse Cwd => qw(cwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
293 15 ▶use autouse 'Data::Dumper' => qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
294 15 ▶use File::Spec::Functions qw(catfile file_name_is_absolute rel2abs);
Subroutine BEGIN: called CC=1 SCAR=0.0
295 15 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
296 15 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
297  
298 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
299 # Internal constants
300 15 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
301 15 ▶use constant FALSE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
302  
303  
304 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
305 # The return values
306 15 ▶use constant HEY_IT_WORKED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
307 15 ▶use constant I_DONT_KNOW_WHAT_HAPPENED => 1; # 0b0000_0001
Subroutine BEGIN: called CC=1 SCAR=0.0
308 15 ▶use constant ITS_NOT_MY_FAULT => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
309 15 ▶use constant THE_PROGRAMMERS_AN_IDIOT => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
310 15 ▶use constant A_MODULE_FAILED_TO_INSTALL => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
311  
312  
313 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
314 # set up the order of options that we layer over CPAN::Shell
315 15 ▶BEGIN { # most of this should be in methods
Subroutine BEGIN: called CC=1 SCAR=0.0
316 15 ▶use vars qw( @META_OPTIONS $Default %CPAN_METHODS @CPAN_OPTIONS @option_order
Subroutine BEGIN: called CC=1 SCAR=0.0
317 15 %Method_table %Method_table_index );
318  
319 15 @META_OPTIONS = qw( h v V I g G M: C A D O l L a r p P j: J w x X );
320  
321 15 $Default = 'default';
322  
323 15 %CPAN_METHODS = ( # map switches to method names in CPAN::Shell
324 $Default => 'install',
325 'c' => 'clean',
326 'f' => 'force',
327 'i' => 'install',
328 'm' => 'make',
329 't' => 'test',
330 'u' => 'upgrade',
331 'T' => 'notest',
332 's' => 'shell',
333 );
334 15 @CPAN_OPTIONS = grep { $_ ne $Default } sort keys %CPAN_METHODS;
335  
336 15 @option_order = ( @META_OPTIONS, @CPAN_OPTIONS );
337  
338  
339 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
340 # map switches to the subroutines in this script, along with other information.
341 # use this stuff instead of hard-coded indices and values
342 sub NO_ARGS () { 0 }
343 sub ARGS () { 1 }
344 sub GOOD_EXIT () { 0 }
345  
346 15 %Method_table = (
347 # key => [ sub ref, takes args?, exit value, description ]
348  
349 # options that do their thing first, then exit
350 h => [ \&_print_help, NO_ARGS, GOOD_EXIT, 'Printing help' ],
351 v => [ \&_print_version, NO_ARGS, GOOD_EXIT, 'Printing version' ],
352 V => [ \&_print_details, NO_ARGS, GOOD_EXIT, 'Printing detailed version' ],
353 X => [ \&_list_all_namespaces, NO_ARGS, GOOD_EXIT, 'Listing all namespaces' ],
354  
355 # options that affect other options
356 j => [ \&_load_config, ARGS, GOOD_EXIT, 'Use specified config file' ],
357 J => [ \&_dump_config, NO_ARGS, GOOD_EXIT, 'Dump configuration to stdout' ],
358 F => [ \&_lock_lobotomy, NO_ARGS, GOOD_EXIT, 'Turn off CPAN.pm lock files' ],
359 I => [ \&_load_local_lib, NO_ARGS, GOOD_EXIT, 'Loading local::lib' ],
360 M => [ \&_use_these_mirrors, ARGS, GOOD_EXIT, 'Setting per session mirrors' ],
361 P => [ \&_find_good_mirrors, NO_ARGS, GOOD_EXIT, 'Finding good mirrors' ],
362 w => [ \&_turn_on_warnings, NO_ARGS, GOOD_EXIT, 'Turning on warnings' ],
363  
364 # options that do their one thing
365 g => [ \&_download, ARGS, GOOD_EXIT, 'Download the latest distro' ],
366 G => [ \&_gitify, ARGS, GOOD_EXIT, 'Down and gitify the latest distro' ],
367  
368 C => [ \&_show_Changes, ARGS, GOOD_EXIT, 'Showing Changes file' ],
369 A => [ \&_show_Author, ARGS, GOOD_EXIT, 'Showing Author' ],
370 D => [ \&_show_Details, ARGS, GOOD_EXIT, 'Showing Details' ],
371 O => [ \&_show_out_of_date, NO_ARGS, GOOD_EXIT, 'Showing Out of date' ],
372 l => [ \&_list_all_mods, NO_ARGS, GOOD_EXIT, 'Listing all modules' ],
373  
374 L => [ \&_show_author_mods, ARGS, GOOD_EXIT, 'Showing author mods' ],
375 a => [ \&_create_autobundle, NO_ARGS, GOOD_EXIT, 'Creating autobundle' ],
376 p => [ \&_ping_mirrors, NO_ARGS, GOOD_EXIT, 'Pinging mirrors' ],
377  
378 r => [ \&_recompile, NO_ARGS, GOOD_EXIT, 'Recompiling' ],
379 u => [ \&_upgrade, NO_ARGS, GOOD_EXIT, 'Running `make test`' ],
380 's' => [ \&_shell, NO_ARGS, GOOD_EXIT, 'Drop into the CPAN.pm shell' ],
381  
382 'x' => [ \&_guess_namespace, ARGS, GOOD_EXIT, 'Guessing namespaces' ],
383 c => [ \&_default, ARGS, GOOD_EXIT, 'Running `make clean`' ],
384 f => [ \&_default, ARGS, GOOD_EXIT, 'Installing with force' ],
385 i => [ \&_default, ARGS, GOOD_EXIT, 'Running `make install`' ],
386 'm' => [ \&_default, ARGS, GOOD_EXIT, 'Running `make`' ],
387 t => [ \&_default, ARGS, GOOD_EXIT, 'Running `make test`' ],
388 T => [ \&_default, ARGS, GOOD_EXIT, 'Installing with notest' ],
389 );
390  
391 15 %Method_table_index = (
392 code => 0,
393 takes_args => 1,
394 exit_value => 2,
395 description => 3,
396 );
397 }
398  
399  
400 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
401 # finally, do some argument processing
402  
403 sub _stupid_interface_hack_for_non_rtfmers
404 14 ▶ {
Subroutine _stupid_interface_hack_for_non_rtfmers: called CC=3 SCAR=11.0
405 15 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
406 14 ▶ shift @ARGV if( $ARGV[0] eq 'install' and @ARGV > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[0] eq "install" and @ARGV > 1 1 13 14
Condition100%3/3
$ARGV[0] eq "install" and @ARGV > 1
!ll&&!rl&&r
1211
MC/DC100%2/2
$ARGV[0] eq "install" and @ARGV > 1
$ARGV[0] eq "install" @ARGV > 1
Truth table100%3/3
A and B
A= $ARGV[0] eq "install"B= @ARGV > 1
ABresult
0X0
100
111
407 }
408  
409 sub _process_options
410 11 ▶ {
Subroutine _process_options: called CC=4 SCAR=13.9
411 11 my %options;
412  
413 11 ▶ push @ARGV, grep $_, split /\s+/, $ENV{CPAN_OPTS} || '';
Condition50%1/2
$ENV{'CPAN_OPTS'} || ''
l!l
011
MC/DC0%0/1
$ENV{'CPAN_OPTS'} || ''
$ENV{'CPAN_OPTS'}
Truth table50%1/2
A
A= $ENV{'CPAN_OPTS'}
Aresult
11
00
414  
415 # if no arguments, just drop into the shell
416 11 ▶ if( 0 == @ARGV ) { CPAN::shell(); exit 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (0 == @ARGV) { } 1 10 11
elsif (&Getopt::Std::getopts(join('', @App::Cpan::option_order), \%options)) { } 9 1 10
417 elsif (Getopt::Std::getopts(
418 join( '', @option_order ), \%options ))
419 {
420 9 \%options;
421 }
422 1 else { exit 1 }
423 }
424  
425 sub _process_setup_options
426 9 ▶ {
Subroutine _process_setup_options: called CC=10 SCAR=27.1
427 9 my( $class, $options ) = @_;
428  
429 9 ▶ if( $options->{j} )
Branch: 2 branches
BranchTrueFalseTotal
if ($options->{'j'}) { } 8 1 9
elsif (not $options->{'h'}) { } 0 1 1
430 {
431 8 $Method_table{j}[ $Method_table_index{code} ]->( $options->{j} );
432 8 delete $options->{j};
433 }
434 elsif ( ! $options->{h} ) { # h "ignores all of the other options and arguments"
435 # this is what CPAN.pm would do otherwise
436 0 local $CPAN::Be_Silent = 1;
437 0 CPAN::HandleConfig->load(
438 # be_silent => 1, deprecated
439 write_file => 0,
440 );
441 }
442  
443 9 ▶ $class->_turn_off_testing if $options->{T};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"T"} 0 9 9
444  
445 9 foreach my $o ( qw(F I w P M) )
446 {
447 45 ▶ next unless exists $options->{$o};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{$o} 45 0 45
448 0 $Method_table{$o}[ $Method_table_index{code} ]->( $options->{$o} );
449 0 delete $options->{$o};
450 }
451  
452 9 ▶ if( $options->{o} )
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"o"}) 0 9 9
453 {
454 0 my @pairs = map { [ split /=/, $_, 2 ] } split /,/, $options->{o};
455 0 foreach my $pair ( @pairs )
456 {
457 0 my( $setting, $value ) = @$pair;
458 0 $CPAN::Config->{$setting} = $value;
459 # $logger->debug( "Setting [$setting] to [$value]" );
460 }
461 0 delete $options->{o};
462 }
463  
464 9 my $option_count = grep { $options->{$_} } @option_order;
465 15 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
466  
467 # don't count options that imply installation
468 9 foreach my $opt ( qw(f T) ) { # don't count force or notest
469 18 $option_count -= $options->{$opt};
470 }
471  
472 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
473 # if there are no options, set -i (this line fixes RT ticket 16915)
474 9 ▶ $options->{i}++ unless $option_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $option_count 7 2 9
475 }
476  
477 9 ▶sub _setup_environment {
Subroutine _setup_environment: called CC=3 SCAR=12.0
478 # should we override or set defaults? If this were a true interactive
479 # session, we'd be in the CPAN shell.
480  
481 # https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md
482 9 ▶ $ENV{NONINTERACTIVE_TESTING} = 1 unless defined $ENV{NONINTERACTIVE_TESTING};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"NONINTERACTIVE_TESTING"} 0 9 9
483 9 ▶ $ENV{PERL_MM_USE_DEFAULT} = 1 unless defined $ENV{PERL_MM_USE_DEFAULT};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"PERL_MM_USE_DEFAULT"} 0 9 9
484 }
485  
486 =item run( ARGS )
487  
488 Just do it.
489  
490 The C<run> method returns 0 on success and a positive number on
491 failure. See the section on EXIT CODES for details on the values.
492  
493 =cut
494  
495 15 my $logger;
496  
497 sub run
498 10 ▶ {
Subroutine run: called CC=6 SCAR=18.1
Pod documented
499 10 my( $class, @args ) = @_;
500 10 local @ARGV = @args;
501 10 my $return_value = HEY_IT_WORKED; # assume that things will work
502  
503 10 $logger = $class->_init_logger;
504 10 $logger->debug( "Using logger from @{[ref $logger]}" );
505  
506 10 $class->_hook_into_CPANpm_report;
507 10 $logger->debug( "Hooked into output" );
508  
509 10 $class->_stupid_interface_hack_for_non_rtfmers;
510 10 $logger->debug( "Patched cargo culting" );
511  
512 10 my $options = $class->_process_options;
513 9 $logger->debug( "Options are @{[Dumper($options)]}" );
514  
515 9 $class->_process_setup_options( $options );
516  
517 9 $class->_setup_environment( $options );
518  
519 9 OPTION: foreach my $option ( @option_order )
520 {
521 202 ▶ next unless $options->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{$option} 193 9 202
522  
523 my( $sub, $takes_args, $description ) =
524 9 map { $Method_table{$option}[ $Method_table_index{$_} ] }
525 qw( code takes_args description );
526  
527 9 ▶ unless( ref $sub eq ref sub {} )
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sub eq ref sub { } ) 0 9 9
528 {
529 0 $return_value = THE_PROGRAMMERS_AN_IDIOT;
530 0 last OPTION;
531 }
532  
533 9 ▶ $logger->info( "[$option] $description -- ignoring other arguments" )
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV and not $takes_args 0 9 9
Condition66%2/3
@ARGV and not $takes_args
!ll&&!rl&&r
270
MC/DC0%0/2
@ARGV and not $takes_args
@ARGV not $takes_args
Truth table66%2/3
A and not(B)
A= @ARGVB= not $takes_args
ABresult
0X0
100
111
534 if( @ARGV && ! $takes_args );
535  
536 9 $return_value = $sub->( \ @ARGV, $options );
537  
538 6 last;
539 }
540  
541 6 return $return_value;
542 }
543  
544 my $LEVEL;
545 {
546 package
547 Local::Null::Logger; # hide from PAUSE
548  
549 15 my @LOGLEVELS = qw(TRACE DEBUG INFO WARN ERROR FATAL);
550 15 ▶$LEVEL = uc($ENV{CPANSCRIPT_LOGLEVEL} || 'INFO');
Condition100%2/2
$ENV{'CPANSCRIPT_LOGLEVEL'} || 'INFO'
l!l
114
MC/DC100%1/1
$ENV{'CPANSCRIPT_LOGLEVEL'} || 'INFO'
$ENV{'CPANSCRIPT_LOGLEVEL'}
Truth table100%2/2
A
A= $ENV{'CPANSCRIPT_LOGLEVEL'}
Aresult
11
00
551 15 my %LL = map { $LOGLEVELS[$_] => $_ } 0..$#LOGLEVELS;
552 15 ▶unless (defined $LL{$LEVEL}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $LL{$LEVEL}) 0 15 15
553 0 warn "Unsupported loglevel '$LEVEL', setting to INFO";
554 0 $LEVEL = 'INFO';
555 }
556 12 ▶sub new { bless \ my $x, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
557 83 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
558 83 my $autoload = our $AUTOLOAD;
559 83 $autoload =~ s/.*://;
560 83 ▶ return if $LL{uc $autoload} < $LL{$LEVEL};
Branch: 1 branch
BranchTrueFalseTotal
if $LL{uc $autoload} < $LL{$LEVEL} 78 5 83
561 $CPAN::Frontend->mywarn(">($autoload): $_\n")
562 5 for split /[\r\n]+/, $_[1];
563 }
564 0 ▶sub DESTROY { 1 }
Subroutine DESTROY: not called CC=1 SCAR=6.9
565 }
566  
567 # load a module without searching the default entry for the current
568 # directory
569 15 ▶sub _safe_load_module {
Subroutine _safe_load_module: called CC=2 SCAR=7.0
570 12 my $name = shift;
571  
572 12 local @INC = @INC;
573 12 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 0 12 12
574  
575 12 eval "require $name; 1";
576 }
577  
578 sub _init_logger
579 12 ▶ {
Subroutine _init_logger: called CC=2 SCAR=7.6
580 12 my $log4perl_loaded = _safe_load_module("Log::Log4perl");
581  
582 12 ▶ unless( $log4perl_loaded )
Branch: 1 branch
BranchTrueFalseTotal
unless ($log4perl_loaded) 12 0 12
583 {
584 12 print STDOUT "Loading internal logger. Log::Log4perl recommended for better logging\n";
585 12 $logger = Local::Null::Logger->new;
586 12 return $logger;
587 }
588  
589 0 Log::Log4perl::init( \ <<"HERE" );
590 log4perl.rootLogger=$LEVEL, A1
591 log4perl.appender.A1=Log::Log4perl::Appender::Screen
592 log4perl.appender.A1.layout=PatternLayout
593 log4perl.appender.A1.layout.ConversionPattern=%m%n
594 HERE
595  
596 0 $logger = Log::Log4perl->get_logger( 'App::Cpan' );
597 }
598  
599 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
600 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
601 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
602  
603 sub _default
604 7 ▶ {
Subroutine _default: called CC=19 SCAR=34.4
605 7 my( $args, $options ) = @_;
606  
607 7 my $switch = '';
608  
609 # choose the option that we're going to use
610 # we'll deal with 'f' (force) later, so skip it
611 7 foreach my $option ( @CPAN_OPTIONS )
612 {
613 28 ▶ next if ( $option eq 'f' or $option eq 'T' );
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "f" or $option eq "T" 14 14 28
Condition100%3/3
$option eq "f" or $option eq "T"
l!l&&r!l&&!r
7714
MC/DC100%2/2
$option eq "f" or $option eq "T"
$option eq "f" $option eq "T"
Truth table100%3/3
A or B
A= $option eq "f"B= $option eq "T"
ABresult
1X1
011
000
614 14 ▶ next unless $options->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{$option} 7 7 14
615 7 $switch = $option;
616 7 last;
617 }
618  
619 # 1. with no switches, but arguments, use the default switch (install)
620 # 2. with no switches and no args, start the shell
621 # 3. With a switch but no args, die! These switches need arguments.
622 0 ▶ if( not $switch and @$args ) { $switch = $Default; }
Branch: 3 branches
BranchTrueFalseTotal
if (not $switch and @$args) { } 0 7 7
elsif (not $switch || @$args) { } 0 7 7
elsif ($switch and not @$args) { } 0 7 7
Condition33%1/3
not $switch and @$args
!ll&&!rl&&r
700
MC/DC0%0/2
not $switch and @$args
not $switch @$args
Truth table33%1/3
not(A) and B
A= not $switchB= @$args
ABresult
0X0
100
111
623 0 ▶ elsif( not $switch and not @$args ) { return CPAN::shell() }
Condition33%1/3
$switch || @$args
l!l&&r!l&&!r
700
MC/DC0%0/2
$switch || @$args
$switch @$args
Truth table33%1/3
A || B
A= $switchB= @$args
ABresult
1X1
011
000
624 ▶ elsif( $switch and not @$args )
Condition33%1/3
$switch and not @$args
!ll&&!rl&&r
070
MC/DC0%0/2
$switch and not @$args
$switch not @$args
Truth table33%1/3
A and not(B)
A= $switchB= not @$args
ABresult
0X0
100
111
625 0 { die "Nothing to $CPAN_METHODS{$switch}!\n"; }
626  
627 # Get and check the method from CPAN::Shell
628 7 my $method = $CPAN_METHODS{$switch};
629 7 ▶ die "CPAN.pm cannot $method!\n" unless CPAN::Shell->can( $method );
Branch: 1 branch
BranchTrueFalseTotal
unless "CPAN::Shell"->can($method) 0 7 7
630  
631 # call the CPAN::Shell method, with force or notest if specified
632 7 my $action = do {
633 0 ▶ if( $options->{f} ) { sub { CPAN::Shell->force( $method, @_ ) } }
Subroutine __ANON__: not called CC=1 SCAR=1.7
Branch: 2 branches
BranchTrueFalseTotal
if ($options->{'f'}) { } 0 7 7
elsif ($options->{'T'}) { } 0 7 7
634 0 ▶ elsif( $options->{T} ) { sub { CPAN::Shell->notest( $method, @_ ) } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
635 7 ▶ else { sub { CPAN::Shell->$method( @_ ) } }
Subroutine __ANON__: called CC=1 SCAR=0.0
636 };
637  
638 # How do I handle exit codes for multiple arguments?
639 7 my @errors = ();
640  
641 7 ▶ $options->{x} or _disable_guessers();
Branch: 1 branch
BranchTrueFalseTotal
$options->{"x"} or _disable_guessers() 0 7 7
642  
643 7 foreach my $arg ( @$args )
644 {
645 # check the argument and perhaps capture typos
646 7 ▶ my $module = _expand_module( $arg ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $module = _expand_module($arg) or do { $logger->error("Skipping $arg because I couldn't find a matching namespace."); next } 7 0 7
647 0 $logger->error( "Skipping $arg because I couldn't find a matching namespace." );
648 0 next;
649 };
650  
651 7 _clear_cpanpm_output();
652 7 $action->( $arg );
653  
654 5 my $error = _cpanpm_output_indicates_failure();
655 5 ▶ push @errors, $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 4 1 5
656 }
657  
658 5 return do {
659 5 ▶ if( @errors ) { $errors[0] }
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) { } 4 1 5
660 1 else { HEY_IT_WORKED }
661 };
662  
663 }
664  
665 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
666  
667 =for comment
668  
669 CPAN.pm sends all the good stuff either to STDOUT, or to a temp
670 file if $CPAN::Be_Silent is set. I have to intercept that output
671 so I can find out what happened.
672  
673 =cut
674  
675 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
676 15 my $scalar = '';
677  
678 sub _hook_into_CPANpm_report
679 11 ▶ {
Subroutine _hook_into_CPANpm_report: called CC=1 SCAR=0.0
680 15 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
681  
682 1252 ▶ *CPAN::Shell::myprint = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
683 1252 my($self,$what) = @_;
684 1252 ▶ $scalar .= $what if defined $what;
Branch: 1 branch
BranchTrueFalseTotal
if defined $what 1252 0 1252
685 $self->print_ornamented($what,
686 1252 ▶ $CPAN::Config->{colorize_print}||'bold blue on_white',
Condition100%2/2
$CPAN::Config->{'colorize_print'} || 'bold blue on_white'
l!l
31249
MC/DC100%1/1
$CPAN::Config->{'colorize_print'} || 'bold blue on_white'
$CPAN::Config->{'colorize_print'}
Truth table100%2/2
A
A= $CPAN::Config->{'colorize_print'}
Aresult
11
00
687 );
688 11 };
689  
690 34 ▶ *CPAN::Shell::mywarn = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
691 34 my($self,$what) = @_;
692 34 ▶ $scalar .= $what if defined $what;
Branch: 1 branch
BranchTrueFalseTotal
if defined $what 34 0 34
693 $self->print_ornamented($what,
694 34 ▶ $CPAN::Config->{colorize_warn}||'bold red on_white'
Condition100%2/2
$CPAN::Config->{'colorize_warn'} || 'bold red on_white'
l!l
331
MC/DC100%1/1
$CPAN::Config->{'colorize_warn'} || 'bold red on_white'
$CPAN::Config->{'colorize_warn'}
Truth table100%2/2
A
A= $CPAN::Config->{'colorize_warn'}
Aresult
11
00
695 );
696 11 };
697  
698 }
699  
700 15 ▶sub _clear_cpanpm_output { $scalar = '' }
Subroutine _clear_cpanpm_output: called CC=1 SCAR=0.0
701  
702 11 ▶sub _get_cpanpm_output { $scalar }
Subroutine _get_cpanpm_output: called CC=1 SCAR=0.0
703  
704 # These are lines I don't care about in CPAN.pm output. If I can
705 # filter out the informational noise, I have a better chance to
706 # catch the error signal
707 15 my @skip_lines = (
708 qr/^\QWarning \(usually harmless\)/,
709 qr/\bwill not store persistent state\b/,
710 qr(//hint//),
711 qr/^\s+reports\s+/,
712 qr/^Try the command/,
713 qr/^\s+$/,
714 qr/^to find objects/,
715 qr/^\s*Database was generated on/,
716 qr/^Going to read/,
717 qr|^\s+i\s+/|, # the i /Foo::Whatever/ line when it doesn't know
718 );
719  
720 sub _get_cpanpm_last_line
721 34 ▶ {
Subroutine _get_cpanpm_last_line: called CC=4 SCAR=13.9
722 34 my $fh;
723  
724 34 ▶ if( $] < 5.008 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.008) { } 0 34 34
725 0 $fh = IO::Scalar->new( \ $scalar );
726 }
727 else {
728 34 eval q{ open $fh, '<', \\ $scalar; };
729 }
730  
731 34 my @lines = <$fh>;
732  
733 # This is a bit ugly. Once we examine a line, we have to
734 # examine the line before it and go through all of the same
735 # regexes. I could do something fancy, but this works.
736 REGEXES: {
737 34 foreach my $regex ( @skip_lines )
738 {
739 371 ▶ if( $lines[-1] =~ m/$regex/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[-1] =~ /$regex/) 11 360 371
740 {
741 11 pop @lines;
742 11 redo REGEXES; # we have to go through all of them for every line!
743 }
744 }
745 }
746  
747 34 $logger->debug( "Last interesting line of CPAN.pm output is:\n\t$lines[-1]" );
748  
749 34 $lines[-1];
750 }
751 }
752  
753 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
754 15 my $epic_fail_words = join '|',
755 qw( Error stop(?:ping)? problems force not unsupported
756 fail(?:ed)? Cannot\s+install );
757  
758 sub _cpanpm_output_indicates_failure
759 14 ▶ {
Subroutine _cpanpm_output_indicates_failure: called CC=3 SCAR=11.0
760 14 my $last_line = _get_cpanpm_last_line();
761  
762 14 my $result = $last_line =~ /\b(?:$epic_fail_words)\b/i;
763 14 ▶ return A_MODULE_FAILED_TO_INSTALL if $last_line =~ /\b(?:Cannot\s+install)\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if $last_line =~ /\b(?:Cannot\s+install)\b/i 0 14 14
764  
765 14 ▶ $result || ();
Branch: 1 branch
BranchTrueFalseTotal
$result or () 9 5 14
766 }
767 }
768  
769 sub _cpanpm_output_indicates_success
770 9 ▶ {
Subroutine _cpanpm_output_indicates_success: called CC=2 SCAR=6.9
771 9 my $last_line = _get_cpanpm_last_line();
772  
773 9 my $result = $last_line =~ /\b(?:\s+-- OK|PASS)\b/;
774 9 ▶ $result || ();
Branch: 1 branch
BranchTrueFalseTotal
$result or () 4 5 9
775 }
776  
777 sub _cpanpm_output_is_vague
778 0 ▶ {
Subroutine _cpanpm_output_is_vague: not called CC=3 SCAR=24.8
779 0 ▶ return FALSE if
Branch: 1 branch
BranchTrueFalseTotal
if _cpanpm_output_indicates_failure() or _cpanpm_output_indicates_success() 0 0 0
Condition0%0/3
_cpanpm_output_indicates_failure() or _cpanpm_output_indicates_success()
l!l&&r!l&&!r
000
MC/DC0%0/2
_cpanpm_output_indicates_failure() or _cpanpm_output_indicates_success()
_cpanpm_output_indicates_failure() _cpanpm_output_indicates_success()
Truth table0%0/3
A or B
A= _cpanpm_output_indicates_failure()B= _cpanpm_output_indicates_success()
ABresult
1X1
011
000
780 _cpanpm_output_indicates_failure() ||
781 _cpanpm_output_indicates_success();
782  
783 0 return TRUE;
784 }
785  
786 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
787 0 ▶sub _turn_on_warnings {
Subroutine _turn_on_warnings: not called CC=1 SCAR=6.9
788 0 carp "Warnings are implemented yet";
789 0 return HEY_IT_WORKED;
790 }
791  
792 0 ▶sub _turn_off_testing {
Subroutine _turn_off_testing: not called CC=1 SCAR=6.9
793 0 $logger->debug( 'Trusting test report history' );
794 0 $CPAN::Config->{trust_test_report_history} = 1;
795 0 return HEY_IT_WORKED;
796 }
797  
798 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
799 sub _print_help
800 1 ▶ {
Subroutine _print_help: called CC=2 SCAR=7.3
801 1 $logger->info( "Use perldoc to read the documentation" );
802 1 my $HAVE_PERLDOC = eval { require Pod::Perldoc; 1; };
803 1 ▶ if ($HAVE_PERLDOC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAVE_PERLDOC) { } 1 0 1
804 1 system qq{"$^X" -e "require Pod::Perldoc; Pod::Perldoc->run()" $0};
805 1 exit;
806 } else {
807 0 warn "Please install Pod::Perldoc, maybe try 'cpan -i Pod::Perldoc'\n";
808 0 return HEY_IT_WORKED;
809 }
810 }
811  
812 sub _print_version # -v
813 0 ▶ {
Subroutine _print_version: not called CC=1 SCAR=6.9
814 0 $logger->info(
815 "$0 script version $VERSION, CPAN.pm version " . CPAN->VERSION );
816  
817 0 return HEY_IT_WORKED;
818 }
819  
820 sub _print_details # -V
821 0 ▶ {
Subroutine _print_details: not called CC=5 SCAR=34.0
822 0 _print_version();
823  
824 0 _check_install_dirs();
825  
826 0 $logger->info( '-' x 50 . "\nChecking configured mirrors..." );
827 0 foreach my $mirror ( @{ $CPAN::Config->{urllist} } ) {
828 0 _print_ping_report( $mirror );
829 }
830  
831 0 $logger->info( '-' x 50 . "\nChecking for faster mirrors..." );
832  
833 {
834 0 require CPAN::Mirrors;
835  
836 0 ▶ if ( $CPAN::Config->{connect_to_internet_ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Config->{"connect_to_internet_ok"}) 0 0 0
837 0 $CPAN::Frontend->myprint(qq{Trying to fetch a mirror list from the Internet\n});
838 0 ▶ eval { CPAN::FTP->localize('MIRRORED.BY',File::Spec->catfile($CPAN::Config->{keep_source_where},'MIRRORED.BY'),3,1) }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "CPAN::FTP"->localize("MIRRORED.BY", "File::Spec"->catfile($CPAN::Config->{"keep_source_where"}, "MIRRORED.BY"), 3, 1) } } or $CPAN::Frontend->mywarn("We failed to get a copy of the mirror list from the Internet.\nYou will need to provide CPAN mirror URLs yourself.\n") 0 0 0
839 or $CPAN::Frontend->mywarn(<<'HERE');
840 We failed to get a copy of the mirror list from the Internet.
841 You will need to provide CPAN mirror URLs yourself.
842 HERE
843 0 $CPAN::Frontend->myprint("\n");
844 }
845  
846 0 my $mirrors = CPAN::Mirrors->new( _mirror_file() );
847 0 my @continents = $mirrors->find_best_continents;
848  
849 0 my @mirrors = $mirrors->get_mirrors_by_continents( $continents[0] );
850 0 my @timings = $mirrors->get_mirrors_timings( \@mirrors );
851  
852 0 foreach my $timing ( @timings ) {
853 0 $logger->info( sprintf "%s (%0.2f ms)",
854 $timing->hostname, $timing->rtt );
855 }
856 }
857  
858 0 return HEY_IT_WORKED;
859 }
860  
861 sub _check_install_dirs
862 0 ▶ {
Subroutine _check_install_dirs: not called CC=6 SCAR=37.4
863 0 my $makepl_arg = $CPAN::Config->{makepl_arg};
864 0 my $mbuildpl_arg = $CPAN::Config->{mbuildpl_arg};
865  
866 0 my @custom_dirs;
867 # PERL_MM_OPT
868 0 push @custom_dirs,
869 $makepl_arg =~ m/INSTALL_BASE\s*=\s*(\S+)/g,
870 $mbuildpl_arg =~ m/--install_base\s*=\s*(\S+)/g;
871  
872 0 ▶ if( @custom_dirs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@custom_dirs) 0 0 0
873 0 foreach my $dir ( @custom_dirs ) {
874 0 _print_inc_dir_report( $dir );
875 }
876 }
877  
878 # XXX: also need to check makepl_args, etc
879  
880 my @checks = (
881 [ 'core', [ grep $_, @Config{qw(installprivlib installarchlib)} ] ],
882 [ 'vendor', [ grep $_, @Config{qw(installvendorlib installvendorarch)} ] ],
883 [ 'site', [ grep $_, @Config{qw(installsitelib installsitearch)} ] ],
884 [ 'PERL5LIB', _split_paths( $ENV{PERL5LIB} ) ],
885 0 [ 'PERLLIB', _split_paths( $ENV{PERLLIB} ) ],
886 );
887  
888 0 $logger->info( '-' x 50 . "\nChecking install dirs..." );
889 0 foreach my $tuple ( @checks ) {
890 0 my( $label ) = $tuple->[0];
891  
892 0 $logger->info( "Checking $label" );
893 0 ▶ $logger->info( "\tno directories for $label" ) unless @{ $tuple->[1] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$tuple->[1];} 0 0 0
894 0 foreach my $dir ( @{ $tuple->[1] } ) {
895 0 _print_inc_dir_report( $dir );
896 }
897 }
898  
899 }
900  
901 sub _split_paths
902 0 ▶ {
Subroutine _split_paths: not called CC=2 SCAR=17.9
903 0 ▶ [ map { _expand_filename( $_ ) } split /$Config{path_sep}/, $_[0] || '' ];
Condition0%0/2
$_[0] || ''
l!l
00
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
904 }
905  
906  
907 =pod
908  
909 Stolen from File::Path::Expand
910  
911 =cut
912  
913 sub _expand_filename
914 9 ▶ {
Subroutine _expand_filename: called CC=3 SCAR=11.1
915 9 my( $path ) = @_;
916 15 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
917 9 $logger->debug( "Expanding path $path\n" );
918 9 $path =~ s{\A~([^/]+)?}{
919 3 ▶ _home_of( $1 || $> ) || "~$1"
Condition60%3/5
_home_of($1 || $>) || "~$1"
l!l
30
$1 || $>
l!l&&r!l&&!r
210
MC/DC0%0/1
_home_of($1 || $>) || "~$1"
_home_of($1 || $>)
MC/DC0%0/2
$1 || $>
$1 $>
Truth table50%1/2
A
A= _home_of($1 || $>)
Aresult
11
00
Truth table66%2/3
A || B
A= $1B= $>
ABresult
1X1
011
000
920 }e;
921 9 return $path;
922 }
923  
924 sub _home_of
925 0 ▶ {
Subroutine _home_of: not called CC=2 SCAR=17.9
926 0 require User::pwent;
927 0 my( $user ) = @_;
928 0 ▶ my $ent = User::pwent::getpw($user) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ent = User::pwent::getpw($user) or return 0 0 0
929 0 return $ent->dir;
930 }
931  
932 sub _get_default_inc
933 0 ▶ {
Subroutine _get_default_inc: not called CC=1 SCAR=6.9
934 0 require Config;
935  
936 0 [ @Config::Config{ _vars() }, '.' ];
937 }
938  
939 0 ▶sub _vars {
Subroutine _vars: not called CC=1 SCAR=6.9
940 0 qw(
941 installarchlib
942 installprivlib
943 installsitearch
944 installsitelib
945 );
946 }
947  
948 0 ▶sub _ping_mirrors {
Subroutine _ping_mirrors: not called CC=3 SCAR=24.8
949 0 my $urls = $CPAN::Config->{urllist};
950 0 require URI;
951  
952 0 foreach my $url ( @$urls ) {
953 0 my( $obj ) = URI->new( $url );
954 0 ▶ next unless _is_pingable_scheme( $obj );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_pingable_scheme($obj) 0 0 0
955 0 my $host = $obj->host;
956 0 _print_ping_report( $obj );
957 }
958  
959 }
960  
961 0 ▶sub _is_pingable_scheme {
Subroutine _is_pingable_scheme: not called CC=1 SCAR=6.9
962 0 my( $uri ) = @_;
963  
964 0 $uri->scheme eq 'file'
965 }
966  
967 0 ▶sub _mirror_file {
Subroutine _mirror_file: not called CC=2 SCAR=17.9
968 0 my $file = do {
969 0 my $file = 'MIRRORED.BY';
970 my $local_path = File::Spec->catfile(
971 0 $CPAN::Config->{keep_source_where}, $file );
972  
973 0 ▶ if( -e $local_path ) { $local_path }
Branch: 1 branch
BranchTrueFalseTotal
if (-e $local_path) { } 0 0 0
974 else {
975 0 require CPAN::FTP;
976 0 CPAN::FTP->localize( $file, $local_path, 3, 1 );
977 0 $local_path;
978 }
979 };
980 }
981  
982 0 ▶sub _find_good_mirrors {
Subroutine _find_good_mirrors: not called CC=3 SCAR=24.8
983 0 require CPAN::Mirrors;
984  
985 0 my $mirrors = CPAN::Mirrors->new( _mirror_file() );
986  
987 0 my @mirrors = $mirrors->best_mirrors(
988 how_many => 5,
989 verbose => 1,
990 );
991  
992 0 foreach my $mirror ( @mirrors ) {
993 0 ▶ next unless eval { $mirror->can( 'http' ) };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $mirror->can("http") } } 0 0 0
994 0 _print_ping_report( $mirror->http );
995 }
996  
997 $CPAN::Config->{urllist} = [
998 0 map { $_->http } @mirrors
999 ];
1000 }
1001  
1002 sub _print_inc_dir_report
1003 0 ▶ {
Subroutine _print_inc_dir_report: not called CC=2 SCAR=17.9
1004 0 my( $dir ) = shift;
1005  
1006 0 ▶ my $writeable = -w $dir ? '+' : '!!! (not writeable)';
Branch: 1 branch
BranchTrueFalseTotal
-w $dir ? : 0 0 0
1007 0 $logger->info( "\t$writeable $dir" );
1008 0 return -w $dir;
1009 }
1010  
1011 sub _print_ping_report
1012 0 ▶ {
Subroutine _print_ping_report: not called CC=2 SCAR=17.9
1013 0 my( $mirror ) = @_;
1014  
1015 0 my $rtt = eval { _get_ping_report( $mirror ) };
1016 0 ▶ my $result = $rtt ? sprintf "+ (%4d ms)", $rtt * 1000 : '!';
Branch: 1 branch
BranchTrueFalseTotal
$rtt ? : 0 0 0
1017  
1018 0 $logger->info(
1019 sprintf "\t%s %s", $result, $mirror
1020 );
1021 }
1022  
1023 sub _get_ping_report
1024 0 ▶ {
Subroutine _get_ping_report: not called CC=7 SCAR=40.3
1025 0 require URI;
1026 0 my( $mirror ) = @_;
1027 0 ▶ my( $url ) = ref $mirror ? $mirror : URI->new( $mirror ); #XXX
Branch: 1 branch
BranchTrueFalseTotal
ref $mirror ? : 0 0 0
1028 0 require Net::Ping;
1029  
1030 0 my $ping = Net::Ping->new( 'tcp', 1 );
1031  
1032 0 ▶ if( $url->scheme eq 'file' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "file") 0 0 0
1033 0 return -e $url->file;
1034 }
1035  
1036 0 my( $port ) = $url->port;
1037  
1038 0 ▶ return unless $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $port 0 0 0
1039  
1040 0 ▶ if ( $ping->can('port_number') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ping->can('port_number')) { } 0 0 0
1041 0 $ping->port_number($port);
1042 }
1043 else {
1044 0 $ping->{'port_num'} = $port;
1045 }
1046  
1047 0 ▶ $ping->hires(1) if $ping->can( 'hires' );
Branch: 1 branch
BranchTrueFalseTotal
if $ping->can("hires") 0 0 0
1048 0 my( $alive, $rtt ) = eval{ $ping->ping( $url->host ) };
1049 0 ▶ $alive ? $rtt : undef;
Branch: 1 branch
BranchTrueFalseTotal
$alive ? : 0 0 0
1050 }
1051  
1052 sub _load_local_lib # -I
1053 0 ▶ {
Subroutine _load_local_lib: not called CC=2 SCAR=17.9
1054 0 $logger->debug( "Loading local::lib" );
1055  
1056 0 my $rc = _safe_load_module("local::lib");
1057 0 ▶ unless( $rc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc) 0 0 0
1058 0 $logger->logdie( "Could not load local::lib" );
1059 }
1060  
1061 0 local::lib->import;
1062  
1063 0 return HEY_IT_WORKED;
1064 }
1065  
1066 sub _use_these_mirrors # -M
1067 0 ▶ {
Subroutine _use_these_mirrors: not called CC=2 SCAR=17.9
1068 0 $logger->debug( "Setting per session mirrors" );
1069 0 ▶ unless( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]) 0 0 0
1070 0 $logger->logdie( "The -M switch requires a comma-separated list of mirrors" );
1071 }
1072  
1073 0 $CPAN::Config->{urllist} = [ split /,/, $_[0] ];
1074  
1075 0 $logger->debug( "Mirrors are @{$CPAN::Config->{urllist}}" );
1076  
1077 }
1078  
1079 sub _create_autobundle
1080 0 ▶ {
Subroutine _create_autobundle: not called CC=1 SCAR=6.9
1081 0 $logger->info(
1082 "Creating autobundle in $CPAN::Config->{cpan_home}/Bundle" );
1083  
1084 0 CPAN::Shell->autobundle;
1085  
1086 0 return HEY_IT_WORKED;
1087 }
1088  
1089 sub _recompile
1090 0 ▶ {
Subroutine _recompile: not called CC=1 SCAR=6.9
1091 0 $logger->info( "Recompiling dynamically-loaded extensions" );
1092  
1093 0 CPAN::Shell->recompile;
1094  
1095 0 return HEY_IT_WORKED;
1096 }
1097  
1098 sub _upgrade
1099 0 ▶ {
Subroutine _upgrade: not called CC=1 SCAR=6.9
1100 0 $logger->info( "Upgrading all modules" );
1101  
1102 0 CPAN::Shell->upgrade();
1103  
1104 0 return HEY_IT_WORKED;
1105 }
1106  
1107 sub _shell
1108 0 ▶ {
Subroutine _shell: not called CC=1 SCAR=6.9
1109 0 $logger->info( "Dropping into shell" );
1110  
1111 0 CPAN::shell();
1112  
1113 0 return HEY_IT_WORKED;
1114 }
1115  
1116 sub _load_config # -j
1117 8 ▶ {
Subroutine _load_config: called CC=4 SCAR=14.1
1118 8 my $argument = shift;
1119  
1120 8 ▶ my $file = file_name_is_absolute( $argument ) ? $argument : rel2abs( $argument );
Branch: 1 branch
BranchTrueFalseTotal
file_name_is_absolute($argument) ? : 0 8 8
1121 8 ▶ croak( "cpan config file [$file] for -j does not exist!\n" ) unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 8 8
1122  
1123 # should I clear out any existing config here?
1124 8 $CPAN::Config = {};
1125 8 delete $INC{'CPAN/Config.pm'};
1126  
1127 8 my $rc = eval "require '$file'";
1128  
1129 # CPAN::HandleConfig::require_myconfig_or_config looks for this
1130 8 $INC{'CPAN/MyConfig.pm'} = 'fake out!';
1131  
1132 # CPAN::HandleConfig::load looks for this
1133 8 $CPAN::Config_loaded = 'fake out';
1134  
1135 8 ▶ croak( "Could not load [$file]: $@\n") unless $rc;
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 0 8 8
1136  
1137 8 return HEY_IT_WORKED;
1138 }
1139  
1140 sub _dump_config # -J
1141 1 ▶ {
Subroutine _dump_config: called CC=2 SCAR=7.0
1142 1 my $args = shift;
1143 1 require Data::Dumper;
1144  
1145 1 ▶ my $fh = $args->[0] || \*STDOUT;
Condition50%1/2
$args->[0] || \*STDOUT
l!l
01
MC/DC0%0/1
$args->[0] || \*STDOUT
$args->[0]
Truth table50%1/2
A
A= $args->[0]
Aresult
11
00
1146  
1147 1 local $Data::Dumper::Sortkeys = 1;
1148 1 my $dd = Data::Dumper->new(
1149 [$CPAN::Config],
1150 ['$CPAN::Config']
1151 );
1152  
1153 1 print $fh $dd->Dump, "\n1;\n__END__\n";
1154  
1155 1 return HEY_IT_WORKED;
1156 }
1157  
1158 sub _lock_lobotomy # -F
1159 0 ▶ {
Subroutine _lock_lobotomy: not called CC=1 SCAR=2.2
1160 15 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
1161  
1162 0 ▶ *CPAN::_flock = sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1163 0 ▶ *CPAN::checklock = sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1164  
1165 0 return HEY_IT_WORKED;
1166 }
1167  
1168 sub _download
1169 0 ▶ {
Subroutine _download: not called CC=3 SCAR=24.8
1170 0 my $args = shift;
1171  
1172 0 local $CPAN::DEBUG = 1;
1173  
1174 0 my %paths;
1175  
1176 0 foreach my $arg ( @$args ) {
1177 0 $logger->info( "Checking $arg" );
1178  
1179 0 ▶ my $module = _expand_module( $arg ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $module = _expand_module($arg) or next 0 0 0
1180 0 my $path = $module->cpan_file;
1181  
1182 0 $logger->debug( "Inst file would be $path\n" );
1183  
1184 0 $paths{$module} = _get_file( _make_path( $path ) );
1185  
1186 0 $logger->info( "Downloaded [$arg] to [$paths{$arg}]" );
1187 }
1188  
1189 0 return \%paths;
1190 }
1191  
1192 0 ▶sub _make_path { join "/", qw(authors id), $_[0] }
Subroutine _make_path: not called CC=1 SCAR=6.9
1193  
1194 sub _get_file
1195 0 ▶ {
Subroutine _get_file: not called CC=5 SCAR=34.0
1196 0 my $path = shift;
1197  
1198 0 my $loaded = _safe_load_module("LWP::Simple");
1199 0 ▶ croak "You need LWP::Simple to use features that fetch files from CPAN\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 0 0
1200 unless $loaded;
1201  
1202 0 my $file = substr $path, rindex( $path, '/' ) + 1;
1203 0 my $store_path = catfile( cwd(), $file );
1204 0 $logger->debug( "Store path is $store_path" );
1205  
1206 0 foreach my $site ( @{ $CPAN::Config->{urllist} } )
1207 {
1208 0 my $fetch_path = join "/", $site, $path;
1209 0 $logger->debug( "Trying $fetch_path" );
1210 0 my $status_code = LWP::Simple::getstore( $fetch_path, $store_path );
1211 0 ▶ last if( 200 <= $status_code and $status_code <= 300 );
Branch: 1 branch
BranchTrueFalseTotal
if 200 <= $status_code and $status_code <= 300 0 0 0
Condition0%0/3
200 <= $status_code and $status_code <= 300
!ll&&!rl&&r
000
MC/DC0%0/2
200 <= $status_code and $status_code <= 300
200 <= $status_code $status_code <= 300
Truth table0%0/3
A and B
A= 200 <= $status_codeB= $status_code <= 300
ABresult
0X0
100
111
1212 0 $logger->warn( "Could not get [$fetch_path]: Status code $status_code" );
1213 }
1214  
1215 0 return $store_path;
1216 }
1217  
1218 sub _gitify
1219 0 ▶ {
Subroutine _gitify: not called CC=6 SCAR=37.4
1220 0 my $args = shift;
1221  
1222 0 my $loaded = _safe_load_module("Archive::Extract");
1223 0 ▶ croak "You need Archive::Extract to use features that gitify distributions\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 0 0
1224 unless $loaded;
1225  
1226 0 my $starting_dir = cwd();
1227  
1228 0 foreach my $arg ( @$args )
1229 {
1230 0 $logger->info( "Checking $arg" );
1231 0 my $store_paths = _download( [ $arg ] );
1232 0 $logger->debug( "gitify Store path is $store_paths->{$arg}" );
1233 0 my $dirname = dirname( $store_paths->{$arg} );
1234  
1235 0 my $ae = Archive::Extract->new( archive => $store_paths->{$arg} );
1236 0 $ae->extract( to => $dirname );
1237  
1238 0 chdir $ae->extract_path;
1239  
1240 0 ▶ my $git = $ENV{GIT_COMMAND} || '/usr/local/bin/git';
Condition0%0/2
$ENV{'GIT_COMMAND'} || '/usr/local/bin/git'
l!l
00
MC/DC0%0/1
$ENV{'GIT_COMMAND'} || '/usr/local/bin/git'
$ENV{'GIT_COMMAND'}
Truth table0%0/2
A
A= $ENV{'GIT_COMMAND'}
Aresult
11
00
1241 0 ▶ croak "Could not find $git" unless -e $git;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $git 0 0 0
1242 0 ▶ croak "$git is not executable" unless -x $git;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $git 0 0 0
1243  
1244 # can we do this in Pure Perl?
1245 0 system( $git, 'init' );
1246 0 system( $git, qw( add . ) );
1247 0 system( $git, qw( commit -a -m ), 'initial import' );
1248 }
1249  
1250 0 chdir $starting_dir;
1251  
1252 0 return HEY_IT_WORKED;
1253 }
1254  
1255 sub _show_Changes
1256 0 ▶ {
Subroutine _show_Changes: not called CC=4 SCAR=30.0
1257 0 my $args = shift;
1258  
1259 0 foreach my $arg ( @$args )
1260 {
1261 0 $logger->info( "Checking $arg\n" );
1262  
1263 0 ▶ my $module = _expand_module( $arg ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $module = _expand_module($arg) or next 0 0 0
1264  
1265 0 my $out = _get_cpanpm_output();
1266  
1267 0 ▶ next unless eval { $module->inst_file };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $module->inst_file } } 0 0 0
1268 #next if $module->uptodate;
1269  
1270 0 ( my $id = $module->id() ) =~ s/::/\-/;
1271  
1272 0 my $url = "http://search.cpan.org/~" . lc( $module->userid ) . "/" .
1273 $id . "-" . $module->cpan_version() . "/";
1274  
1275 #print "URL: $url\n";
1276 0 _get_changes_file($url);
1277 }
1278  
1279 0 return HEY_IT_WORKED;
1280 }
1281  
1282 sub _get_changes_file
1283 0 ▶ {
Subroutine _get_changes_file: not called CC=4 SCAR=30.0
1284 0 ▶ croak "Reading Changes files requires LWP::Simple and URI\n"
Branch: 1 branch
BranchTrueFalseTotal
unless _safe_load_module("LWP::Simple") and _safe_load_module("URI") 0 0 0
Condition0%0/3
_safe_load_module("LWP::Simple") and _safe_load_module("URI")
!ll&&!rl&&r
000
MC/DC0%0/2
_safe_load_module("LWP::Simple") and _safe_load_module("URI")
_safe_load_module("LWP::Simple") _safe_load_module("URI")
Truth table0%0/3
A and B
A= _safe_load_module("LWP::Simple")B= _safe_load_module("URI")
ABresult
0X0
100
111
1285 unless _safe_load_module("LWP::Simple") && _safe_load_module("URI");
1286  
1287 0 my $url = shift;
1288  
1289 0 my $content = LWP::Simple::get( $url );
1290 0 ▶ $logger->info( "Got $url ..." ) if defined $content;
Branch: 1 branch
BranchTrueFalseTotal
if defined $content 0 0 0
1291 #print $content;
1292  
1293 0 my( $change_link ) = $content =~ m|<a href="(.*?)">Changes</a>|gi;
1294  
1295 0 my $changes_url = URI->new_abs( $change_link, $url );
1296 0 $logger->debug( "Change link is: $changes_url" );
1297  
1298 0 my $changes = LWP::Simple::get( $changes_url );
1299  
1300 0 print $changes;
1301  
1302 0 return HEY_IT_WORKED;
1303 }
1304  
1305 sub _show_Author
1306 0 ▶ {
Subroutine _show_Author: not called CC=5 SCAR=34.0
1307 0 my $args = shift;
1308  
1309 0 foreach my $arg ( @$args )
1310 {
1311 0 ▶ my $module = _expand_module( $arg ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $module = _expand_module($arg) or next 0 0 0
1312  
1313 0 ▶ unless( $module )
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 0 0 0
1314 {
1315 0 $logger->info( "Didn't find a $arg module, so no author!" );
1316 0 next;
1317 }
1318  
1319 0 my $author = CPAN::Shell->expand( "Author", $module->userid );
1320  
1321 0 ▶ next unless $module->userid;
Branch: 1 branch
BranchTrueFalseTotal
unless $module->userid 0 0 0
1322  
1323 0 printf "%-25s %-8s %-25s %s\n",
1324 $arg, $module->userid, $author->email, $author->name;
1325 }
1326  
1327 0 return HEY_IT_WORKED;
1328 }
1329  
1330 sub _show_Details
1331 0 ▶ {
Subroutine _show_Details: not called CC=9 SCAR=45.0
1332 0 my $args = shift;
1333  
1334 0 foreach my $arg ( @$args )
1335 {
1336 0 ▶ my $module = _expand_module( $arg ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $module = _expand_module($arg) or next 0 0 0
1337 0 my $author = CPAN::Shell->expand( "Author", $module->userid );
1338  
1339 0 ▶ next unless $module->userid;
Branch: 1 branch
BranchTrueFalseTotal
unless $module->userid 0 0 0
1340  
1341 0 print "$arg\n", "-" x 73, "\n\t";
1342 0 ▶ print join "\n\t",
Branch: 5 branches
BranchTrueFalseTotal
$module->description ? : 0 0 0
$module->cpan_file ? : 0 0 0
$module->inst_file ? : 0 0 0
$module->inst_version ? : 0 0 0
$module->uptodate ? : 0 0 0
1343 $module->description ? $module->description : "(no description)",
1344 $module->cpan_file ? $module->cpan_file : "(no cpanfile)",
1345 $module->inst_file ? $module->inst_file :"(no installation file)" ,
1346 'Installed: ' . ($module->inst_version ? $module->inst_version : "not installed"),
1347 'CPAN: ' . $module->cpan_version . ' ' .
1348 ($module->uptodate ? "" : "Not ") . "up to date",
1349 $author->fullname . " (" . $module->userid . ")",
1350 $author->email;
1351 0 print "\n\n";
1352  
1353 }
1354  
1355 0 return HEY_IT_WORKED;
1356 }
1357  
1358 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
1359 15 my $modules;
1360 sub _get_all_namespaces
1361 0 ▶ {
Subroutine _get_all_namespaces: not called CC=2 SCAR=17.9
1362 0 ▶ return $modules if $modules;
Branch: 1 branch
BranchTrueFalseTotal
if $modules 0 0 0
1363 0 $modules = [ map { $_->id } CPAN::Shell->expand( "Module", "/./" ) ];
1364 }
1365 }
1366  
1367 sub _show_out_of_date
1368 0 ▶ {
Subroutine _show_out_of_date: not called CC=6 SCAR=37.4
1369 0 my $modules = _get_all_namespaces();
1370  
1371 0 printf "%-40s %6s %6s\n", "Module Name", "Local", "CPAN";
1372 0 print "-" x 73, "\n";
1373  
1374 0 foreach my $module ( @$modules )
1375 {
1376 0 ▶ next unless $module = _expand_module($module);
Branch: 1 branch
BranchTrueFalseTotal
unless $module = _expand_module($module) 0 0 0
1377 0 ▶ next unless $module->inst_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $module->inst_file 0 0 0
1378 0 ▶ next if $module->uptodate;
Branch: 1 branch
BranchTrueFalseTotal
if $module->uptodate 0 0 0
1379 0 ▶ printf "%-40s %.4f %.4f\n",
Branch: 1 branch
BranchTrueFalseTotal
$module->inst_version ? : 0 0 0
1380 $module->id,
1381 $module->inst_version ? $module->inst_version : '',
1382 $module->cpan_version;
1383 }
1384  
1385 0 return HEY_IT_WORKED;
1386 }
1387  
1388 sub _show_author_mods
1389 0 ▶ {
Subroutine _show_author_mods: not called CC=3 SCAR=24.8
1390 0 my $args = shift;
1391  
1392 0 my %hash = map { lc $_, 1 } @$args;
1393  
1394 0 my $modules = _get_all_namespaces();
1395  
1396 0 foreach my $module ( @$modules ) {
1397 0 ▶ next unless exists $hash{ lc $module->userid };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash{lc $module->userid} 0 0 0
1398 0 print $module->id, "\n";
1399 }
1400  
1401 0 return HEY_IT_WORKED;
1402 }
1403  
1404 sub _list_all_mods # -l
1405 0 ▶ {
Subroutine _list_all_mods: not called CC=4 SCAR=30.0
1406 0 require File::Find;
1407  
1408 0 my $args = shift;
1409  
1410  
1411 0 my $fh = \*STDOUT;
1412  
1413 0 INC: foreach my $inc ( @INC )
1414 {
1415 0 my( $wanted, $reporter ) = _generator();
1416 0 File::Find::find( { wanted => $wanted }, $inc );
1417  
1418 0 my $count = 0;
1419 0 FILE: foreach my $file ( @{ $reporter->() } )
1420 {
1421 0 my $version = _parse_version_safely( $file );
1422  
1423 0 my $module_name = _path_to_module( $inc, $file );
1424 0 ▶ next FILE unless defined $module_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module_name 0 0 0
1425  
1426 0 print $fh "$module_name\t$version\n";
1427  
1428 #last if $count++ > 5;
1429 }
1430 }
1431  
1432 0 return HEY_IT_WORKED;
1433 }
1434  
1435 sub _generator
1436 0 ▶ {
Subroutine _generator: not called CC=1 SCAR=6.9
1437 0 my @files = ();
1438  
1439 0 ▶ sub { push @files,
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if /\A\w+\.pm\z/ 0 0 0
1440 File::Spec->canonpath( $File::Find::name )
1441 if m/\A\w+\.pm\z/ },
1442 0 ▶ sub { \@files },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1443 0 }
1444  
1445 sub _parse_version_safely # stolen from PAUSE's mldistwatch, but refactored
1446 0 ▶ {
Subroutine _parse_version_safely: not called CC=9 SCAR=45.0
1447 0 my( $file ) = @_;
1448  
1449 0 local $/ = "\n";
1450 0 local $_; # don't mess with the $_ in the map calling this
1451  
1452 0 ▶ return unless open FILE, "<$file";
Branch: 1 branch
BranchTrueFalseTotal
unless open FILE, "<$file" 0 0 0
1453  
1454 0 my $in_pod = 0;
1455 0 my $version;
1456 0 ▶ while( <FILE> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
1457 {
1458 0 chomp;
1459 0 ▶ $in_pod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $in_pod;
Branch: 2 branches
BranchTrueFalseTotal
/^=(?!cut)/ ? : 0 0 0
/^=cut/ ? : 0 0 0
1460 0 ▶ next if $in_pod || /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^\s*#/ 0 0 0
Condition0%0/3
$in_pod or /^\s*#/
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_pod or /^\s*#/
$in_pod /^\s*#/
Truth table0%0/3
A or B
A= $in_podB= /^\s*#/
ABresult
1X1
011
000
1461  
1462 0 ▶ next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
Branch: 1 branch
BranchTrueFalseTotal
unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ 0 0 0
1463 0 my( $sigil, $var ) = ( $1, $2 );
1464  
1465 0 $version = _eval_version( $_, $sigil, $var );
1466 0 last;
1467 }
1468 0 close FILE;
1469  
1470 0 ▶ return 'undef' unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
1471  
1472 0 return $version;
1473 }
1474  
1475 sub _eval_version
1476 0 ▶ {
Subroutine _eval_version: not called CC=1 SCAR=2.6
1477 0 my( $line, $sigil, $var ) = @_;
1478  
1479 # split package line to hide from PAUSE
1480 0 my $eval = qq{
1481 package
1482 ExtUtils::MakeMaker::_version;
1483  
1484 no warnings;
1485 local $sigil$var;
1486 \$$var=undef; do {
1487 $line
1488 }; \$$var
1489 };
1490  
1491 0 my $version = do {
1492 0 local $^W = 0;
1493 15 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1494 0 eval( $eval );
1495 };
1496  
1497 0 return $version;
1498 }
1499  
1500 sub _path_to_module
1501 0 ▶ {
Subroutine _path_to_module: not called CC=2 SCAR=17.9
1502 0 my( $inc, $path ) = @_;
1503 0 ▶ return if length $path < length $inc;
Branch: 1 branch
BranchTrueFalseTotal
if length $path < length $inc 0 0 0
1504  
1505 0 my $module_path = substr( $path, length $inc );
1506 0 $module_path =~ s/\.pm\z//;
1507  
1508 # XXX: this is cheating and doesn't handle everything right
1509 0 my @dirs = grep { ! /\W/ } File::Spec->splitdir( $module_path );
1510 0 shift @dirs;
1511  
1512 0 my $module_name = join "::", @dirs;
1513  
1514 0 return $module_name;
1515 }
1516  
1517  
1518 sub _expand_module
1519 7 ▶ {
Subroutine _expand_module: called CC=6 SCAR=33.1
1520 7 my( $module ) = @_;
1521  
1522 7 my $expanded = CPAN::Shell->expandany( $module );
1523 7 ▶ return $expanded if $expanded;
Branch: 1 branch
BranchTrueFalseTotal
if $expanded 7 0 7
1524 0 $expanded = CPAN::Shell->expand( "Module", $module );
1525 0 ▶ unless( defined $expanded ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expanded) 0 0 0
1526 0 $logger->error( "Could not expand [$module]. Check the module name." );
1527 my $threshold = (
1528 0 grep { int }
1529 0 sort { length $a <=> length $b }
1530 length($module)/4, 4
1531 )[0];
1532  
1533 0 my $guesses = _guess_at_module_name( $module, $threshold );
1534 0 ▶ if( defined $guesses and @$guesses ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $guesses and @$guesses) 0 0 0
Condition0%0/3
defined $guesses and @$guesses
!ll&&!rl&&r
000
MC/DC0%0/2
defined $guesses and @$guesses
defined $guesses @$guesses
Truth table0%0/3
A and B
A= defined $guessesB= @$guesses
ABresult
0X0
100
111
1535 0 $logger->info( "Perhaps you meant one of these:" );
1536 0 foreach my $guess ( @$guesses ) {
1537 0 $logger->info( "\t$guess" );
1538 }
1539 }
1540 0 return;
1541 }
1542  
1543 0 return $expanded;
1544 }
1545  
1546 15 my $guessers = [
1547 [ qw( Text::Levenshtein::XS distance 7 1 ) ],
1548 [ qw( Text::Levenshtein::Damerau::XS xs_edistance 7 1 ) ],
1549  
1550 [ qw( Text::Levenshtein distance 7 1 ) ],
1551 [ qw( Text::Levenshtein::Damerau::PP pp_edistance 7 1 ) ],
1552  
1553 ];
1554  
1555 sub _disable_guessers
1556 7 ▶ {
Subroutine _disable_guessers: called CC=2 SCAR=6.9
1557 7 $_->[-1] = 0 for @$guessers;
1558 }
1559  
1560 # for -x
1561 sub _guess_namespace
1562 0 ▶ {
Subroutine _guess_namespace: not called CC=3 SCAR=24.8
1563 0 my $args = shift;
1564  
1565 0 foreach my $arg ( @$args )
1566 {
1567 0 $logger->debug( "Checking $arg" );
1568 0 my $guesses = _guess_at_module_name( $arg );
1569  
1570 0 foreach my $guess ( @$guesses ) {
1571 0 print $guess, "\n";
1572 }
1573 }
1574  
1575 0 return HEY_IT_WORKED;
1576 }
1577  
1578 0 ▶sub _list_all_namespaces {
Subroutine _list_all_namespaces: not called CC=2 SCAR=17.9
1579 0 my $modules = _get_all_namespaces();
1580  
1581 0 foreach my $module ( @$modules ) {
1582 0 print $module, "\n";
1583 }
1584 }
1585  
1586 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
1587 15 my $distance;
1588 my $_threshold;
1589 15 my $can_guess;
1590 15 my $shown_help = 0;
1591 sub _guess_at_module_name
1592 0 ▶ {
Subroutine _guess_at_module_name: not called CC=12 SCAR=48.9
1593 0 my( $target, $threshold ) = @_;
1594  
1595 0 ▶ unless( defined $distance ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $distance) 0 0 0
1596 0 foreach my $try ( @$guessers ) {
1597 0 ▶ $can_guess = eval "require $try->[0]; 1" or next;
Branch: 1 branch
BranchTrueFalseTotal
$can_guess = eval "require $try->[0]; 1" or next 0 0 0
1598  
1599 0 ▶ $try->[-1] or next; # disabled
Branch: 1 branch
BranchTrueFalseTotal
$try->[-1] or next 0 0 0
1600 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1601 0 $distance = \&{ join "::", @$try[0,1] };
1602 0 ▶ $threshold ||= $try->[2];
Condition0%0/3
$threshold ||= $try->[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
$threshold ||= $try->[2]
$threshold $try->[2]
Truth table0%0/3
A ||= B
A= $thresholdB= $try->[2]
ABresult
1X1
011
000
1603 }
1604 }
1605 0 ▶ $_threshold ||= $threshold;
Condition0%0/3
$_threshold ||= $threshold
l!l&&r!l&&!r
000
MC/DC0%0/2
$_threshold ||= $threshold
$_threshold $threshold
Truth table0%0/3
A ||= B
A= $_thresholdB= $threshold
ABresult
1X1
011
000
1606  
1607 0 ▶ unless( $distance ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distance) 0 0 0
1608 0 ▶ unless( $shown_help ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shown_help) 0 0 0
1609 0 my $modules = join ", ", map { $_->[0] } @$guessers;
1610 0 substr $modules, rindex( $modules, ',' ), 1, ', and';
1611  
1612 # Should this be colorized?
1613 0 ▶ if( $can_guess ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_guess) { } 0 0 0
1614 0 $logger->info( "I can suggest names if you provide the -x option on invocation." );
1615 }
1616 else {
1617 0 $logger->info( "I can suggest names if you install one of $modules" );
1618 0 $logger->info( "and you provide the -x option on invocation." );
1619 }
1620 0 $shown_help++;
1621 }
1622 0 return;
1623 }
1624  
1625 0 my $modules = _get_all_namespaces();
1626 0 $logger->info( "Checking " . @$modules . " namespaces for close match suggestions" );
1627  
1628 0 my %guesses;
1629 0 foreach my $guess ( @$modules ) {
1630 0 my $distance = $distance->( $target, $guess );
1631 0 ▶ next if $distance > $_threshold;
Branch: 1 branch
BranchTrueFalseTotal
if $distance > $_threshold 0 0 0
1632 0 $guesses{$guess} = $distance;
1633 }
1634  
1635 0 my @guesses = sort { $guesses{$a} <=> $guesses{$b} } keys %guesses;
1636 0 return [ grep { defined } @guesses[0..9] ];
1637 }
1638 }
1639  
1640 15 1;
1641  
1642 =back
1643  
1644 =head1 EXIT VALUES
1645  
1646 The script exits with zero if it thinks that everything worked, or a
1647 positive number if it thinks that something failed. Note, however, that
1648 in some cases it has to divine a failure by the output of things it does
1649 not control. For now, the exit codes are vague:
1650  
1651 1 An unknown error
1652  
1653 2 The was an external problem
1654  
1655 4 There was an internal problem with the script
1656  
1657 8 A module failed to install
1658  
1659 =head1 TO DO
1660  
1661 * There is initial support for Log4perl if it is available, but I
1662 haven't gone through everything to make the NullLogger work out
1663 correctly if Log4perl is not installed.
1664  
1665 * When I capture CPAN.pm output, I need to check for errors and
1666 report them to the user.
1667  
1668 * Warnings switch
1669  
1670 * Check then exit
1671  
1672 =head1 BUGS
1673  
1674 * none noted
1675  
1676 =head1 SEE ALSO
1677  
1678 L<CPAN>, L<App::cpanminus>
1679  
1680 =head1 SOURCE AVAILABILITY
1681  
1682 This code is in Github in the CPAN.pm repository:
1683  
1684 https://github.com/andk/cpanpm
1685  
1686 The source used to be tracked separately in another GitHub repo,
1687 but the canonical source is now in the above repo.
1688  
1689 =head1 CREDITS
1690  
1691 Japheth Cleaver added the bits to allow a forced install (C<-f>).
1692  
1693 Jim Brandt suggested and provided the initial implementation for the
1694 up-to-date and Changes features.
1695  
1696 Adam Kennedy pointed out that C<exit()> causes problems on Windows
1697 where this script ends up with a .bat extension
1698  
1699 David Golden helps integrate this into the C<CPAN.pm> repos.
1700  
1701 Jim Keenan fixed up various issues with _download
1702  
1703 =head1 AUTHOR
1704  
1705 brian d foy, C<< <bdfoy@cpan.org> >>
1706  
1707 =head1 COPYRIGHT
1708  
1709 Copyright (c) 2001-2021, brian d foy, All Rights Reserved.
1710  
1711 You may redistribute this under the same terms as Perl itself.
1712  
1713 =cut
1714  
1715 # Local Variables:
1716 # mode: cperl
1717 # indent-tabs-mode: t
1718 # cperl-indent-level: 8
1719 # cperl-continued-statement-offset: 8
1720 # End:
« blib/lib/CPAN/HTTP/Client.pm ↑ Summary blib/lib/CPAN/Exception/yaml_process_error.pm »