File Coverage

blib/lib/CPAN.pm
Criterion Covered Total %
statement 243 771 31.5
branch 46 366 12.5
condition 23 154 14.9
subroutine 63 102 61.7
pod 10 24 41.6
total 385 1417 27.1


line stmt bran cond sub pod time code
1             # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2             # vim: ts=4 sts=4 sw=4:
3 7     7   112900 use strict;
  7         32  
  7         994  
4             package CPAN;
5             $CPAN::VERSION = '2.05';
6             $CPAN::VERSION =~ s/_//;
7              
8             # we need to run chdir all over and we would get at wrong libraries
9             # there
10 7     7   167 use File::Spec ();
  7         23  
  7         600  
11             BEGIN {
12 7 50   7   1291 if (File::Spec->can("rel2abs")) {
13 7         41 for my $inc (@INC) {
14 80 50       2563 $inc = File::Spec->rel2abs($inc) unless ref $inc;
15             }
16             }
17             }
18 7     7   4619 use CPAN::Author;
  7         31  
  7         264  
19 7     7   6255 use CPAN::HandleConfig;
  7         25  
  7         307  
20 7     7   5672 use CPAN::Version;
  7         29  
  7         364  
21 7     7   9242 use CPAN::Bundle;
  7         29  
  7         280  
22 7     7   6567 use CPAN::CacheMgr;
  7         28  
  7         287  
23 7     7   6362 use CPAN::Complete;
  7         23  
  7         269  
24 7     7   53 use CPAN::Debug;
  7         11  
  7         143  
25 7     7   22090 use CPAN::Distribution;
  7         26  
  7         400  
26 7     7   6160 use CPAN::Distrostatus;
  7         21  
  7         199  
27 7     7   9794 use CPAN::FTP;
  7         34  
  7         351  
28 7     7   6843 use CPAN::Index 1.93; # https://rt.cpan.org/Ticket/Display.html?id=43349
  7         277  
  7         271  
29 7     7   75 use CPAN::InfoObj;
  7         23  
  7         157  
30 7     7   152 use CPAN::Module;
  7         78  
  7         248  
31 7     7   6126 use CPAN::Prompt;
  7         33  
  7         374  
32 7     7   7043 use CPAN::URL;
  7         22  
  7         228  
33 7     7   4659 use CPAN::Queue;
  7         21  
  7         399  
34 7     7   5584 use CPAN::Tarzip;
  7         28  
  7         309  
35 7     7   13210 use CPAN::DeferredCode;
  7         20  
  7         196  
36 7     7   20738 use CPAN::Shell;
  7         29  
  7         383  
37 7     7   6561 use CPAN::LWP::UserAgent;
  7         19  
  7         350  
38 7     7   5210 use CPAN::Exception::RecursiveDependency;
  7         20  
  7         399  
39 7     7   4346 use CPAN::Exception::yaml_not_installed;
  7         19  
  7         246  
40 7     7   4947 use CPAN::Exception::yaml_process_error;
  7         71  
  7         187  
41              
42 7     7   41 use Carp ();
  7         14  
  7         112  
43 7     7   35 use Config ();
  7         12  
  7         133  
44 7     7   35 use Cwd qw(chdir);
  7         11  
  7         430  
45 7     7   43 use DirHandle ();
  7         12  
  7         122  
46 7     7   32 use Exporter ();
  7         15  
  7         135  
47 7     7   9538 use ExtUtils::MakeMaker qw(prompt); # for some unknown reason,
  7         782970  
  7         587  
48             # 5.005_04 does not work without
49             # this
50 7     7   69 use File::Basename ();
  7         18  
  7         125  
51 7     7   5818 use File::Copy ();
  7         29355  
  7         328  
52 7     7   57 use File::Find;
  7         18  
  7         541  
53 7     7   42 use File::Path ();
  7         14  
  7         107  
54 7     7   11780 use FileHandle ();
  7         80708  
  7         465  
55 7     7   65 use Fcntl qw(:flock);
  7         14  
  7         1199  
56 7     7   10108 use Safe ();
  7         413980  
  7         571  
57 7     7   7784 use Sys::Hostname qw(hostname);
  7         10665  
  7         516  
58 7     7   21491 use Text::ParseWords ();
  7         10572  
  7         197  
59 7     7   15110 use Text::Wrap ();
  7         33957  
  7         488  
60              
61             # protect against "called too early"
62             sub find_perl ();
63             sub anycwd ();
64             sub _uniq;
65              
66 7     7   5728 no lib ".";
  7         13329  
  7         51  
67              
68             require Mac::BuildTools if $^O eq 'MacOS';
69             if ($ENV{PERL5_CPAN_IS_RUNNING} && $$ != $ENV{PERL5_CPAN_IS_RUNNING}) {
70             $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} ||= $ENV{PERL5_CPAN_IS_RUNNING};
71             my @rec = _uniq split(/,/, $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION}), $$;
72             $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} = join ",", @rec;
73             # warn "# Note: Recursive call of CPAN.pm detected\n";
74             my $w = sprintf "# Note: CPAN.pm is running in process %d now", pop @rec;
75             my %sleep = (
76             5 => 30,
77             6 => 60,
78             7 => 120,
79             );
80             my $sleep = @rec > 7 ? 300 : ($sleep{scalar @rec}||0);
81             my $verbose = @rec >= 4;
82             while (@rec) {
83             $w .= sprintf " which has been called by process %d", pop @rec;
84             }
85             if ($sleep) {
86             $w .= ".\n\n# Sleeping $sleep seconds to protect other processes\n";
87             }
88             if ($verbose) {
89             warn $w;
90             }
91             local $| = 1;
92             while ($sleep > 0) {
93             printf "\r#%5d", --$sleep;
94             sleep 1;
95             }
96             print "\n";
97             }
98             $ENV{PERL5_CPAN_IS_RUNNING}=$$;
99             $ENV{PERL5_CPANPLUS_IS_RUNNING}=$$; # https://rt.cpan.org/Ticket/Display.html?id=23735
100              
101 7     7   26525 END { $CPAN::End++; &cleanup; }
  7         54  
102              
103             $CPAN::Signal ||= 0;
104             $CPAN::Frontend ||= "CPAN::Shell";
105             unless (@CPAN::Defaultsites) {
106             @CPAN::Defaultsites = map {
107             CPAN::URL->new(TEXT => $_, FROM => "DEF")
108             }
109             "http://www.perl.org/CPAN/",
110             "ftp://ftp.perl.org/pub/CPAN/";
111             }
112             # $CPAN::iCwd (i for initial)
113             $CPAN::iCwd ||= CPAN::anycwd();
114             $CPAN::Perl ||= CPAN::find_perl();
115             $CPAN::Defaultdocs ||= "http://search.cpan.org/perldoc?";
116             $CPAN::Defaultrecent ||= "http://search.cpan.org/uploads.rdf";
117             $CPAN::Defaultrecent ||= "http://cpan.uwinnipeg.ca/htdocs/cpan.xml";
118              
119             # our globals are getting a mess
120 7         19448 use vars qw(
121             $AUTOLOAD
122             $Be_Silent
123             $CONFIG_DIRTY
124             $Defaultdocs
125             $Echo_readline
126             $Frontend
127             $GOTOSHELL
128             $HAS_USABLE
129             $Have_warned
130             $MAX_RECURSION
131             $META
132             $RUN_DEGRADED
133             $Signal
134             $SQLite
135             $Suppress_readline
136             $VERSION
137             $autoload_recursion
138             $term
139             @Defaultsites
140             @EXPORT
141 7     7   10531 );
  7         20  
142              
143             $MAX_RECURSION = 32;
144              
145             @CPAN::ISA = qw(CPAN::Debug Exporter);
146              
147             # note that these functions live in CPAN::Shell and get executed via
148             # AUTOLOAD when called directly
149             @EXPORT = qw(
150             autobundle
151             bundle
152             clean
153             cvs_import
154             expand
155             force
156             fforce
157             get
158             install
159             install_tested
160             is_tested
161             make
162             mkmyconfig
163             notest
164             perldoc
165             readme
166             recent
167             recompile
168             report
169             shell
170             smoke
171             test
172             upgrade
173             );
174              
175             sub soft_chdir_with_alternatives ($);
176              
177             {
178             $autoload_recursion ||= 0;
179              
180             #-> sub CPAN::AUTOLOAD ;
181             sub AUTOLOAD { ## no critic
182 1     1   18 $autoload_recursion++;
183 1         3 my($l) = $AUTOLOAD;
184 1         12 $l =~ s/.*:://;
185 1 50       5 if ($CPAN::Signal) {
186 0         0 warn "Refusing to autoload '$l' while signal pending";
187 0         0 $autoload_recursion--;
188 0         0 return;
189             }
190 1 50       9 if ($autoload_recursion > 1) {
191 0         0 my $fullcommand = join " ", map { "'$_'" } $l, @_;
  0         0  
192 0         0 warn "Refusing to autoload $fullcommand in recursion\n";
193 0         0 $autoload_recursion--;
194 0         0 return;
195             }
196 1         3 my(%export);
197 1         81 @export{@EXPORT} = '';
198 1 50       29 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
199 1 50       5 if (exists $export{$l}) {
200 0         0 CPAN::Shell->$l(@_);
201             } else {
202 1         18 die(qq{Unknown CPAN command "$AUTOLOAD". }.
203             qq{Type ? for help.\n});
204             }
205 0         0 $autoload_recursion--;
206             }
207             }
208              
209             {
210             my $x = *SAVEOUT; # avoid warning
211             open($x,">&STDOUT") or die "dup failed";
212             my $redir = 0;
213             sub _redirect(@) {
214             #die if $redir;
215 0     0   0 local $_;
216 0         0 push(@_,undef);
217 0         0 while(defined($_=shift)) {
218 0 0       0 if (s/^\s*>//){
    0          
219 0 0       0 my ($m) = s/^>// ? ">" : "";
220 0         0 s/\s+//;
221 0 0       0 $_=shift unless length;
222 0 0       0 die "no dest" unless defined;
223 0 0       0 open(STDOUT,">$m$_") or die "open:$_:$!\n";
224 0         0 $redir=1;
225             } elsif ( s/^\s*\|\s*// ) {
226 0         0 my $pipe="| $_";
227 0         0 while(defined($_[0])){
228 0         0 $pipe .= ' ' . shift;
229             }
230 0 0       0 open(STDOUT,$pipe) or die "open:$pipe:$!\n";
231 0         0 $redir=1;
232             } else {
233 0         0 push(@_,$_);
234             }
235             }
236 0         0 return @_;
237             }
238             sub _unredirect {
239 0 0   0   0 return unless $redir;
240 0         0 $redir = 0;
241             ## redirect: unredirect and propagate errors. explicit close to wait for pipe.
242 0         0 close(STDOUT);
243 0         0 open(STDOUT,">&SAVEOUT");
244 0 0       0 die "$@" if "$@";
245             ## redirect: done
246             }
247             }
248              
249             sub _uniq {
250 0     0   0 my(@list) = @_;
251 0         0 my %seen;
252 0         0 return grep { !$seen{$_}++ } @list;
  0         0  
253             }
254              
255             #-> sub CPAN::shell ;
256             sub shell {
257 0     0 1 0 my($self) = @_;
258 0 0       0 $Suppress_readline = ! -t STDIN unless defined $Suppress_readline;
259 0 0       0 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
260              
261 0   0     0 my $oprompt = shift || CPAN::Prompt->new;
262 0         0 my $prompt = $oprompt;
263 0   0     0 my $commandline = shift || "";
264 0   0     0 $CPAN::CurrentCommandId ||= 1;
265              
266 0         0 local($^W) = 1;
267 0 0       0 unless ($Suppress_readline) {
268 0         0 require Term::ReadLine;
269 0 0 0     0 if (! $term
270             or
271             $term->ReadLine eq "Term::ReadLine::Stub"
272             ) {
273 0         0 $term = Term::ReadLine->new('CPAN Monitor');
274             }
275 0 0       0 if ($term->ReadLine eq "Term::ReadLine::Gnu") {
276 0         0 my $attribs = $term->Attribs;
277             $attribs->{attempted_completion_function} = sub {
278 0     0   0 &CPAN::Complete::gnu_cpl;
279             }
280 0         0 } else {
281 0         0 $readline::rl_completion_function =
282             $readline::rl_completion_function = 'CPAN::Complete::cpl';
283             }
284 0 0       0 if (my $histfile = $CPAN::Config->{'histfile'}) {{
285 0 0       0 unless ($term->can("AddHistory")) {
  0         0  
286 0         0 $CPAN::Frontend->mywarn("Terminal does not support AddHistory.\n");
287 0         0 last;
288             }
289 0         0 $META->readhist($term,$histfile);
290             }}
291 0         0 for ($CPAN::Config->{term_ornaments}) { # alias
292 0         0 local $Term::ReadLine::termcap_nowarn = 1;
293 0 0       0 $term->ornaments($_) if defined;
294             }
295             # $term->OUT is autoflushed anyway
296 0         0 my $odef = select STDERR;
297 0         0 $| = 1;
298 0         0 select STDOUT;
299 0         0 $| = 1;
300 0         0 select $odef;
301             }
302              
303 0         0 $META->checklock();
304 0 0       0 my @cwd = grep { defined $_ and length $_ }
  0 0       0  
305             CPAN::anycwd(),
306             File::Spec->can("tmpdir") ? File::Spec->tmpdir() : (),
307             File::Spec->rootdir();
308 0         0 my $try_detect_readline;
309 0 0       0 $try_detect_readline = $term->ReadLine eq "Term::ReadLine::Stub" if $term;
310 0 0       0 unless ($CPAN::Config->{inhibit_startup_message}) {
311 0 0       0 my $rl_avail = $Suppress_readline ? "suppressed" :
    0          
312             ($term->ReadLine ne "Term::ReadLine::Stub") ? "enabled" :
313             "available (maybe install Bundle::CPAN or Bundle::CPANxxl?)";
314 0         0 $CPAN::Frontend->myprint(
315             sprintf qq{
316             cpan shell -- CPAN exploration and modules installation (v%s)
317             Enter 'h' for help.
318              
319             },
320             $CPAN::VERSION,
321             $rl_avail
322             )
323             }
324 0         0 my($continuation) = "";
325 0         0 my $last_term_ornaments;
326 0         0 SHELLCOMMAND: while () {
327 0 0       0 if ($Suppress_readline) {
328 0 0       0 if ($Echo_readline) {
329 0         0 $|=1;
330             }
331 0         0 print $prompt;
332 0 0       0 last SHELLCOMMAND unless defined ($_ = <> );
333 0 0       0 if ($Echo_readline) {
334             # backdoor: I could not find a way to record sessions
335 0         0 print $_;
336             }
337 0         0 chomp;
338             } else {
339             last SHELLCOMMAND unless
340 0 0       0 defined ($_ = $term->readline($prompt, $commandline));
341             }
342 0 0       0 $_ = "$continuation$_" if $continuation;
343 0         0 s/^\s+//;
344 0 0       0 next SHELLCOMMAND if /^$/;
345 0         0 s/^\s*\?\s*/help /;
346 0 0       0 if (/^(?:q(?:uit)?|bye|exit)\s*$/i) {
    0          
    0          
    0          
347 0         0 last SHELLCOMMAND;
348             } elsif (s/\\$//s) {
349 0         0 chomp;
350 0         0 $continuation = $_;
351 0         0 $prompt = " > ";
352             } elsif (/^\!/) {
353 0         0 s/^\!//;
354 0         0 my($eval) = $_;
355             package
356             CPAN::Eval; # hide from the indexer
357 7     7   55 use strict;
  7         13  
  7         296  
358 7     7   73 use vars qw($import_done);
  7         18  
  7         11633  
359 0 0       0 CPAN->import(':DEFAULT') unless $import_done++;
360 0 0       0 CPAN->debug("eval[$eval]") if $CPAN::DEBUG;
361 0         0 eval($eval);
362 0 0       0 warn $@ if $@;
363 0         0 $continuation = "";
364 0         0 $prompt = $oprompt;
365             } elsif (/./) {
366 0         0 my(@line);
367 0         0 eval { @line = Text::ParseWords::shellwords($_) };
  0         0  
368 0 0       0 warn($@), next SHELLCOMMAND if $@;
369 0 0       0 warn("Text::Parsewords could not parse the line [$_]"),
370             next SHELLCOMMAND unless @line;
371 0 0       0 $CPAN::META->debug("line[".join("|",@line)."]") if $CPAN::DEBUG;
372 0         0 my $command = shift @line;
373 0         0 eval {
374 0         0 local (*STDOUT)=*STDOUT;
375 0         0 @line = _redirect(@line);
376 0         0 CPAN::Shell->$command(@line)
377             };
378 0         0 my $command_error = $@;
379 0         0 _unredirect;
380 0         0 my $reported_error;
381 0 0       0 if ($command_error) {
382 0         0 my $err = $command_error;
383 0 0 0     0 if (ref $err and $err->isa('CPAN::Exception::blocked_urllist')) {
384 0         0 $CPAN::Frontend->mywarn("Client not fully configured, please proceed with configuring.$err");
385 0         0 $reported_error = ref $err;
386             } else {
387             # I'd prefer never to arrive here and make all errors exception objects
388 0 0       0 if ($err =~ /\S/) {
389 0         0 require Carp;
390 0         0 require Dumpvalue;
391 0         0 my $dv = Dumpvalue->new(tick => '"');
392 0         0 Carp::cluck(sprintf "Catching error: %s", $dv->stringify($err));
393             }
394             }
395             }
396 0 0       0 if ($command =~ /^(
397             # classic commands
398             make
399             |test
400             |install
401             |clean
402              
403             # pragmas for classic commands
404             |ff?orce
405             |notest
406              
407             # compounds
408             |report
409             |smoke
410             |upgrade
411             )$/x) {
412             # only commands that tell us something about failed distros
413             # eval necessary for people without an urllist
414 0         0 eval {CPAN::Shell->failed($CPAN::CurrentCommandId,1);};
  0         0  
415 0 0       0 if (my $err = $@) {
416 0 0 0     0 unless (ref $err and $reported_error eq ref $err) {
417 0         0 die $@;
418             }
419             }
420             }
421 0         0 soft_chdir_with_alternatives(\@cwd);
422 0         0 $CPAN::Frontend->myprint("\n");
423 0         0 $continuation = "";
424 0         0 $CPAN::CurrentCommandId++;
425 0         0 $prompt = $oprompt;
426             }
427             } continue {
428 0         0 $commandline = ""; # I do want to be able to pass a default to
429             # shell, but on the second command I see no
430             # use in that
431 0         0 $Signal=0;
432 0         0 CPAN::Queue->nullify_queue;
433 0 0       0 if ($try_detect_readline) {
434 0 0 0     0 if ($CPAN::META->has_inst("Term::ReadLine::Gnu")
435             ||
436             $CPAN::META->has_inst("Term::ReadLine::Perl")
437             ) {
438 0         0 delete $INC{"Term/ReadLine.pm"};
439 0         0 my $redef = 0;
440 0         0 local($SIG{__WARN__}) = CPAN::Shell::paintdots_onreload(\$redef);
441 0         0 require Term::ReadLine;
442 0         0 $CPAN::Frontend->myprint("\n$redef subroutines in ".
443             "Term::ReadLine redefined\n");
444 0         0 $GOTOSHELL = 1;
445             }
446             }
447 0 0 0     0 if ($term and $term->can("ornaments")) {
448 0         0 for ($CPAN::Config->{term_ornaments}) { # alias
449 0 0       0 if (defined $_) {
450 0 0 0     0 if (not defined $last_term_ornaments
451             or $_ != $last_term_ornaments
452             ) {
453 0         0 local $Term::ReadLine::termcap_nowarn = 1;
454 0         0 $term->ornaments($_);
455 0         0 $last_term_ornaments = $_;
456             }
457             } else {
458 0         0 undef $last_term_ornaments;
459             }
460             }
461             }
462 0         0 for my $class (qw(Module Distribution)) {
463             # again unsafe meta access?
464 0         0 for my $dm (keys %{$CPAN::META->{readwrite}{"CPAN::$class"}}) {
  0         0  
465 0 0       0 next unless $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
466 0         0 CPAN->debug("BUG: $class '$dm' was in command state, resetting");
467 0         0 delete $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
468             }
469             }
470 0 0       0 if ($GOTOSHELL) {
471 0         0 $GOTOSHELL = 0; # not too often
472 0 0 0     0 $META->savehist if $CPAN::term && $CPAN::term->can("GetHistory");
473 0         0 @_ = ($oprompt,"");
474 0         0 goto &shell;
475             }
476             }
477 0         0 soft_chdir_with_alternatives(\@cwd);
478             }
479              
480             #-> CPAN::soft_chdir_with_alternatives ;
481             sub soft_chdir_with_alternatives ($) {
482 0     0 0 0 my($cwd) = @_;
483 0 0       0 unless (@$cwd) {
484 0         0 my $root = File::Spec->rootdir();
485 0         0 $CPAN::Frontend->mywarn(qq{Warning: no good directory to chdir to!
486             Trying '$root' as temporary haven.
487             });
488 0         0 push @$cwd, $root;
489             }
490 0         0 while () {
491 0 0       0 if (chdir $cwd->[0]) {
492 0         0 return;
493             } else {
494 0 0       0 if (@$cwd>1) {
495 0         0 $CPAN::Frontend->mywarn(qq{Could not chdir to "$cwd->[0]": $!
496             Trying to chdir to "$cwd->[1]" instead.
497             });
498 0         0 shift @$cwd;
499             } else {
500 0         0 $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd->[0]": $!});
501             }
502             }
503             }
504             }
505              
506             sub _flock {
507 0     0   0 my($fh,$mode) = @_;
508 0 0 0     0 if ( $Config::Config{d_flock} || $Config::Config{d_fcntl_can_lock} ) {
    0          
509 0         0 return flock $fh, $mode;
510             } elsif (!$Have_warned->{"d_flock"}++) {
511 0         0 $CPAN::Frontend->mywarn("Your OS does not seem to support locking; continuing and ignoring all locking issues\n");
512 0         0 $CPAN::Frontend->mysleep(5);
513 0         0 return 1;
514             } else {
515 0         0 return 1;
516             }
517             }
518              
519             sub _yaml_module () {
520 3   50 3   23 my $yaml_module = $CPAN::Config->{yaml_module} || "YAML";
521 3 50 33     16 if (
522             $yaml_module ne "YAML"
523             &&
524             !$CPAN::META->has_inst($yaml_module)
525             ) {
526             # $CPAN::Frontend->mywarn("'$yaml_module' not installed, falling back to 'YAML'\n");
527 0         0 $yaml_module = "YAML";
528             }
529 3 0 33     18 if ($yaml_module eq "YAML"
      33        
      33        
530             &&
531             $CPAN::META->has_inst($yaml_module)
532             &&
533             $YAML::VERSION < 0.60
534             &&
535             !$Have_warned->{"YAML"}++
536             ) {
537 0         0 $CPAN::Frontend->mywarn("Warning: YAML version '$YAML::VERSION' is too low, please upgrade!\n".
538             "I'll continue but problems are *very* likely to happen.\n"
539             );
540 0         0 $CPAN::Frontend->mysleep(5);
541             }
542 3         11 return $yaml_module;
543             }
544              
545             # CPAN::_yaml_loadfile
546             sub _yaml_loadfile {
547 0     0   0 my($self,$local_file) = @_;
548 0 0       0 return +[] unless -s $local_file;
549 0         0 my $yaml_module = _yaml_module;
550 0 0       0 if ($CPAN::META->has_inst($yaml_module)) {
551             # temporarily enable yaml code deserialisation
552 7     7   54 no strict 'refs';
  7         19  
  7         33708  
553             # 5.6.2 could not do the local() with the reference
554             # so we do it manually instead
555 0         0 my $old_loadcode = ${"$yaml_module\::LoadCode"};
  0         0  
556 0   0     0 ${ "$yaml_module\::LoadCode" } = $CPAN::Config->{yaml_load_code} || 0;
  0         0  
557              
558 0         0 my ($code, @yaml);
559 0 0       0 if ($code = UNIVERSAL::can($yaml_module, "LoadFile")) {
    0          
560 0         0 eval { @yaml = $code->($local_file); };
  0         0  
561 0 0       0 if ($@) {
562             # this shall not be done by the frontend
563 0         0 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
564             }
565             } elsif ($code = UNIVERSAL::can($yaml_module, "Load")) {
566 0         0 local *FH;
567 0 0       0 open FH, $local_file or die "Could not open '$local_file': $!";
568 0         0 local $/;
569 0         0 my $ystream = ;
570 0         0 eval { @yaml = $code->($ystream); };
  0         0  
571 0 0       0 if ($@) {
572             # this shall not be done by the frontend
573 0         0 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
574             }
575             }
576 0         0 ${"$yaml_module\::LoadCode"} = $old_loadcode;
  0         0  
577 0         0 return \@yaml;
578             } else {
579             # this shall not be done by the frontend
580 0         0 die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "parse");
581             }
582 0         0 return +[];
583             }
584              
585             # CPAN::_yaml_dumpfile
586             sub _yaml_dumpfile {
587 0     0   0 my($self,$local_file,@what) = @_;
588 0         0 my $yaml_module = _yaml_module;
589 0 0       0 if ($CPAN::META->has_inst($yaml_module)) {
590 0         0 my $code;
591 0 0       0 if (UNIVERSAL::isa($local_file, "FileHandle")) {
    0          
    0          
592 0         0 $code = UNIVERSAL::can($yaml_module, "Dump");
593 0         0 eval { print $local_file $code->(@what) };
  0         0  
594             } elsif ($code = UNIVERSAL::can($yaml_module, "DumpFile")) {
595 0         0 eval { $code->($local_file,@what); };
  0         0  
596             } elsif ($code = UNIVERSAL::can($yaml_module, "Dump")) {
597 0         0 local *FH;
598 0 0       0 open FH, ">$local_file" or die "Could not open '$local_file': $!";
599 0         0 print FH $code->(@what);
600             }
601 0 0       0 if ($@) {
602 0         0 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"dump",$@);
603             }
604             } else {
605 0 0       0 if (UNIVERSAL::isa($local_file, "FileHandle")) {
606             # I think this case does not justify a warning at all
607             } else {
608 0         0 die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "dump");
609             }
610             }
611             }
612              
613             sub _init_sqlite () {
614 0 0   0   0 unless ($CPAN::META->has_inst("CPAN::SQLite")) {
615 0 0       0 $CPAN::Frontend->mywarn(qq{CPAN::SQLite not installed, trying to work without\n})
616             unless $Have_warned->{"CPAN::SQLite"}++;
617 0         0 return;
618             }
619 0         0 require CPAN::SQLite::META; # not needed since CVS version of 2006-12-17
620 0   0     0 $CPAN::SQLite ||= CPAN::SQLite::META->new($CPAN::META);
621             }
622              
623             {
624             my $negative_cache = {};
625             sub _sqlite_running {
626 127 100 66 127   661 if ($negative_cache->{time} && time < $negative_cache->{time} + 60) {
627             # need to cache the result, otherwise too slow
628 126         431 return $negative_cache->{fact};
629             } else {
630 1         3 $negative_cache = {}; # reset
631             }
632 1   33     6 my $ret = $CPAN::Config->{use_sqlite} && ($CPAN::SQLite || _init_sqlite());
633 1 50       4 return $ret if $ret; # fast anyway
634 1         3 $negative_cache->{time} = time;
635 1         5 return $negative_cache->{fact} = $ret;
636             }
637             }
638              
639             $META ||= CPAN->new; # In case we re-eval ourselves we need the ||
640              
641             # from here on only subs.
642             ################################################################################
643              
644             sub _perl_fingerprint {
645 0     0   0 my($self,$other_fingerprint) = @_;
646 0         0 my $dll = eval {OS2::DLLname()};
  0         0  
647 0         0 my $mtime_dll = 0;
648 0 0       0 if (defined $dll) {
649 0 0       0 $mtime_dll = (-f $dll ? (stat(_))[9] : '-1');
650             }
651 0 0       0 my $mtime_perl = (-f CPAN::find_perl ? (stat(_))[9] : '-1');
652 0         0 my $this_fingerprint = {
653             '$^X' => CPAN::find_perl,
654             sitearchexp => $Config::Config{sitearchexp},
655             'mtime_$^X' => $mtime_perl,
656             'mtime_dll' => $mtime_dll,
657             };
658 0 0       0 if ($other_fingerprint) {
659 0 0       0 if (exists $other_fingerprint->{'stat($^X)'}) { # repair fp from rev. 1.88_57
660 0         0 $other_fingerprint->{'mtime_$^X'} = $other_fingerprint->{'stat($^X)'}[9];
661             }
662             # mandatory keys since 1.88_57
663 0         0 for my $key (qw($^X sitearchexp mtime_dll mtime_$^X)) {
664 0 0       0 return unless $other_fingerprint->{$key} eq $this_fingerprint->{$key};
665             }
666 0         0 return 1;
667             } else {
668 0         0 return $this_fingerprint;
669             }
670             }
671              
672             sub suggest_myconfig () {
673 0 0   0 0 0 SUGGEST_MYCONFIG: if(!$INC{'CPAN/MyConfig.pm'}) {
674 0         0 $CPAN::Frontend->myprint("You don't seem to have a user ".
675             "configuration (MyConfig.pm) yet.\n");
676 0         0 my $new = CPAN::Shell::colorable_makemaker_prompt("Do you want to create a ".
677             "user configuration now? (Y/n)",
678             "yes");
679 0 0       0 if($new =~ m{^y}i) {
680 0         0 CPAN::Shell->mkmyconfig();
681 0         0 return &checklock;
682             } else {
683 0         0 $CPAN::Frontend->mydie("OK, giving up.");
684             }
685             }
686             }
687              
688             #-> sub CPAN::all_objects ;
689             sub all_objects {
690 0     0 0 0 my($mgr,$class) = @_;
691 0 0       0 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
692 0 0       0 CPAN->debug("mgr[$mgr] class[$class]") if $CPAN::DEBUG;
693 0         0 CPAN::Index->reload;
694 0         0 values %{ $META->{readwrite}{$class} }; # unsafe meta access, ok
  0         0  
695             }
696              
697             # Called by shell, not in batch mode. In batch mode I see no risk in
698             # having many processes updating something as installations are
699             # continually checked at runtime. In shell mode I suspect it is
700             # unintentional to open more than one shell at a time
701              
702             #-> sub CPAN::checklock ;
703             sub checklock {
704 0     0 0 0 my($self) = @_;
705 0         0 my $lockfile = File::Spec->catfile($CPAN::Config->{cpan_home},".lock");
706 0 0 0     0 if (-f $lockfile && -M _ > 0) {
707 0 0       0 my $fh = FileHandle->new($lockfile) or
708             $CPAN::Frontend->mydie("Could not open lockfile '$lockfile': $!");
709 0         0 my $otherpid = <$fh>;
710 0         0 my $otherhost = <$fh>;
711 0         0 $fh->close;
712 0 0 0     0 if (defined $otherpid && $otherpid) {
713 0         0 chomp $otherpid;
714             }
715 0 0 0     0 if (defined $otherhost && $otherhost) {
716 0         0 chomp $otherhost;
717             }
718 0         0 my $thishost = hostname();
719 0 0 0     0 if (defined $otherhost && defined $thishost &&
    0 0        
    0 0        
      0        
      0        
720             $otherhost ne '' && $thishost ne '' &&
721             $otherhost ne $thishost) {
722 0         0 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile '$lockfile'\n".
723             "reports other host $otherhost and other ".
724             "process $otherpid.\n".
725             "Cannot proceed.\n"));
726             } elsif ($RUN_DEGRADED) {
727 0         0 $CPAN::Frontend->mywarn("Running in downgraded mode (experimental)\n");
728             } elsif (defined $otherpid && $otherpid) {
729 0 0       0 return if $$ == $otherpid; # should never happen
730 0         0 $CPAN::Frontend->mywarn(
731             qq{
732             There seems to be running another CPAN process (pid $otherpid). Contacting...
733             });
734 3 0 0 3   4039 if (kill 0, $otherpid or $!{EPERM}) {
  3 0       4458  
  3         18644  
  0         0  
735 0         0 $CPAN::Frontend->mywarn(qq{Other job is running.\n});
736 0         0 my($ans) =
737             CPAN::Shell::colorable_makemaker_prompt
738             (qq{Shall I try to run in downgraded }.
739             qq{mode? (Y/n)},"y");
740 0 0       0 if ($ans =~ /^y/i) {
741 0         0 $CPAN::Frontend->mywarn("Running in downgraded mode (experimental).
742             Please report if something unexpected happens\n");
743 0         0 $RUN_DEGRADED = 1;
744 0         0 for ($CPAN::Config) {
745             # XXX
746             # $_->{build_dir_reuse} = 0; # 2006-11-17 akoenig Why was that?
747 0         0 $_->{commandnumber_in_prompt} = 0; # visibility
748 0         0 $_->{histfile} = ""; # who should win otherwise?
749 0         0 $_->{cache_metadata} = 0; # better would be a lock?
750 0         0 $_->{use_sqlite} = 0; # better would be a write lock!
751 0         0 $_->{auto_commit} = 0; # we are violent, do not persist
752 0         0 $_->{test_report} = 0; # Oliver Paukstadt had sent wrong reports in degraded mode
753             }
754             } else {
755 0         0 $CPAN::Frontend->mydie("
756             You may want to kill the other job and delete the lockfile. On UNIX try:
757             kill $otherpid
758             rm $lockfile
759             ");
760             }
761             } elsif (-w $lockfile) {
762 0         0 my($ans) =
763             CPAN::Shell::colorable_makemaker_prompt
764             (qq{Other job not responding. Shall I overwrite }.
765             qq{the lockfile '$lockfile'? (Y/n)},"y");
766 0 0       0 $CPAN::Frontend->myexit("Ok, bye\n")
767             unless $ans =~ /^y/i;
768             } else {
769 0         0 Carp::croak(
770             qq{Lockfile '$lockfile' not writable by you. }.
771             qq{Cannot proceed.\n}.
772             qq{ On UNIX try:\n}.
773             qq{ rm '$lockfile'\n}.
774             qq{ and then rerun us.\n}
775             );
776             }
777             } else {
778 0         0 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Found invalid lockfile ".
779             "'$lockfile', please remove. Cannot proceed.\n"));
780             }
781             }
782 0         0 my $dotcpan = $CPAN::Config->{cpan_home};
783 0         0 eval { File::Path::mkpath($dotcpan);};
  0         0  
784 0 0       0 if ($@) {
785             # A special case at least for Jarkko.
786 0         0 my $firsterror = $@;
787 0         0 my $seconderror;
788             my $symlinkcpan;
789 0 0       0 if (-l $dotcpan) {
790 0         0 $symlinkcpan = readlink $dotcpan;
791 0 0       0 die "readlink $dotcpan failed: $!" unless defined $symlinkcpan;
792 0         0 eval { File::Path::mkpath($symlinkcpan); };
  0         0  
793 0 0       0 if ($@) {
794 0         0 $seconderror = $@;
795             } else {
796 0         0 $CPAN::Frontend->mywarn(qq{
797             Working directory $symlinkcpan created.
798             });
799             }
800             }
801 0 0       0 unless (-d $dotcpan) {
802 0         0 my $mess = qq{
803             Your configuration suggests "$dotcpan" as your
804             CPAN.pm working directory. I could not create this directory due
805             to this error: $firsterror\n};
806 0 0       0 $mess .= qq{
807             As "$dotcpan" is a symlink to "$symlinkcpan",
808             I tried to create that, but I failed with this error: $seconderror
809             } if $seconderror;
810 0         0 $mess .= qq{
811             Please make sure the directory exists and is writable.
812             };
813 0         0 $CPAN::Frontend->mywarn($mess);
814 0         0 return suggest_myconfig;
815             }
816             } # $@ after eval mkpath $dotcpan
817 0         0 if (0) { # to test what happens when a race condition occurs
818             for (reverse 1..10) {
819             print $_, "\n";
820             sleep 1;
821             }
822             }
823             # locking
824 0 0 0     0 if (!$RUN_DEGRADED && !$self->{LOCKFH}) {
825 0         0 my $fh;
826 0 0       0 unless ($fh = FileHandle->new("+>>$lockfile")) {
827 0         0 $CPAN::Frontend->mywarn(qq{
828              
829             Your configuration suggests that CPAN.pm should use a working
830             directory of
831             $CPAN::Config->{cpan_home}
832             Unfortunately we could not create the lock file
833             $lockfile
834             due to '$!'.
835              
836             Please make sure that the configuration variable
837             \$CPAN::Config->{cpan_home}
838             points to a directory where you can write a .lock file. You can set
839             this variable in either a CPAN/MyConfig.pm or a CPAN/Config.pm in your
840             \@INC path;
841             });
842 0         0 return suggest_myconfig;
843             }
844 0         0 my $sleep = 1;
845 0         0 while (!CPAN::_flock($fh, LOCK_EX|LOCK_NB)) {
846 0 0       0 if ($sleep>10) {
847 0         0 $CPAN::Frontend->mydie("Giving up\n");
848             }
849 0         0 $CPAN::Frontend->mysleep($sleep++);
850 0         0 $CPAN::Frontend->mywarn("Could not lock lockfile with flock: $!; retrying\n");
851             }
852              
853 0         0 seek $fh, 0, 0;
854 0         0 truncate $fh, 0;
855 0         0 $fh->autoflush(1);
856 0         0 $fh->print($$, "\n");
857 0         0 $fh->print(hostname(), "\n");
858 0         0 $self->{LOCK} = $lockfile;
859 0         0 $self->{LOCKFH} = $fh;
860             }
861             $SIG{TERM} = sub {
862 0     0   0 my $sig = shift;
863 0         0 &cleanup;
864 0         0 $CPAN::Frontend->mydie("Got SIG$sig, leaving");
865 0         0 };
866             $SIG{INT} = sub {
867             # no blocks!!!
868 0     0   0 my $sig = shift;
869 0 0       0 &cleanup if $Signal;
870 0 0       0 die "Got yet another signal" if $Signal > 1;
871 0 0       0 $CPAN::Frontend->mydie("Got another SIG$sig") if $Signal;
872 0         0 $CPAN::Frontend->mywarn("Caught SIG$sig, trying to continue\n");
873 0         0 $Signal++;
874 0         0 };
875              
876             # From: Larry Wall
877             # Subject: Re: deprecating SIGDIE
878             # To: perl5-porters@perl.org
879             # Date: Thu, 30 Sep 1999 14:58:40 -0700 (PDT)
880             #
881             # The original intent of __DIE__ was only to allow you to substitute one
882             # kind of death for another on an application-wide basis without respect
883             # to whether you were in an eval or not. As a global backstop, it should
884             # not be used any more lightly (or any more heavily :-) than class
885             # UNIVERSAL. Any attempt to build a general exception model on it should
886             # be politely squashed. Any bug that causes every eval {} to have to be
887             # modified should be not so politely squashed.
888             #
889             # Those are my current opinions. It is also my opinion that polite
890             # arguments degenerate to personal arguments far too frequently, and that
891             # when they do, it's because both people wanted it to, or at least didn't
892             # sufficiently want it not to.
893             #
894             # Larry
895              
896             # global backstop to cleanup if we should really die
897 0         0 $SIG{__DIE__} = \&cleanup;
898 0 0       0 $self->debug("Signal handler set.") if $CPAN::DEBUG;
899             }
900              
901             #-> sub CPAN::DESTROY ;
902             sub DESTROY {
903 0     0   0 &cleanup; # need an eval?
904             }
905              
906             #-> sub CPAN::anycwd ;
907             sub anycwd () {
908 7     7 1 23 my $getcwd;
909 7   100     50 $getcwd = $CPAN::Config->{'getcwd'} || 'cwd';
910 7         59 CPAN->$getcwd();
911             }
912              
913             #-> sub CPAN::cwd ;
914 7     7 1 71534 sub cwd {Cwd::cwd();}
915              
916             #-> sub CPAN::getcwd ;
917 0     0 1 0 sub getcwd {Cwd::getcwd();}
918              
919             #-> sub CPAN::fastcwd ;
920 0     0 1 0 sub fastcwd {Cwd::fastcwd();}
921              
922             #-> sub CPAN::backtickcwd ;
923 0     0 1 0 sub backtickcwd {my $cwd = `cwd`; chomp $cwd; $cwd}
  0         0  
  0         0  
924              
925             # Adapted from Probe::Perl
926             #-> sub CPAN::_perl_is_same
927             sub _perl_is_same {
928 0     0   0 my ($perl) = @_;
929 0   0     0 return MM->maybe_command($perl)
930             && `$perl -MConfig=myconfig -e print -e myconfig` eq Config->myconfig;
931             }
932              
933             # Adapted in part from Probe::Perl
934             #-> sub CPAN::find_perl ;
935             sub find_perl () {
936 7 50   7 0 644 if ( File::Spec->file_name_is_absolute($^X) ) {
937 7         266 return $^X;
938             }
939             else {
940 0         0 my $exe = $Config::Config{exe_ext};
941 0         0 my @candidates = (
942             File::Spec->catfile($CPAN::iCwd,$^X),
943             $Config::Config{'perlpath'},
944             );
945 0         0 for my $perl_name ($^X, 'perl', 'perl5', "perl$]") {
946 0         0 for my $path (File::Spec->path(), $Config::Config{'binexp'}) {
947 0 0 0     0 if ( defined($path) && length $path && -d $path ) {
      0        
948 0         0 my $perl = File::Spec->catfile($path,$perl_name);
949 0         0 push @candidates, $perl;
950             # try with extension if not provided already
951 0 0 0     0 if ($^O eq 'VMS') {
    0          
952             # VMS might have a file version at the end
953 0 0       0 push @candidates, $perl . $exe
954             unless $perl =~ m/$exe(;\d+)?$/i;
955             } elsif (defined $exe && length $exe) {
956 0 0       0 push @candidates, $perl . $exe
957             unless $perl =~ m/$exe$/i;
958             }
959             }
960             }
961             }
962 0         0 for my $perl ( @candidates ) {
963 0 0 0     0 if (MM->maybe_command($perl) && _perl_is_same($perl)) {
964 0         0 $^X = $perl;
965 0         0 return $perl;
966             }
967             }
968             }
969 0         0 return $^X; # default fall back
970             }
971              
972             #-> sub CPAN::exists ;
973             sub exists {
974 31     31 0 85 my($mgr,$class,$id) = @_;
975 31 50       67 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
976 31         117 CPAN::Index->reload;
977             ### Carp::croak "exists called without class argument" unless $class;
978 31   50     72 $id ||= "";
979 31 100       103 $id =~ s/:+/::/g if $class eq "CPAN::Module";
980 31         57 my $exists;
981 31 50       71 if (CPAN::_sqlite_running) {
982 0   0     0 $exists = (exists $META->{readonly}{$class}{$id} or
983             $CPAN::SQLite->set($class, $id));
984             } else {
985 31         155 $exists = exists $META->{readonly}{$class}{$id};
986             }
987 31   66     240 $exists ||= exists $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
988             }
989              
990             #-> sub CPAN::delete ;
991             sub delete {
992 0     0 0 0 my($mgr,$class,$id) = @_;
993 0         0 delete $META->{readonly}{$class}{$id}; # unsafe meta access, ok
994 0         0 delete $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
995             }
996              
997             #-> sub CPAN::has_usable
998             # has_inst is sometimes too optimistic, we should replace it with this
999             # has_usable whenever a case is given
1000             sub has_usable {
1001 116     116 1 265 my($self,$mod,$message) = @_;
1002 116 100       669 return 1 if $HAS_USABLE->{$mod};
1003 4         47 my $has_inst = $self->has_inst($mod,$message);
1004 4 50       29 return unless $has_inst;
1005 4         12 my $usable;
1006             $usable = {
1007              
1008             #
1009             # these subroutines die if they believe the installed version is unusable;
1010             #
1011             'CPAN::Meta' => [
1012             sub {
1013 1     1   9 require CPAN::Meta;
1014 1 50       41 unless (CPAN::Version->vge(CPAN::Meta->VERSION, 2.110350)) {
1015 0         0 for ("Will not use CPAN::Meta, need version 2.110350\n") {
1016 0         0 $CPAN::Frontend->mywarn($_);
1017 0         0 die $_;
1018             }
1019             }
1020             },
1021 0     0   0 ],
1022              
1023             LWP => [ # we frequently had "Can't locate object
1024             # method "new" via package "LWP::UserAgent" at
1025             # (eval 69) line 2006
1026             sub {require LWP},
1027 0     0   0 sub {require LWP::UserAgent},
1028 0     0   0 sub {require HTTP::Request},
1029 0     0   0 sub {require URI::URL;
1030 0 0       0 unless (CPAN::Version->vge(URI::URL::->VERSION,0.08)) {
1031 0         0 for ("Will not use URI::URL, need 0.08\n") {
1032 0         0 $CPAN::Frontend->mywarn($_);
1033 0         0 die $_;
1034             }
1035             }
1036             },
1037 0     0   0 ],
1038             'Net::FTP' => [
1039             sub {require Net::FTP},
1040 0     0   0 sub {require Net::Config},
1041             ],
1042             'HTTP::Tiny' => [
1043             sub {
1044 0     0   0 require HTTP::Tiny;
1045 0 0       0 unless (CPAN::Version->vge(HTTP::Tiny->VERSION, 0.005)) {
1046 0         0 for ("Will not use HTTP::Tiny, need version 0.005\n") {
1047 0         0 $CPAN::Frontend->mywarn($_);
1048 0         0 die $_;
1049             }
1050             }
1051             },
1052 0     0   0 ],
1053             'File::HomeDir' => [
1054             sub {require File::HomeDir;
1055 0 0       0 unless (CPAN::Version->vge(File::HomeDir::->VERSION, 0.52)) {
1056 0         0 for ("Will not use File::HomeDir, need 0.52\n") {
1057 0         0 $CPAN::Frontend->mywarn($_);
1058 0         0 die $_;
1059             }
1060             }
1061             },
1062 1     1   14 ],
1063             'Archive::Tar' => [
1064             sub {require Archive::Tar;
1065 1         3 my $demand = "1.50";
1066 1 50       45 unless (CPAN::Version->vge(Archive::Tar::->VERSION, $demand)) {
1067 0         0 my $atv = Archive::Tar->VERSION;
1068 0         0 for ("You have Archive::Tar $atv, but $demand or later is recommended. Please upgrade.\n") {
1069 0         0 $CPAN::Frontend->mywarn($_);
1070             # don't die, because we may need
1071             # Archive::Tar to upgrade
1072             }
1073              
1074             }
1075             },
1076 0     0   0 ],
1077             'File::Temp' => [
1078             # XXX we should probably delete from
1079             # %INC too so we can load after we
1080             # installed a new enough version --
1081             # I'm not sure.
1082             sub {require File::Temp;
1083 0 0       0 unless (CPAN::Version->vge(File::Temp::->VERSION,0.16)) {
1084 0         0 for ("Will not use File::Temp, need 0.16\n") {
1085 0         0 $CPAN::Frontend->mywarn($_);
1086 0         0 die $_;
1087             }
1088             }
1089             },
1090 4         246 ]
1091             };
1092 4 100       33 if ($usable->{$mod}) {
1093 2         5 for my $c (0..$#{$usable->{$mod}}) {
  2         15  
1094 2         7 my $code = $usable->{$mod}[$c];
1095 2         6 my $ret = eval { &$code() };
  2         9  
1096 2 50       15 $ret = "" unless defined $ret;
1097 2 50       11 if ($@) {
1098             # warn "DEBUG: c[$c]\$\@[$@]ret[$ret]";
1099 0         0 return;
1100             }
1101             }
1102             }
1103 4         226 return $HAS_USABLE->{$mod} = 1;
1104             }
1105              
1106             #-> sub CPAN::has_inst
1107             sub has_inst {
1108 40     40 1 2713 my($self,$mod,$message) = @_;
1109 40 50       176 Carp::croak("CPAN->has_inst() called without an argument")
1110             unless defined $mod;
1111 15 100       42 my %dont = map { $_ => 1 } keys %{$CPAN::META->{dontload_hash}||{}},
  40 50       345  
  40         252  
1112 40 50       224 keys %{$CPAN::Config->{dontload_hash}||{}},
1113 40         51 @{$CPAN::Config->{dontload_list}||[]};
1114 40 100 66     319 if (defined $message && $message eq "no" # as far as I remember only used by Nox
      100        
1115             ||
1116             $dont{$mod}
1117             ) {
1118 9   100     72 $CPAN::META->{dontload_hash}{$mod}||=1; # unsafe meta access, ok
1119 9         35 return 0;
1120             }
1121 31         54 my $file = $mod;
1122 31         37 my $obj;
1123 31         127 $file =~ s|::|/|g;
1124 31         50 $file .= ".pm";
1125 31 100       100 if ($INC{$file}) {
    100          
    50          
    50          
    50          
1126             # checking %INC is wrong, because $INC{LWP} may be true
1127             # although $INC{"URI/URL.pm"} may have failed. But as
1128             # I really want to say "blah loaded OK", I have to somehow
1129             # cache results.
1130             ### warn "$file in %INC"; #debug
1131 18         89 return 1;
1132 13         15369 } elsif (eval { require $file }) {
1133             # eval is good: if we haven't yet read the database it's
1134             # perfect and if we have installed the module in the meantime,
1135             # it tries again. The second require is only a NOOP returning
1136             # 1 if we had success, otherwise it's retrying
1137              
1138 7         330192 my $mtime = (stat $INC{$file})[9];
1139             # privileged files loaded by has_inst; Note: we use $mtime
1140             # as a proxy for a checksum.
1141 7         58 $CPAN::Shell::reload->{$file} = $mtime;
1142 7         1214 my $v = eval "\$$mod\::VERSION";
1143 7 50       85 $v = $v ? " (v$v)" : "";
1144 7         178 CPAN::Shell->optprint("load_module","CPAN: $mod loaded ok$v\n");
1145 7 50       37 if ($mod eq "CPAN::WAIT") {
1146 0         0 push @CPAN::Shell::ISA, 'CPAN::WAIT';
1147             }
1148 7         67 return 1;
1149             } elsif ($mod eq "Net::FTP") {
1150 0 0       0 $CPAN::Frontend->mywarn(qq{
1151             Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
1152             if you just type
1153             install Bundle::libnet
1154              
1155             }) unless $Have_warned->{"Net::FTP"}++;
1156 0         0 $CPAN::Frontend->mysleep(3);
1157             } elsif ($mod eq "Digest::SHA") {
1158 0 0       0 if ($Have_warned->{"Digest::SHA"}++) {
1159 0         0 $CPAN::Frontend->mywarn(qq{CPAN: checksum security checks disabled }.
1160             qq{because Digest::SHA not installed.\n});
1161             } else {
1162 0         0 $CPAN::Frontend->mywarn(qq{
1163             CPAN: checksum security checks disabled because Digest::SHA not installed.
1164             Please consider installing the Digest::SHA module.
1165              
1166             });
1167 0         0 $CPAN::Frontend->mysleep(2);
1168             }
1169             } elsif ($mod eq "Module::Signature") {
1170             # NOT prefs_lookup, we are not a distro
1171 0         0 my $check_sigs = $CPAN::Config->{check_sigs};
1172 0 0       0 if (not $check_sigs) {
    0          
1173             # they do not want us:-(
1174             } elsif (not $Have_warned->{"Module::Signature"}++) {
1175             # No point in complaining unless the user can
1176             # reasonably install and use it.
1177 0 0 0     0 if (eval { require Crypt::OpenPGP; 1 } ||
  0   0     0  
  0         0  
1178             (
1179             defined $CPAN::Config->{'gpg'}
1180             &&
1181             $CPAN::Config->{'gpg'} =~ /\S/
1182             )
1183             ) {
1184 0         0 $CPAN::Frontend->mywarn(qq{
1185             CPAN: Module::Signature security checks disabled because Module::Signature
1186             not installed. Please consider installing the Module::Signature module.
1187             You may also need to be able to connect over the Internet to the public
1188             key servers like pool.sks-keyservers.net or pgp.mit.edu.
1189              
1190             });
1191 0         0 $CPAN::Frontend->mysleep(2);
1192             }
1193             }
1194             } else {
1195 6         15 delete $INC{$file}; # if it inc'd LWP but failed during, say, URI
1196             }
1197 6         50 return 0;
1198             }
1199              
1200             #-> sub CPAN::instance ;
1201             sub instance {
1202 43     43 1 122 my($mgr,$class,$id) = @_;
1203 43         197 CPAN::Index->reload;
1204 43   50     92 $id ||= "";
1205             # unsafe meta access, ok?
1206 43 100       169 return $META->{readwrite}{$class}{$id} if exists $META->{readwrite}{$class}{$id};
1207 39   33     328 $META->{readwrite}{$class}{$id} ||= $class->new(ID => $id);
1208             }
1209              
1210             #-> sub CPAN::new ;
1211             sub new {
1212 7     7 0 151 bless {}, shift;
1213             }
1214              
1215             #-> sub CPAN::_exit_messages ;
1216             sub _exit_messages {
1217 0     0   0 my ($self) = @_;
1218 0   0     0 $self->{exit_messages} ||= [];
1219             }
1220              
1221             #-> sub CPAN::cleanup ;
1222             sub cleanup {
1223             # warn "cleanup called with arg[@_] End[$CPAN::End] Signal[$Signal]";
1224 7     7 0 58 local $SIG{__DIE__} = '';
1225 7         24 my($message) = @_;
1226 7         25 my $i = 0;
1227 7         30 my $ineval = 0;
1228 7         25 my($subroutine);
1229 7         107 while ((undef,undef,undef,$subroutine) = caller(++$i)) {
1230 14 100       108 $ineval = 1, last if
1231             $subroutine eq '(eval)';
1232             }
1233 7 50 33     109 return if $ineval && !$CPAN::End;
1234 7 50       109 return unless defined $META->{LOCK};
1235 0 0         return unless -f $META->{LOCK};
1236 0           $META->savehist;
1237 0   0       $META->{cachemgr} ||= CPAN::CacheMgr->new('atexit');
1238 0           close $META->{LOCKFH};
1239 0           unlink $META->{LOCK};
1240             # require Carp;
1241             # Carp::cluck("DEBUGGING");
1242 0 0         if ( $CPAN::CONFIG_DIRTY ) {
1243 0           $CPAN::Frontend->mywarn("Warning: Configuration not saved.\n");
1244             }
1245 0           $CPAN::Frontend->myprint("Lockfile removed.\n");
1246 0           for my $msg ( @{ $META->_exit_messages } ) {
  0            
1247 0           $CPAN::Frontend->myprint($msg);
1248             }
1249             }
1250              
1251             #-> sub CPAN::readhist
1252             sub readhist {
1253 0     0 0   my($self,$term,$histfile) = @_;
1254 0   0       my $histsize = $CPAN::Config->{'histsize'} || 100;
1255 0 0         $term->Attribs->{'MaxHistorySize'} = $histsize if (defined($term->Attribs->{'MaxHistorySize'}));
1256 0           my($fh) = FileHandle->new;
1257 0 0         open $fh, "<$histfile" or return;
1258 0           local $/ = "\n";
1259 0           while (<$fh>) {
1260 0           chomp;
1261 0           $term->AddHistory($_);
1262             }
1263 0           close $fh;
1264             }
1265              
1266             #-> sub CPAN::savehist
1267             sub savehist {
1268 0     0 0   my($self) = @_;
1269 0           my($histfile,$histsize);
1270 0 0         unless ($histfile = $CPAN::Config->{'histfile'}) {
1271 0           $CPAN::Frontend->mywarn("No history written (no histfile specified).\n");
1272 0           return;
1273             }
1274 0   0       $histsize = $CPAN::Config->{'histsize'} || 100;
1275 0 0         if ($CPAN::term) {
1276 0 0         unless ($CPAN::term->can("GetHistory")) {
1277 0           $CPAN::Frontend->mywarn("Terminal does not support GetHistory.\n");
1278 0           return;
1279             }
1280             } else {
1281 0           return;
1282             }
1283 0           my @h = $CPAN::term->GetHistory;
1284 0 0         splice @h, 0, @h-$histsize if @h>$histsize;
1285 0           my($fh) = FileHandle->new;
1286 0 0         open $fh, ">$histfile" or $CPAN::Frontend->mydie("Couldn't open >$histfile: $!");
1287 0           local $\ = local $, = "\n";
1288 0           print $fh @h;
1289 0           close $fh;
1290             }
1291              
1292             #-> sub CPAN::is_tested
1293             sub is_tested {
1294 0     0 1   my($self,$what,$when) = @_;
1295 0 0         unless ($what) {
1296 0           Carp::cluck("DEBUG: empty what");
1297 0           return;
1298             }
1299 0           $self->{is_tested}{$what} = $when;
1300             }
1301              
1302             #-> sub CPAN::reset_tested
1303             # forget all distributions tested -- resets what gets included in PERL5LIB
1304             sub reset_tested {
1305 0     0 0   my ($self) = @_;
1306 0           $self->{is_tested} = {};
1307             }
1308              
1309             #-> sub CPAN::is_installed
1310             # unsets the is_tested flag: as soon as the thing is installed, it is
1311             # not needed in set_perl5lib anymore
1312             sub is_installed {
1313 0     0 0   my($self,$what) = @_;
1314 0           delete $self->{is_tested}{$what};
1315             }
1316              
1317             sub _list_sorted_descending_is_tested {
1318 0     0     my($self) = @_;
1319 0           my $foul = 0;
1320 0   0       my @sorted = sort
      0        
1321             { ($self->{is_tested}{$b}||0) <=> ($self->{is_tested}{$a}||0) }
1322             grep
1323 0 0         { if ($foul){ 0 } elsif (-e) { 1 } else { $foul = $_; 0 } }
  0 0          
  0            
  0            
  0            
  0            
1324 0           keys %{$self->{is_tested}};
1325 0 0         if ($foul) {
1326 0           $CPAN::Frontend->mywarn("Lost build_dir detected ($foul), giving up all cached test results of currently running session.\n");
1327 0           for my $dbd (keys %{$self->{is_tested}}) { # distro-build-dir
  0            
1328 0           SEARCH: for my $d ($CPAN::META->all_objects("CPAN::Distribution")) {
1329 0 0 0       if ($d->{build_dir} && $d->{build_dir} eq $dbd) {
1330 0           $CPAN::Frontend->mywarn(sprintf "Flushing cache for %s\n", $d->pretty_id);
1331 0           $d->fforce("");
1332 0           last SEARCH;
1333             }
1334             }
1335 0           delete $self->{is_tested}{$dbd};
1336             }
1337 0           return ();
1338             } else {
1339 0           return @sorted;
1340             }
1341             }
1342              
1343             #-> sub CPAN::set_perl5lib
1344             # Notes on max environment variable length:
1345             # - Win32 : XP or later, 8191; Win2000 or NT4, 2047
1346             {
1347             my $fh;
1348             sub set_perl5lib {
1349 0     0 0   my($self,$for) = @_;
1350 0 0         unless ($for) {
1351 0           (undef,undef,undef,$for) = caller(1);
1352 0           $for =~ s/.*://;
1353             }
1354 0   0       $self->{is_tested} ||= {};
1355 0 0         return unless %{$self->{is_tested}};
  0            
1356 0           my $env = $ENV{PERL5LIB};
1357 0 0         $env = $ENV{PERLLIB} unless defined $env;
1358 0           my @env;
1359 0 0 0       push @env, split /\Q$Config::Config{path_sep}\E/, $env if defined $env and length $env;
1360             #my @dirs = map {("$_/blib/arch", "$_/blib/lib")} keys %{$self->{is_tested}};
1361             #$CPAN::Frontend->myprint("Prepending @dirs to PERL5LIB.\n");
1362              
1363 0           my @dirs = map {("$_/blib/arch", "$_/blib/lib")} $self->_list_sorted_descending_is_tested;
  0            
1364 0 0         return if !@dirs;
1365              
1366 0 0         if (@dirs < 12) {
    0          
1367 0           $CPAN::Frontend->optprint('perl5lib', "Prepending @dirs to PERL5LIB for '$for'\n");
1368 0           $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1369             } elsif (@dirs < 24 ) {
1370 0           my @d = map {my $cp = $_;
  0            
1371 0           $cp =~ s/^\Q$CPAN::Config->{build_dir}\E/%BUILDDIR%/;
1372 0           $cp
1373             } @dirs;
1374 0           $CPAN::Frontend->optprint('perl5lib', "Prepending @d to PERL5LIB; ".
1375             "%BUILDDIR%=$CPAN::Config->{build_dir} ".
1376             "for '$for'\n"
1377             );
1378 0           $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1379             } else {
1380 0           my $cnt = keys %{$self->{is_tested}};
  0            
1381 0           $CPAN::Frontend->optprint('perl5lib', "Prepending blib/arch and blib/lib of ".
1382             "$cnt build dirs to PERL5LIB; ".
1383             "for '$for'\n"
1384             );
1385 0           $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1386             }
1387             }}
1388              
1389              
1390             1;
1391              
1392              
1393             __END__