1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
4 $VERSION = eval $VERSION;
7 use CPAN::HandleConfig;
16 use ExtUtils::MakeMaker (); # $SelfLoader::DEBUG=1;
17 use File::Basename ();
25 use Sys::Hostname qw(hostname);
26 use Text::ParseWords ();
28 no lib "."; # we need to run chdir all over and we would get at wrong
31 require Mac::BuildTools if $^O eq 'MacOS';
33 END { $CPAN::End++; &cleanup; }
36 $CPAN::Frontend ||= "CPAN::Shell";
37 $CPAN::Defaultsite ||= "ftp://ftp.perl.org/pub/CPAN";
38 # $CPAN::iCwd (i for initial) is going to be initialized during find_perl
39 $CPAN::Perl ||= CPAN::find_perl();
40 $CPAN::Defaultdocs ||= "http://search.cpan.org/perldoc?";
41 $CPAN::Defaultrecent ||= "http://search.cpan.org/recent";
47 use vars qw($VERSION @EXPORT $AUTOLOAD $DEBUG $META $HAS_USABLE $term
48 $Signal $Suppress_readline $Frontend
49 $Defaultsite $Have_warned $Defaultdocs $Defaultrecent
52 @CPAN::ISA = qw(CPAN::Debug Exporter);
55 autobundle bundle expand force notest get cvs_import
56 install make readme recompile shell test clean
60 sub soft_chdir_with_alternatives ($);
62 #-> sub CPAN::AUTOLOAD ;
67 @EXPORT{@EXPORT} = '';
68 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
69 if (exists $EXPORT{$l}){
72 $CPAN::Frontend->mywarn(qq{Unknown CPAN command "$AUTOLOAD". }.
81 $Suppress_readline = ! -t STDIN unless defined $Suppress_readline;
82 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
84 my $oprompt = shift || CPAN::Prompt->new;
85 my $prompt = $oprompt;
86 my $commandline = shift || "";
87 $CPAN::CurrentCommandId ||= 1;
90 unless ($Suppress_readline) {
91 require Term::ReadLine;
94 $term->ReadLine eq "Term::ReadLine::Stub"
96 $term = Term::ReadLine->new('CPAN Monitor');
98 if ($term->ReadLine eq "Term::ReadLine::Gnu") {
99 my $attribs = $term->Attribs;
100 $attribs->{attempted_completion_function} = sub {
101 &CPAN::Complete::gnu_cpl;
104 $readline::rl_completion_function =
105 $readline::rl_completion_function = 'CPAN::Complete::cpl';
107 if (my $histfile = $CPAN::Config->{'histfile'}) {{
108 unless ($term->can("AddHistory")) {
109 $CPAN::Frontend->mywarn("Terminal does not support AddHistory.\n");
112 my($fh) = FileHandle->new;
113 open $fh, "<$histfile" or last;
117 $term->AddHistory($_);
121 # $term->OUT is autoflushed anyway
122 my $odef = select STDERR;
129 # no strict; # I do not recall why no strict was here (2000-09-03)
131 my @cwd = (CPAN::anycwd(),File::Spec->tmpdir(),File::Spec->rootdir());
132 my $try_detect_readline;
133 $try_detect_readline = $term->ReadLine eq "Term::ReadLine::Stub" if $term;
134 my $rl_avail = $Suppress_readline ? "suppressed" :
135 ($term->ReadLine ne "Term::ReadLine::Stub") ? "enabled" :
136 "available (try 'install Bundle::CPAN')";
138 $CPAN::Frontend->myprint(
140 cpan shell -- CPAN exploration and modules installation (v%s)
147 unless $CPAN::Config->{'inhibit_startup_message'} ;
148 my($continuation) = "";
149 SHELLCOMMAND: while () {
150 if ($Suppress_readline) {
152 last SHELLCOMMAND unless defined ($_ = <> );
155 last SHELLCOMMAND unless
156 defined ($_ = $term->readline($prompt, $commandline));
158 $_ = "$continuation$_" if $continuation;
160 next SHELLCOMMAND if /^$/;
161 $_ = 'h' if /^\s*\?/;
162 if (/^(?:q(?:uit)?|bye|exit)$/i) {
173 use vars qw($import_done);
174 CPAN->import(':DEFAULT') unless $import_done++;
175 CPAN->debug("eval[$eval]") if $CPAN::DEBUG;
182 if ($] < 5.00322) { # parsewords had a bug until recently
185 eval { @line = Text::ParseWords::shellwords($_) };
186 warn($@), next SHELLCOMMAND if $@;
187 warn("Text::Parsewords could not parse the line [$_]"),
188 next SHELLCOMMAND unless @line;
190 $CPAN::META->debug("line[".join("|",@line)."]") if $CPAN::DEBUG;
191 my $command = shift @line;
192 eval { CPAN::Shell->$command(@line) };
194 if ($command =~ /^(make|test|install|force|notest)$/) {
195 CPAN::Shell->failed($CPAN::CurrentCommandId,1);
197 soft_chdir_with_alternatives(\@cwd);
198 $CPAN::Frontend->myprint("\n");
200 $CPAN::CurrentCommandId++;
204 $commandline = ""; # I do want to be able to pass a default to
205 # shell, but on the second command I see no
208 CPAN::Queue->nullify_queue;
209 if ($try_detect_readline) {
210 if ($CPAN::META->has_inst("Term::ReadLine::Gnu")
212 $CPAN::META->has_inst("Term::ReadLine::Perl")
214 delete $INC{"Term/ReadLine.pm"};
216 local($SIG{__WARN__}) = CPAN::Shell::paintdots_onreload(\$redef);
217 require Term::ReadLine;
218 $CPAN::Frontend->myprint("\n$redef subroutines in ".
219 "Term::ReadLine redefined\n");
225 soft_chdir_with_alternatives(\@cwd);
228 sub soft_chdir_with_alternatives ($) {
230 while (not chdir $cwd->[0]) {
232 $CPAN::Frontend->mywarn(qq{Could not chdir to "$cwd->[0]": $!
233 Trying to chdir to "$cwd->[1]" instead.
237 $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd->[0]": $!});
241 package CPAN::CacheMgr;
243 @CPAN::CacheMgr::ISA = qw(CPAN::InfoObj CPAN);
248 use vars qw($Ua $Thesite $Themethod);
249 @CPAN::FTP::ISA = qw(CPAN::Debug);
251 package CPAN::LWP::UserAgent;
253 use vars qw(@ISA $USER $PASSWD $SETUPDONE);
254 # we delay requiring LWP::UserAgent and setting up inheritance until we need it
256 package CPAN::Complete;
258 @CPAN::Complete::ISA = qw(CPAN::Debug);
259 @CPAN::Complete::COMMANDS = sort qw(
260 ! a b d h i m o q r u
279 use vars qw($LAST_TIME $DATE_OF_02 $DATE_OF_03);
280 @CPAN::Index::ISA = qw(CPAN::Debug);
283 # use constant PROTOCOL => "2.0"; # outcommented to avoid warning on upgrade from 1.57
286 package CPAN::InfoObj;
288 @CPAN::InfoObj::ISA = qw(CPAN::Debug);
290 package CPAN::Author;
292 @CPAN::Author::ISA = qw(CPAN::InfoObj);
294 package CPAN::Distribution;
296 @CPAN::Distribution::ISA = qw(CPAN::InfoObj);
298 package CPAN::Bundle;
300 @CPAN::Bundle::ISA = qw(CPAN::Module);
302 package CPAN::Module;
304 @CPAN::Module::ISA = qw(CPAN::InfoObj);
306 package CPAN::Exception::RecursiveDependency;
308 use overload '""' => "as_string";
315 for my $dep (@$deps) {
317 last if $seen{$dep}++;
319 bless { deps => \@deps }, $class;
324 "\nRecursive dependency detected:\n " .
325 join("\n => ", @{$self->{deps}}) .
326 ".\nCannot continue.\n";
329 package CPAN::Prompt; use overload '""' => "as_string";
330 our $prompt = "cpan> ";
331 $CPAN::CurrentCommandId ||= 0;
332 sub as_randomly_capitalized_string {
334 substr($prompt,$_,1)=rand()<0.5 ?
335 uc(substr($prompt,$_,1)) :
336 lc(substr($prompt,$_,1)) for 0..3;
343 if ($CPAN::Config->{commandnumber_in_prompt}) {
344 sprintf "cpan[%d]> ", $CPAN::CurrentCommandId;
350 package CPAN::Distrostatus;
351 use overload '""' => "as_string",
354 my($class,$arg) = @_;
357 FAILED => substr($arg,0,2) eq "NO",
358 COMMANDID => $CPAN::CurrentCommandId,
361 sub commandid { shift->{COMMANDID} }
362 sub failed { shift->{FAILED} }
366 $self->{TEXT} = $set;
372 if (0) { # called from rematein during install?
381 use vars qw($AUTOLOAD @ISA $COLOR_REGISTERED $ADVANCED_QUERY $PRINT_ORNAMENTING);
382 @CPAN::Shell::ISA = qw(CPAN::Debug);
383 $COLOR_REGISTERED ||= 0;
384 $PRINT_ORNAMENTING ||= 0;
386 #-> sub CPAN::Shell::AUTOLOAD ;
388 my($autoload) = $AUTOLOAD;
389 my $class = shift(@_);
390 # warn "autoload[$autoload] class[$class]";
391 $autoload =~ s/.*:://;
392 if ($autoload =~ /^w/) {
393 if ($CPAN::META->has_inst('CPAN::WAIT')) {
394 CPAN::WAIT->$autoload(@_);
396 $CPAN::Frontend->mywarn(qq{
397 Commands starting with "w" require CPAN::WAIT to be installed.
398 Please consider installing CPAN::WAIT to use the fulltext index.
399 For this you just need to type
404 $CPAN::Frontend->mywarn(qq{Unknown shell command '$autoload'. }.
413 # One use of the queue is to determine if we should or shouldn't
414 # announce the availability of a new CPAN module
416 # Now we try to use it for dependency tracking. For that to happen
417 # we need to draw a dependency tree and do the leaves first. This can
418 # easily be reached by running CPAN.pm recursively, but we don't want
419 # to waste memory and run into deep recursion. So what we can do is
422 # CPAN::Queue is the package where the queue is maintained. Dependencies
423 # often have high priority and must be brought to the head of the queue,
424 # possibly by jumping the queue if they are already there. My first code
425 # attempt tried to be extremely correct. Whenever a module needed
426 # immediate treatment, I either unshifted it to the front of the queue,
427 # or, if it was already in the queue, I spliced and let it bypass the
428 # others. This became a too correct model that made it impossible to put
429 # an item more than once into the queue. Why would you need that? Well,
430 # you need temporary duplicates as the manager of the queue is a loop
433 # (1) looks at the first item in the queue without shifting it off
435 # (2) cares for the item
437 # (3) removes the item from the queue, *even if its agenda failed and
438 # even if the item isn't the first in the queue anymore* (that way
439 # protecting against never ending queues)
441 # So if an item has prerequisites, the installation fails now, but we
442 # want to retry later. That's easy if we have it twice in the queue.
444 # I also expect insane dependency situations where an item gets more
445 # than two lives in the queue. Simplest example is triggered by 'install
446 # Foo Foo Foo'. People make this kind of mistakes and I don't want to
447 # get in the way. I wanted the queue manager to be a dumb servant, not
448 # one that knows everything.
450 # Who would I tell in this model that the user wants to be asked before
451 # processing? I can't attach that information to the module object,
452 # because not modules are installed but distributions. So I'd have to
453 # tell the distribution object that it should ask the user before
454 # processing. Where would the question be triggered then? Most probably
455 # in CPAN::Distribution::rematein.
456 # Hope that makes sense, my head is a bit off:-) -- AK
463 my $self = bless { qmod => $s }, $class;
468 # CPAN::Queue::first ;
474 # CPAN::Queue::delete_first ;
476 my($class,$what) = @_;
478 for my $i (0..$#All) {
479 if ( $All[$i]->{qmod} eq $what ) {
486 # CPAN::Queue::jumpqueue ;
490 CPAN->debug(sprintf("before jumpqueue All[%s] what[%s]",
491 join(",",map {$_->{qmod}} @All),
494 WHAT: for my $what (reverse @what) {
496 for (my $i=0; $i<$#All;$i++) { #prevent deep recursion
497 CPAN->debug("i[$All[$i]]what[$what]") if $CPAN::DEBUG;
498 if ($All[$i]->{qmod} eq $what){
500 if ($jumped > 100) { # one's OK if e.g. just
501 # processing now; more are OK if
502 # user typed it several times
503 $CPAN::Frontend->mywarn(
504 qq{Object [$what] queued more than 100 times, ignoring}
510 my $obj = bless { qmod => $what }, $class;
513 CPAN->debug(sprintf("after jumpqueue All[%s] what[%s]",
514 join(",",map {$_->{qmod}} @All),
519 # CPAN::Queue::exists ;
521 my($self,$what) = @_;
522 my @all = map { $_->{qmod} } @All;
523 my $exists = grep { $_->{qmod} eq $what } @All;
524 # warn "in exists what[$what] all[@all] exists[$exists]";
528 # CPAN::Queue::delete ;
531 @All = grep { $_->{qmod} ne $mod } @All;
534 # CPAN::Queue::nullify_queue ;
544 $META ||= CPAN->new; # In case we re-eval ourselves we need the ||
546 # from here on only subs.
547 ################################################################################
549 #-> sub CPAN::all_objects ;
551 my($mgr,$class) = @_;
552 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
553 CPAN->debug("mgr[$mgr] class[$class]") if $CPAN::DEBUG;
555 values %{ $META->{readwrite}{$class} }; # unsafe meta access, ok
557 *all = \&all_objects;
559 # Called by shell, not in batch mode. In batch mode I see no risk in
560 # having many processes updating something as installations are
561 # continually checked at runtime. In shell mode I suspect it is
562 # unintentional to open more than one shell at a time
564 #-> sub CPAN::checklock ;
567 my $lockfile = File::Spec->catfile($CPAN::Config->{cpan_home},".lock");
568 if (-f $lockfile && -M _ > 0) {
569 my $fh = FileHandle->new($lockfile) or
570 $CPAN::Frontend->mydie("Could not open lockfile '$lockfile': $!");
571 my $otherpid = <$fh>;
572 my $otherhost = <$fh>;
574 if (defined $otherpid && $otherpid) {
577 if (defined $otherhost && $otherhost) {
580 my $thishost = hostname();
581 if (defined $otherhost && defined $thishost &&
582 $otherhost ne '' && $thishost ne '' &&
583 $otherhost ne $thishost) {
584 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile '$lockfile'\n".
585 "reports other host $otherhost and other process $otherpid.\n".
586 "Cannot proceed.\n"));
588 elsif (defined $otherpid && $otherpid) {
589 return if $$ == $otherpid; # should never happen
590 $CPAN::Frontend->mywarn(
592 There seems to be running another CPAN process (pid $otherpid). Contacting...
594 if (kill 0, $otherpid) {
595 $CPAN::Frontend->mydie(qq{Other job is running.
596 You may want to kill it and delete the lockfile, maybe. On UNIX try:
600 } elsif (-w $lockfile) {
602 ExtUtils::MakeMaker::prompt
603 (qq{Other job not responding. Shall I overwrite }.
604 qq{the lockfile '$lockfile'? (Y/n)},"y");
605 $CPAN::Frontend->myexit("Ok, bye\n")
606 unless $ans =~ /^y/i;
609 qq{Lockfile '$lockfile' not writeable by you. }.
610 qq{Cannot proceed.\n}.
612 qq{ rm '$lockfile'\n}.
613 qq{ and then rerun us.\n}
617 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile '$lockfile'\n".
618 "reports other process with ID ".
619 "$otherpid. Cannot proceed.\n"));
622 my $dotcpan = $CPAN::Config->{cpan_home};
623 eval { File::Path::mkpath($dotcpan);};
625 # A special case at least for Jarkko.
630 $symlinkcpan = readlink $dotcpan;
631 die "readlink $dotcpan failed: $!" unless defined $symlinkcpan;
632 eval { File::Path::mkpath($symlinkcpan); };
636 $CPAN::Frontend->mywarn(qq{
637 Working directory $symlinkcpan created.
641 unless (-d $dotcpan) {
643 Your configuration suggests "$dotcpan" as your
644 CPAN.pm working directory. I could not create this directory due
645 to this error: $firsterror\n};
647 As "$dotcpan" is a symlink to "$symlinkcpan",
648 I tried to create that, but I failed with this error: $seconderror
651 Please make sure the directory exists and is writable.
653 $CPAN::Frontend->mydie($diemess);
657 unless ($fh = FileHandle->new(">$lockfile")) {
658 if ($! =~ /Permission/) {
659 my $incc = $INC{'CPAN/Config.pm'};
660 my $myincc = File::Spec->catfile($ENV{HOME},'.cpan','CPAN','MyConfig.pm');
661 $CPAN::Frontend->myprint(qq{
663 Your configuration suggests that CPAN.pm should use a working
665 $CPAN::Config->{cpan_home}
666 Unfortunately we could not create the lock file
668 due to permission problems.
670 Please make sure that the configuration variable
671 \$CPAN::Config->{cpan_home}
672 points to a directory where you can write a .lock file. You can set
673 this variable in either
680 $CPAN::Frontend->mydie("Could not open >$lockfile: $!");
682 $fh->print($$, "\n");
683 $fh->print(hostname(), "\n");
684 $self->{LOCK} = $lockfile;
688 $CPAN::Frontend->mydie("Got SIGTERM, leaving");
693 $CPAN::Frontend->mydie("Got another SIGINT") if $Signal;
694 print "Caught SIGINT\n";
698 # From: Larry Wall <larry@wall.org>
699 # Subject: Re: deprecating SIGDIE
700 # To: perl5-porters@perl.org
701 # Date: Thu, 30 Sep 1999 14:58:40 -0700 (PDT)
703 # The original intent of __DIE__ was only to allow you to substitute one
704 # kind of death for another on an application-wide basis without respect
705 # to whether you were in an eval or not. As a global backstop, it should
706 # not be used any more lightly (or any more heavily :-) than class
707 # UNIVERSAL. Any attempt to build a general exception model on it should
708 # be politely squashed. Any bug that causes every eval {} to have to be
709 # modified should be not so politely squashed.
711 # Those are my current opinions. It is also my optinion that polite
712 # arguments degenerate to personal arguments far too frequently, and that
713 # when they do, it's because both people wanted it to, or at least didn't
714 # sufficiently want it not to.
718 # global backstop to cleanup if we should really die
719 $SIG{__DIE__} = \&cleanup;
720 $self->debug("Signal handler set.") if $CPAN::DEBUG;
723 #-> sub CPAN::DESTROY ;
725 &cleanup; # need an eval?
728 #-> sub CPAN::anycwd ;
731 $getcwd = $CPAN::Config->{'getcwd'} || 'cwd';
736 sub cwd {Cwd::cwd();}
738 #-> sub CPAN::getcwd ;
739 sub getcwd {Cwd::getcwd();}
741 #-> sub CPAN::find_perl ;
743 my($perl) = File::Spec->file_name_is_absolute($^X) ? $^X : "";
744 my $pwd = $CPAN::iCwd = CPAN::anycwd();
745 my $candidate = File::Spec->catfile($pwd,$^X);
746 $perl ||= $candidate if MM->maybe_command($candidate);
749 my ($component,$perl_name);
750 DIST_PERLNAME: foreach $perl_name ($^X, 'perl', 'perl5', "perl$]") {
751 PATH_COMPONENT: foreach $component (File::Spec->path(),
752 $Config::Config{'binexp'}) {
753 next unless defined($component) && $component;
754 my($abs) = File::Spec->catfile($component,$perl_name);
755 if (MM->maybe_command($abs)) {
767 #-> sub CPAN::exists ;
769 my($mgr,$class,$id) = @_;
770 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
772 ### Carp::croak "exists called without class argument" unless $class;
774 $id =~ s/:+/::/g if $class eq "CPAN::Module";
775 exists $META->{readonly}{$class}{$id} or
776 exists $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
779 #-> sub CPAN::delete ;
781 my($mgr,$class,$id) = @_;
782 delete $META->{readonly}{$class}{$id}; # unsafe meta access, ok
783 delete $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
786 #-> sub CPAN::has_usable
787 # has_inst is sometimes too optimistic, we should replace it with this
788 # has_usable whenever a case is given
790 my($self,$mod,$message) = @_;
791 return 1 if $HAS_USABLE->{$mod};
792 my $has_inst = $self->has_inst($mod,$message);
793 return unless $has_inst;
796 LWP => [ # we frequently had "Can't locate object
797 # method "new" via package "LWP::UserAgent" at
798 # (eval 69) line 2006
800 sub {require LWP::UserAgent},
801 sub {require HTTP::Request},
802 sub {require URI::URL},
805 sub {require Net::FTP},
806 sub {require Net::Config},
809 if ($usable->{$mod}) {
810 for my $c (0..$#{$usable->{$mod}}) {
811 my $code = $usable->{$mod}[$c];
812 my $ret = eval { &$code() };
814 warn "DEBUG: c[$c]\$\@[$@]ret[$ret]";
819 return $HAS_USABLE->{$mod} = 1;
822 #-> sub CPAN::has_inst
824 my($self,$mod,$message) = @_;
825 Carp::croak("CPAN->has_inst() called without an argument")
827 if (defined $message && $message eq "no"
829 exists $CPAN::META->{dontload_hash}{$mod} # unsafe meta access, ok
831 exists $CPAN::Config->{dontload_hash}{$mod}
833 $CPAN::META->{dontload_hash}{$mod}||=1; # unsafe meta access, ok
841 # checking %INC is wrong, because $INC{LWP} may be true
842 # although $INC{"URI/URL.pm"} may have failed. But as
843 # I really want to say "bla loaded OK", I have to somehow
845 ### warn "$file in %INC"; #debug
847 } elsif (eval { require $file }) {
848 # eval is good: if we haven't yet read the database it's
849 # perfect and if we have installed the module in the meantime,
850 # it tries again. The second require is only a NOOP returning
851 # 1 if we had success, otherwise it's retrying
853 $CPAN::Frontend->myprint("CPAN: $mod loaded ok\n");
854 if ($mod eq "CPAN::WAIT") {
855 push @CPAN::Shell::ISA, 'CPAN::WAIT';
858 } elsif ($mod eq "Net::FTP") {
859 $CPAN::Frontend->mywarn(qq{
860 Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
862 install Bundle::libnet
864 }) unless $Have_warned->{"Net::FTP"}++;
866 } elsif ($mod eq "Digest::SHA"){
867 $CPAN::Frontend->myprint(qq{
868 CPAN: checksum security checks disabled because Digest::SHA not installed.
869 Please consider installing the Digest::SHA module.
873 } elsif ($mod eq "Module::Signature"){
874 unless ($Have_warned->{"Module::Signature"}++) {
875 # No point in complaining unless the user can
876 # reasonably install and use it.
877 if (eval { require Crypt::OpenPGP; 1 } ||
878 defined $CPAN::Config->{'gpg'}) {
879 $CPAN::Frontend->myprint(qq{
880 CPAN: Module::Signature security checks disabled because Module::Signature
881 not installed. Please consider installing the Module::Signature module.
882 You may also need to be able to connect over the Internet to the public
883 keyservers like pgp.mit.edu (port 11371).
890 delete $INC{$file}; # if it inc'd LWP but failed during, say, URI
895 #-> sub CPAN::instance ;
897 my($mgr,$class,$id) = @_;
900 # unsafe meta access, ok?
901 return $META->{readwrite}{$class}{$id} if exists $META->{readwrite}{$class}{$id};
902 $META->{readwrite}{$class}{$id} ||= $class->new(ID => $id);
910 #-> sub CPAN::cleanup ;
912 # warn "cleanup called with arg[@_] End[$CPAN::End] Signal[$Signal]";
913 local $SIG{__DIE__} = '';
918 while ((undef,undef,undef,$subroutine) = caller(++$i)) {
920 $subroutine eq '(eval)';
922 return if $ineval && !$CPAN::End;
923 return unless defined $META->{LOCK};
924 return unless -f $META->{LOCK};
926 unlink $META->{LOCK};
928 # Carp::cluck("DEBUGGING");
929 $CPAN::Frontend->mywarn("Lockfile removed.\n");
932 #-> sub CPAN::savehist
935 my($histfile,$histsize);
936 unless ($histfile = $CPAN::Config->{'histfile'}){
937 $CPAN::Frontend->mywarn("No history written (no histfile specified).\n");
940 $histsize = $CPAN::Config->{'histsize'} || 100;
942 unless ($CPAN::term->can("GetHistory")) {
943 $CPAN::Frontend->mywarn("Terminal does not support GetHistory.\n");
949 my @h = $CPAN::term->GetHistory;
950 splice @h, 0, @h-$histsize if @h>$histsize;
951 my($fh) = FileHandle->new;
952 open $fh, ">$histfile" or $CPAN::Frontend->mydie("Couldn't open >$histfile: $!");
953 local $\ = local $, = "\n";
959 my($self,$what) = @_;
960 $self->{is_tested}{$what} = 1;
964 my($self,$what) = @_;
965 delete $self->{is_tested}{$what};
970 $self->{is_tested} ||= {};
971 return unless %{$self->{is_tested}};
972 my $env = $ENV{PERL5LIB};
973 $env = $ENV{PERLLIB} unless defined $env;
975 push @env, $env if defined $env and length $env;
976 my @dirs = map {("$_/blib/arch", "$_/blib/lib")} keys %{$self->{is_tested}};
977 $CPAN::Frontend->myprint("Prepending @dirs to PERL5LIB.\n");
978 $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
981 package CPAN::CacheMgr;
984 #-> sub CPAN::CacheMgr::as_string ;
986 eval { require Data::Dumper };
988 return shift->SUPER::as_string;
990 return Data::Dumper::Dumper(shift);
994 #-> sub CPAN::CacheMgr::cachesize ;
999 #-> sub CPAN::CacheMgr::tidyup ;
1002 return unless -d $self->{ID};
1003 while ($self->{DU} > $self->{'MAX'} ) {
1004 my($toremove) = shift @{$self->{FIFO}};
1005 $CPAN::Frontend->myprint(sprintf(
1006 "Deleting from cache".
1007 ": $toremove (%.1f>%.1f MB)\n",
1008 $self->{DU}, $self->{'MAX'})
1010 return if $CPAN::Signal;
1011 $self->force_clean_cache($toremove);
1012 return if $CPAN::Signal;
1016 #-> sub CPAN::CacheMgr::dir ;
1021 #-> sub CPAN::CacheMgr::entries ;
1023 my($self,$dir) = @_;
1024 return unless defined $dir;
1025 $self->debug("reading dir[$dir]") if $CPAN::DEBUG;
1026 $dir ||= $self->{ID};
1027 my($cwd) = CPAN::anycwd();
1028 chdir $dir or Carp::croak("Can't chdir to $dir: $!");
1029 my $dh = DirHandle->new(File::Spec->curdir)
1030 or Carp::croak("Couldn't opendir $dir: $!");
1033 next if $_ eq "." || $_ eq "..";
1035 push @entries, File::Spec->catfile($dir,$_);
1037 push @entries, File::Spec->catdir($dir,$_);
1039 $CPAN::Frontend->mywarn("Warning: weird direntry in $dir: $_\n");
1042 chdir $cwd or Carp::croak("Can't chdir to $cwd: $!");
1043 sort { -M $b <=> -M $a} @entries;
1046 #-> sub CPAN::CacheMgr::disk_usage ;
1048 my($self,$dir) = @_;
1049 return if exists $self->{SIZE}{$dir};
1050 return if $CPAN::Signal;
1053 unless (chmod 0755, $dir) {
1054 $CPAN::Frontend->mywarn("I have neither the -x permission nor the permission ".
1055 "to change the permission; cannot estimate disk usage ".
1063 $File::Find::prune++ if $CPAN::Signal;
1065 if ($^O eq 'MacOS') {
1067 my $cat = Mac::Files::FSpGetCatInfo($_);
1068 $Du += $cat->ioFlLgLen() + $cat->ioFlRLgLen() if $cat;
1072 unless (chmod 0755, $_) {
1073 $CPAN::Frontend->mywarn("I have neither the -x permission nor ".
1074 "the permission to change the permission; ".
1075 "can only partially estimate disk usage ".
1088 return if $CPAN::Signal;
1089 $self->{SIZE}{$dir} = $Du/1024/1024;
1090 push @{$self->{FIFO}}, $dir;
1091 $self->debug("measured $dir is $Du") if $CPAN::DEBUG;
1092 $self->{DU} += $Du/1024/1024;
1096 #-> sub CPAN::CacheMgr::force_clean_cache ;
1097 sub force_clean_cache {
1098 my($self,$dir) = @_;
1099 return unless -e $dir;
1100 $self->debug("have to rmtree $dir, will free $self->{SIZE}{$dir}")
1102 File::Path::rmtree($dir);
1103 $self->{DU} -= $self->{SIZE}{$dir};
1104 delete $self->{SIZE}{$dir};
1107 #-> sub CPAN::CacheMgr::new ;
1114 ID => $CPAN::Config->{'build_dir'},
1115 MAX => $CPAN::Config->{'build_cache'},
1116 SCAN => $CPAN::Config->{'scan_cache'} || 'atstart',
1119 File::Path::mkpath($self->{ID});
1120 my $dh = DirHandle->new($self->{ID});
1121 bless $self, $class;
1124 $debug .= "timing of CacheMgr->new: ".($t2 - $time);
1126 CPAN->debug($debug) if $CPAN::DEBUG;
1130 #-> sub CPAN::CacheMgr::scan_cache ;
1133 return if $self->{SCAN} eq 'never';
1134 $CPAN::Frontend->mydie("Unknown scan_cache argument: $self->{SCAN}")
1135 unless $self->{SCAN} eq 'atstart';
1136 $CPAN::Frontend->myprint(
1137 sprintf("Scanning cache %s for sizes\n",
1140 for $e ($self->entries($self->{ID})) {
1141 next if $e eq ".." || $e eq ".";
1142 $self->disk_usage($e);
1143 return if $CPAN::Signal;
1148 package CPAN::Shell;
1151 #-> sub CPAN::Shell::h ;
1153 my($class,$about) = @_;
1154 if (defined $about) {
1155 $CPAN::Frontend->myprint("Detailed help not yet implemented\n");
1157 my $filler = " " x (80 - 28 - length($CPAN::VERSION));
1158 $CPAN::Frontend->myprint(qq{
1159 Display Information $filler (ver $CPAN::VERSION)
1160 command argument description
1161 a,b,d,m WORD or /REGEXP/ about authors, bundles, distributions, modules
1162 i WORD or /REGEXP/ about any of the above
1163 r NONE report updatable modules
1164 ls AUTHOR or GLOB about files in the author's directory
1165 (with WORD being a module, bundle or author name or a distribution
1166 name of the form AUTHOR/DISTRIBUTION)
1168 Download, Test, Make, Install...
1169 get download clean make clean
1170 make make (implies get) look open subshell in dist directory
1171 test make test (implies make) readme display these README files
1172 install make install (implies test) perldoc display POD documentation
1175 force COMMAND unconditionally do command
1176 notest COMMAND skip testing
1179 h,? display this menu ! perl-code eval a perl command
1180 o conf [opt] set and query options q quit the cpan shell
1181 reload cpan load CPAN.pm again reload index load newer indices
1182 autobundle Snapshot recent latest CPAN uploads});
1188 #-> sub CPAN::Shell::a ;
1190 my($self,@arg) = @_;
1191 # authors are always UPPERCASE
1193 $_ = uc $_ unless /=/;
1195 $CPAN::Frontend->myprint($self->format_result('Author',@arg));
1199 my($self,$pragmas,$s) = @_;
1200 # ls is really very different, but we had it once as an ordinary
1201 # command in the Shell (upto rev. 321) and we could not handle
1203 my(@accept,@preexpand);
1204 if ($s =~ /[\*\?\/]/) {
1205 if ($CPAN::META->has_inst("Text::Glob")) {
1206 if (my($au,$pathglob) = $s =~ m|(.*?)/(.*)|) {
1207 my $rau = Text::Glob::glob_to_regex(uc $au);
1208 CPAN::Shell->debug("au[$au]pathglob[$pathglob]rau[$rau]")
1210 push @preexpand, map { $_->id . "/" . $pathglob }
1211 CPAN::Shell->expand_by_method('CPAN::Author',['id'],"/$rau/");
1213 my $rau = Text::Glob::glob_to_regex(uc $s);
1214 push @preexpand, map { $_->id }
1215 CPAN::Shell->expand_by_method('CPAN::Author',
1220 $CPAN::Frontend->mydie("Text::Glob not installed, cannot proceed");
1223 push @preexpand, uc $s;
1226 unless (/^[A-Z0-9\-]+(\/|$)/i) {
1227 $CPAN::Frontend->mywarn("ls command rejects argument $_: not an author\n");
1232 my $silent = @accept>1;
1233 my $last_alpha = "";
1234 for my $a (@accept){
1235 my($author,$pathglob);
1236 if ($a =~ m|(.*?)/(.*)|) {
1239 $author = CPAN::Shell->expand_by_method('CPAN::Author',
1241 $a2) or die "No author found for $a2";
1243 $author = CPAN::Shell->expand_by_method('CPAN::Author',
1245 $a) or die "No author found for $a";
1248 my $alpha = substr $author->id, 0, 1;
1250 if ($alpha eq $last_alpha) {
1254 $last_alpha = $alpha;
1256 $CPAN::Frontend->myprint($ad);
1258 for my $pragma (@$pragmas) {
1259 if ($author->can($pragma)) {
1263 $author->ls($pathglob,$silent); # silent if more than one author
1264 for my $pragma (@$pragmas) {
1265 my $meth = "un$pragma";
1266 if ($author->can($meth)) {
1273 #-> sub CPAN::Shell::local_bundles ;
1275 my($self,@which) = @_;
1276 my($incdir,$bdir,$dh);
1277 foreach $incdir ($CPAN::Config->{'cpan_home'},@INC) {
1278 my @bbase = "Bundle";
1279 while (my $bbase = shift @bbase) {
1280 $bdir = File::Spec->catdir($incdir,split /::/, $bbase);
1281 CPAN->debug("bdir[$bdir]\@bbase[@bbase]") if $CPAN::DEBUG;
1282 if ($dh = DirHandle->new($bdir)) { # may fail
1284 for $entry ($dh->read) {
1285 next if $entry =~ /^\./;
1286 if (-d File::Spec->catdir($bdir,$entry)){
1287 push @bbase, "$bbase\::$entry";
1289 next unless $entry =~ s/\.pm(?!\n)\Z//;
1290 $CPAN::META->instance('CPAN::Bundle',"$bbase\::$entry");
1298 #-> sub CPAN::Shell::b ;
1300 my($self,@which) = @_;
1301 CPAN->debug("which[@which]") if $CPAN::DEBUG;
1302 $self->local_bundles;
1303 $CPAN::Frontend->myprint($self->format_result('Bundle',@which));
1306 #-> sub CPAN::Shell::d ;
1307 sub d { $CPAN::Frontend->myprint(shift->format_result('Distribution',@_));}
1309 #-> sub CPAN::Shell::m ;
1310 sub m { # emacs confused here }; sub mimimimimi { # emacs in sync here
1312 $CPAN::Frontend->myprint($self->format_result('Module',@_));
1315 #-> sub CPAN::Shell::i ;
1319 @args = '/./' unless @args;
1321 for my $type (qw/Bundle Distribution Module/) {
1322 push @result, $self->expand($type,@args);
1324 # Authors are always uppercase.
1325 push @result, $self->expand("Author", map { uc $_ } @args);
1327 my $result = @result == 1 ?
1328 $result[0]->as_string :
1330 "No objects found of any type for argument @args\n" :
1332 (map {$_->as_glimpse} @result),
1333 scalar @result, " items found\n",
1335 $CPAN::Frontend->myprint($result);
1338 #-> sub CPAN::Shell::o ;
1340 # CPAN::Shell::o and CPAN::Config::edit are closely related. 'o conf'
1341 # should have been called set and 'o debug' maybe 'set debug'
1343 my($self,$o_type,@o_what) = @_;
1346 CPAN->debug("o_type[$o_type] o_what[".join(" | ",@o_what)."]\n");
1347 if ($o_type eq 'conf') {
1348 shift @o_what if @o_what && $o_what[0] eq 'help';
1349 if (!@o_what) { # print all things, "o conf"
1351 $CPAN::Frontend->myprint("CPAN::Config options");
1352 if (exists $INC{'CPAN/Config.pm'}) {
1353 $CPAN::Frontend->myprint(" from $INC{'CPAN/Config.pm'}");
1355 if (exists $INC{'CPAN/MyConfig.pm'}) {
1356 $CPAN::Frontend->myprint(" and $INC{'CPAN/MyConfig.pm'}");
1358 $CPAN::Frontend->myprint(":\n");
1359 for $k (sort keys %CPAN::HandleConfig::can) {
1360 $v = $CPAN::HandleConfig::can{$k};
1361 $CPAN::Frontend->myprint(sprintf " %-18s [%s]\n", $k, $v);
1363 $CPAN::Frontend->myprint("\n");
1364 for $k (sort keys %$CPAN::Config) {
1365 CPAN::HandleConfig->prettyprint($k);
1367 $CPAN::Frontend->myprint("\n");
1368 } elsif (!CPAN::HandleConfig->edit(@o_what)) {
1369 $CPAN::Frontend->myprint(qq{Type 'o conf' to view all configuration }.
1372 } elsif ($o_type eq 'debug') {
1374 @o_what = () if defined $o_what[0] && $o_what[0] =~ /help/i;
1377 my($what) = shift @o_what;
1378 if ($what =~ s/^-// && exists $CPAN::DEBUG{$what}) {
1379 $CPAN::DEBUG &= $CPAN::DEBUG ^ $CPAN::DEBUG{$what};
1382 if ( exists $CPAN::DEBUG{$what} ) {
1383 $CPAN::DEBUG |= $CPAN::DEBUG{$what};
1384 } elsif ($what =~ /^\d/) {
1385 $CPAN::DEBUG = $what;
1386 } elsif (lc $what eq 'all') {
1388 for (values %CPAN::DEBUG) {
1391 $CPAN::DEBUG = $max;
1394 for (keys %CPAN::DEBUG) {
1395 next unless lc($_) eq lc($what);
1396 $CPAN::DEBUG |= $CPAN::DEBUG{$_};
1399 $CPAN::Frontend->myprint("unknown argument [$what]\n")
1404 my $raw = "Valid options for debug are ".
1405 join(", ",sort(keys %CPAN::DEBUG), 'all').
1406 qq{ or a number. Completion works on the options. }.
1407 qq{Case is ignored.};
1409 $CPAN::Frontend->myprint(Text::Wrap::fill("","",$raw));
1410 $CPAN::Frontend->myprint("\n\n");
1413 $CPAN::Frontend->myprint("Options set for debugging:\n");
1415 for $k (sort {$CPAN::DEBUG{$a} <=> $CPAN::DEBUG{$b}} keys %CPAN::DEBUG) {
1416 $v = $CPAN::DEBUG{$k};
1417 $CPAN::Frontend->myprint(sprintf " %-14s(%s)\n", $k, $v)
1418 if $v & $CPAN::DEBUG;
1421 $CPAN::Frontend->myprint("Debugging turned off completely.\n");
1424 $CPAN::Frontend->myprint(qq{
1426 conf set or get configuration variables
1427 debug set or get debugging options
1432 sub paintdots_onreload {
1435 if ( $_[0] =~ /[Ss]ubroutine ([\w:]+) redefined/ ) {
1439 # $CPAN::Frontend->myprint(".($subr)");
1440 $CPAN::Frontend->myprint(".");
1447 #-> sub CPAN::Shell::reload ;
1449 my($self,$command,@arg) = @_;
1451 $self->debug("self[$self]command[$command]arg[@arg]") if $CPAN::DEBUG;
1452 if ($command =~ /cpan/i) {
1454 chdir $CPAN::iCwd if $CPAN::iCwd; # may fail
1456 MFILE: for my $f (qw(CPAN.pm CPAN/HandleConfig.pm CPAN/FirstTime.pm CPAN/Tarzip.pm
1457 CPAN/Debug.pm CPAN/Version.pm)) {
1458 next unless $INC{$f};
1459 my $pwd = CPAN::anycwd();
1460 CPAN->debug("reloading the whole '$f' from '$INC{$f}' while pwd='$pwd'")
1463 for my $inc (@INC) {
1464 $read = File::Spec->catfile($inc,split /\//, $f);
1469 $CPAN::Frontend->mywarn("Found no file to reload for '$f'\n");
1472 my $fh = FileHandle->new($read) or
1473 $CPAN::Frontend->mydie("Could not open $read: $!");
1476 local($SIG{__WARN__}) = paintdots_onreload(\$redef);
1478 CPAN->debug(sprintf("evaling [%s...]\n",substr($eval,0,64)))
1486 $CPAN::Frontend->myprint("\n$redef subroutines redefined\n");
1487 $failed++ unless $redef;
1489 $CPAN::Frontend->mywarn("\n$failed errors during reload. You better quit ".
1492 } elsif ($command =~ /index/) {
1493 CPAN::Index->force_reload;
1495 $CPAN::Frontend->myprint(qq{cpan re-evals the CPAN.pm file
1496 index re-reads the index files\n});
1500 #-> sub CPAN::Shell::_binary_extensions ;
1501 sub _binary_extensions {
1502 my($self) = shift @_;
1503 my(@result,$module,%seen,%need,$headerdone);
1504 for $module ($self->expand('Module','/./')) {
1505 my $file = $module->cpan_file;
1506 next if $file eq "N/A";
1507 next if $file =~ /^Contact Author/;
1508 my $dist = $CPAN::META->instance('CPAN::Distribution',$file);
1509 next if $dist->isa_perl;
1510 next unless $module->xs_file;
1512 $CPAN::Frontend->myprint(".");
1513 push @result, $module;
1515 # print join " | ", @result;
1516 $CPAN::Frontend->myprint("\n");
1520 #-> sub CPAN::Shell::recompile ;
1522 my($self) = shift @_;
1523 my($module,@module,$cpan_file,%dist);
1524 @module = $self->_binary_extensions();
1525 for $module (@module){ # we force now and compile later, so we
1527 $cpan_file = $module->cpan_file;
1528 my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
1530 $dist{$cpan_file}++;
1532 for $cpan_file (sort keys %dist) {
1533 $CPAN::Frontend->myprint(" CPAN: Recompiling $cpan_file\n\n");
1534 my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
1536 $CPAN::Signal = 0; # it's tempting to reset Signal, so we can
1537 # stop a package from recompiling,
1538 # e.g. IO-1.12 when we have perl5.003_10
1542 #-> sub CPAN::Shell::_u_r_common ;
1544 my($self) = shift @_;
1545 my($what) = shift @_;
1546 CPAN->debug("self[$self] what[$what] args[@_]") if $CPAN::DEBUG;
1547 Carp::croak "Usage: \$obj->_u_r_common(a|r|u)" unless
1548 $what && $what =~ /^[aru]$/;
1550 @args = '/./' unless @args;
1551 my(@result,$module,%seen,%need,$headerdone,
1552 $version_undefs,$version_zeroes);
1553 $version_undefs = $version_zeroes = 0;
1554 my $sprintf = "%s%-25s%s %9s %9s %s\n";
1555 my @expand = $self->expand('Module',@args);
1556 my $expand = scalar @expand;
1557 if (0) { # Looks like noise to me, was very useful for debugging
1558 # for metadata cache
1559 $CPAN::Frontend->myprint(sprintf "%d matches in the database\n", $expand);
1561 MODULE: for $module (@expand) {
1562 my $file = $module->cpan_file;
1563 next MODULE unless defined $file; # ??
1564 $file =~ s|^./../||;
1565 my($latest) = $module->cpan_version;
1566 my($inst_file) = $module->inst_file;
1568 return if $CPAN::Signal;
1571 $have = $module->inst_version;
1572 } elsif ($what eq "r") {
1573 $have = $module->inst_version;
1575 if ($have eq "undef"){
1577 } elsif ($have == 0){
1580 next MODULE unless CPAN::Version->vgt($latest, $have);
1581 # to be pedantic we should probably say:
1582 # && !($have eq "undef" && $latest ne "undef" && $latest gt "");
1583 # to catch the case where CPAN has a version 0 and we have a version undef
1584 } elsif ($what eq "u") {
1590 } elsif ($what eq "r") {
1592 } elsif ($what eq "u") {
1596 return if $CPAN::Signal; # this is sometimes lengthy
1599 push @result, sprintf "%s %s\n", $module->id, $have;
1600 } elsif ($what eq "r") {
1601 push @result, $module->id;
1602 next MODULE if $seen{$file}++;
1603 } elsif ($what eq "u") {
1604 push @result, $module->id;
1605 next MODULE if $seen{$file}++;
1606 next MODULE if $file =~ /^Contact/;
1608 unless ($headerdone++){
1609 $CPAN::Frontend->myprint("\n");
1610 $CPAN::Frontend->myprint(sprintf(
1613 "Package namespace",
1625 $CPAN::META->has_inst("Term::ANSIColor")
1627 $module->description
1629 $color_on = Term::ANSIColor::color("green");
1630 $color_off = Term::ANSIColor::color("reset");
1632 $CPAN::Frontend->myprint(sprintf $sprintf,
1639 $need{$module->id}++;
1643 $CPAN::Frontend->myprint("No modules found for @args\n");
1644 } elsif ($what eq "r") {
1645 $CPAN::Frontend->myprint("All modules are up to date for @args\n");
1649 if ($version_zeroes) {
1650 my $s_has = $version_zeroes > 1 ? "s have" : " has";
1651 $CPAN::Frontend->myprint(qq{$version_zeroes installed module$s_has }.
1652 qq{a version number of 0\n});
1654 if ($version_undefs) {
1655 my $s_has = $version_undefs > 1 ? "s have" : " has";
1656 $CPAN::Frontend->myprint(qq{$version_undefs installed module$s_has no }.
1657 qq{parseable version number\n});
1663 #-> sub CPAN::Shell::r ;
1665 shift->_u_r_common("r",@_);
1668 #-> sub CPAN::Shell::u ;
1670 shift->_u_r_common("u",@_);
1673 # XXX intentionally undocumented because not considered enough
1674 #-> sub CPAN::Shell::failed ;
1676 my($self,$only_id,$silent) = @_;
1678 DIST: for my $d ($CPAN::META->all_objects("CPAN::Distribution")) {
1680 for my $nosayer (qw(signature_verify make make_test install)) {
1681 next unless exists $d->{$nosayer};
1682 next unless $d->{$nosayer}->failed;
1686 next DIST unless $failed;
1687 next DIST if $only_id && $only_id != $d->{$failed}->commandid;
1694 $d->{$failed}->text,
1697 my $scope = $only_id ? "command" : "session";
1699 $CPAN::Frontend->myprint("Failed installations in this $scope:\n$print");
1700 } elsif (!$only_id || !$silent) {
1701 $CPAN::Frontend->myprint("No installations failed in this $scope\n");
1705 # XXX intentionally undocumented because not considered enough
1706 #-> sub CPAN::Shell::status ;
1709 require Devel::Size;
1710 my $ps = FileHandle->new;
1711 open $ps, "/proc/$$/status";
1714 next unless /VmSize:\s+(\d+)/;
1718 $CPAN::Frontend->mywarn(sprintf(
1719 "%-27s %6d\n%-27s %6d\n",
1723 Devel::Size::total_size($CPAN::META)/1024,
1725 for my $k (sort keys %$CPAN::META) {
1726 next unless substr($k,0,4) eq "read";
1727 warn sprintf " %-26s %6d\n", $k, Devel::Size::total_size($CPAN::META->{$k})/1024;
1728 for my $k2 (sort keys %{$CPAN::META->{$k}}) {
1729 warn sprintf " %-25s %6d %6d\n",
1731 Devel::Size::total_size($CPAN::META->{$k}{$k2})/1024,
1732 scalar keys %{$CPAN::META->{$k}{$k2}};
1737 #-> sub CPAN::Shell::autobundle ;
1740 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
1741 my(@bundle) = $self->_u_r_common("a",@_);
1742 my($todir) = File::Spec->catdir($CPAN::Config->{'cpan_home'},"Bundle");
1743 File::Path::mkpath($todir);
1744 unless (-d $todir) {
1745 $CPAN::Frontend->myprint("Couldn't mkdir $todir for some reason\n");
1748 my($y,$m,$d) = (localtime)[5,4,3];
1752 my($me) = sprintf "Snapshot_%04d_%02d_%02d_%02d", $y, $m, $d, $c;
1753 my($to) = File::Spec->catfile($todir,"$me.pm");
1755 $me = sprintf "Snapshot_%04d_%02d_%02d_%02d", $y, $m, $d, ++$c;
1756 $to = File::Spec->catfile($todir,"$me.pm");
1758 my($fh) = FileHandle->new(">$to") or Carp::croak "Can't open >$to: $!";
1760 "package Bundle::$me;\n\n",
1761 "\$VERSION = '0.01';\n\n",
1765 "Bundle::$me - Snapshot of installation on ",
1766 $Config::Config{'myhostname'},
1769 "\n\n=head1 SYNOPSIS\n\n",
1770 "perl -MCPAN -e 'install Bundle::$me'\n\n",
1771 "=head1 CONTENTS\n\n",
1772 join("\n", @bundle),
1773 "\n\n=head1 CONFIGURATION\n\n",
1775 "\n\n=head1 AUTHOR\n\n",
1776 "This Bundle has been generated automatically ",
1777 "by the autobundle routine in CPAN.pm.\n",
1780 $CPAN::Frontend->myprint("\nWrote bundle file
1784 #-> sub CPAN::Shell::expandany ;
1787 CPAN->debug("s[$s]") if $CPAN::DEBUG;
1788 if ($s =~ m|/|) { # looks like a file
1789 $s = CPAN::Distribution->normalize($s);
1790 return $CPAN::META->instance('CPAN::Distribution',$s);
1791 # Distributions spring into existence, not expand
1792 } elsif ($s =~ m|^Bundle::|) {
1793 $self->local_bundles; # scanning so late for bundles seems
1794 # both attractive and crumpy: always
1795 # current state but easy to forget
1797 return $self->expand('Bundle',$s);
1799 return $self->expand('Module',$s)
1800 if $CPAN::META->exists('CPAN::Module',$s);
1805 #-> sub CPAN::Shell::expand ;
1808 my($type,@args) = @_;
1809 CPAN->debug("type[$type]args[@args]") if $CPAN::DEBUG;
1810 my $class = "CPAN::$type";
1811 my $methods = ['id'];
1812 for my $meth (qw(name)) {
1813 next if $] < 5.00303; # no "can"
1814 next unless $class->can($meth);
1815 push @$methods, $meth;
1817 $self->expand_by_method($class,$methods,@args);
1820 sub expand_by_method {
1822 my($class,$methods,@args) = @_;
1825 my($regex,$command);
1826 if ($arg =~ m|^/(.*)/$|) {
1828 } elsif ($arg =~ m/=/) {
1832 CPAN->debug(sprintf "class[%s]regex[%s]command[%s]",
1834 defined $regex ? $regex : "UNDEFINED",
1835 defined $command ? $command : "UNDEFINED",
1837 if (defined $regex) {
1839 $CPAN::META->all_objects($class)
1842 # BUG, we got an empty object somewhere
1843 require Data::Dumper;
1844 CPAN->debug(sprintf(
1845 "Bug in CPAN: Empty id on obj[%s][%s]",
1847 Data::Dumper::Dumper($obj)
1851 for my $method (@$methods) {
1852 if ($obj->$method() =~ /$regex/i) {
1858 } elsif ($command) {
1859 die "equal sign in command disabled (immature interface), ".
1861 ! \$CPAN::Shell::ADVANCED_QUERY=1
1862 to enable it. But please note, this is HIGHLY EXPERIMENTAL code
1863 that may go away anytime.\n"
1864 unless $ADVANCED_QUERY;
1865 my($method,$criterion) = $arg =~ /(.+?)=(.+)/;
1866 my($matchcrit) = $criterion =~ m/^~(.+)/;
1870 $CPAN::META->all_objects($class)
1872 my $lhs = $self->$method() or next; # () for 5.00503
1874 push @m, $self if $lhs =~ m/$matchcrit/;
1876 push @m, $self if $lhs eq $criterion;
1881 if ( $class eq 'CPAN::Bundle' ) {
1882 $xarg =~ s/^(Bundle::)?(.*)/Bundle::$2/;
1883 } elsif ($class eq "CPAN::Distribution") {
1884 $xarg = CPAN::Distribution->normalize($arg);
1888 if ($CPAN::META->exists($class,$xarg)) {
1889 $obj = $CPAN::META->instance($class,$xarg);
1890 } elsif ($CPAN::META->exists($class,$arg)) {
1891 $obj = $CPAN::META->instance($class,$arg);
1898 @m = sort {$a->id cmp $b->id} @m;
1899 if ( $CPAN::DEBUG ) {
1900 my $wantarray = wantarray;
1901 my $join_m = join ",", map {$_->id} @m;
1902 $self->debug("wantarray[$wantarray]join_m[$join_m]");
1904 return wantarray ? @m : $m[0];
1907 #-> sub CPAN::Shell::format_result ;
1910 my($type,@args) = @_;
1911 @args = '/./' unless @args;
1912 my(@result) = $self->expand($type,@args);
1913 my $result = @result == 1 ?
1914 $result[0]->as_string :
1916 "No objects of type $type found for argument @args\n" :
1918 (map {$_->as_glimpse} @result),
1919 scalar @result, " items found\n",
1924 #-> sub CPAN::Shell::report_fh ;
1926 my $installation_report_fh;
1927 my $previously_noticed = 0;
1930 return $installation_report_fh if $installation_report_fh;
1931 $installation_report_fh = File::Temp->new(
1932 template => 'cpan_install_XXXX',
1936 unless ( $installation_report_fh ) {
1937 warn("Couldn't open installation report file; " .
1938 "no report file will be generated."
1939 ) unless $previously_noticed++;
1945 # The only reason for this method is currently to have a reliable
1946 # debugging utility that reveals which output is going through which
1947 # channel. No, I don't like the colors ;-)
1949 #-> sub CPAN::Shell::print_ornameted ;
1950 sub print_ornamented {
1951 my($self,$what,$ornament) = @_;
1953 return unless defined $what;
1955 local $| = 1; # Flush immediately
1956 if ( $CPAN::Be_Silent ) {
1957 print {report_fh()} $what;
1961 if ($CPAN::Config->{term_is_latin}){
1964 =~ s{([\xC0-\xDF])([\x80-\xBF])}{chr(ord($1)<<6&0xC0|ord($2)&0x3F)}eg; #};
1966 if ($PRINT_ORNAMENTING) {
1967 unless (defined &color) {
1968 if ($CPAN::META->has_inst("Term::ANSIColor")) {
1969 import Term::ANSIColor "color";
1971 *color = sub { return "" };
1975 for $line (split /\n/, $what) {
1976 $longest = length($line) if length($line) > $longest;
1978 my $sprintf = "%-" . $longest . "s";
1980 $what =~ s/(.*\n?)//m;
1983 my($nl) = chomp $line ? "\n" : "";
1984 # print "line[$line]ornament[$ornament]sprintf[$sprintf]\n";
1985 print color($ornament), sprintf($sprintf,$line), color("reset"), $nl;
1989 # $what .= "\n"; # newlines unless $PRINT_ORNAMENTING
1995 my($self,$what) = @_;
1997 $self->print_ornamented($what, 'bold blue on_yellow');
2001 my($self,$what) = @_;
2002 $self->myprint($what);
2007 my($self,$what) = @_;
2008 $self->print_ornamented($what, 'bold red on_yellow');
2012 my($self,$what) = @_;
2013 $self->print_ornamented($what, 'bold red on_white');
2014 Carp::confess "died";
2018 my($self,$what) = @_;
2019 $self->print_ornamented($what, 'bold red on_white');
2024 my($self, $sleep) = @_;
2029 return if -t STDOUT;
2030 my $odef = select STDERR;
2037 #-> sub CPAN::Shell::rematein ;
2038 # RE-adme||MA-ke||TE-st||IN-stall
2041 my($meth,@some) = @_;
2043 while($meth =~ /^(force|notest)$/) {
2044 push @pragma, $meth;
2045 $meth = shift @some or
2046 $CPAN::Frontend->mydie("Pragma $pragma[-1] used without method: ".
2050 CPAN->debug("pragma[@pragma]meth[$meth]some[@some]") if $CPAN::DEBUG;
2052 # Here is the place to set "test_count" on all involved parties to
2053 # 0. We then can pass this counter on to the involved
2054 # distributions and those can refuse to test if test_count > X. In
2055 # the first stab at it we could use a 1 for "X".
2057 # But when do I reset the distributions to start with 0 again?
2058 # Jost suggested to have a random or cycling interaction ID that
2059 # we pass through. But the ID is something that is just left lying
2060 # around in addition to the counter, so I'd prefer to set the
2061 # counter to 0 now, and repeat at the end of the loop. But what
2062 # about dependencies? They appear later and are not reset, they
2063 # enter the queue but not its copy. How do they get a sensible
2066 # construct the queue
2068 STHING: foreach $s (@some) {
2071 CPAN->debug("s is an object[$s]") if $CPAN::DEBUG;
2073 } elsif ($s =~ m|^/|) { # looks like a regexp
2074 $CPAN::Frontend->mywarn("Sorry, $meth with a regular expression is ".
2078 } elsif ($meth eq "ls") {
2079 $self->handle_ls(\@pragma,$s);
2082 CPAN->debug("calling expandany [$s]") if $CPAN::DEBUG;
2083 $obj = CPAN::Shell->expandany($s);
2086 $obj->color_cmd_tmps(0,1);
2087 CPAN::Queue->new($obj->id);
2089 } elsif ($CPAN::META->exists('CPAN::Author',uc($s))) {
2090 $obj = $CPAN::META->instance('CPAN::Author',uc($s));
2091 if ($meth =~ /^(dump|ls)$/) {
2094 $CPAN::Frontend->myprint(
2096 "Don't be silly, you can't $meth ",
2104 ->myprint(qq{Warning: Cannot $meth $s, }.
2105 qq{don\'t know what it is.
2110 to find objects with matching identifiers.
2116 # queuerunner (please be warned: when I started to change the
2117 # queue to hold objects instead of names, I made one or two
2118 # mistakes and never found which. I reverted back instead)
2119 while ($s = CPAN::Queue->first) {
2122 $obj = $s; # I do not believe, we would survive if this happened
2124 $obj = CPAN::Shell->expandany($s);
2126 for my $pragma (@pragma) {
2129 ($] < 5.00303 || $obj->can($pragma))){
2130 ### compatibility with 5.003
2131 $obj->$pragma($meth); # the pragma "force" in
2132 # "CPAN::Distribution" must know
2133 # what we are intending
2136 if ($]>=5.00303 && $obj->can('called_for')) {
2137 $obj->called_for($s);
2140 qq{pragma[@pragma]meth[$meth]obj[$obj]as_string\[}.
2146 CPAN::Queue->delete($s);
2148 CPAN->debug("failed");
2152 CPAN::Queue->delete_first($s);
2154 for my $obj (@qcopy) {
2155 $obj->color_cmd_tmps(0,0);
2156 delete $obj->{incommandcolor};
2160 #-> sub CPAN::Shell::recent ;
2164 CPAN::Distribution::_display_url( $self, $CPAN::Defaultrecent );
2169 # set up the dispatching methods
2171 for my $command (qw(
2186 *$command = sub { shift->rematein($command, @_); };
2190 package CPAN::LWP::UserAgent;
2194 return if $SETUPDONE;
2195 if ($CPAN::META->has_usable('LWP::UserAgent')) {
2196 require LWP::UserAgent;
2197 @ISA = qw(Exporter LWP::UserAgent);
2200 $CPAN::Frontend->mywarn("LWP::UserAgent not available\n");
2204 sub get_basic_credentials {
2205 my($self, $realm, $uri, $proxy) = @_;
2206 return unless $proxy;
2207 if ($USER && $PASSWD) {
2208 } elsif (defined $CPAN::Config->{proxy_user} &&
2209 defined $CPAN::Config->{proxy_pass}) {
2210 $USER = $CPAN::Config->{proxy_user};
2211 $PASSWD = $CPAN::Config->{proxy_pass};
2213 require ExtUtils::MakeMaker;
2214 ExtUtils::MakeMaker->import(qw(prompt));
2215 $USER = prompt("Proxy authentication needed!
2216 (Note: to permanently configure username and password run
2217 o conf proxy_user your_username
2218 o conf proxy_pass your_password
2220 if ($CPAN::META->has_inst("Term::ReadKey")) {
2221 Term::ReadKey::ReadMode("noecho");
2223 $CPAN::Frontend->mywarn("Warning: Term::ReadKey seems not to be available, your password will be echoed to the terminal!\n");
2225 $PASSWD = prompt("Password:");
2226 if ($CPAN::META->has_inst("Term::ReadKey")) {
2227 Term::ReadKey::ReadMode("restore");
2229 $CPAN::Frontend->myprint("\n\n");
2231 return($USER,$PASSWD);
2234 # mirror(): Its purpose is to deal with proxy authentication. When we
2235 # call SUPER::mirror, we relly call the mirror method in
2236 # LWP::UserAgent. LWP::UserAgent will then call
2237 # $self->get_basic_credentials or some equivalent and this will be
2238 # $self->dispatched to our own get_basic_credentials method.
2240 # Our own get_basic_credentials sets $USER and $PASSWD, two globals.
2242 # 407 stands for HTTP_PROXY_AUTHENTICATION_REQUIRED. Which means
2243 # although we have gone through our get_basic_credentials, the proxy
2244 # server refuses to connect. This could be a case where the username or
2245 # password has changed in the meantime, so I'm trying once again without
2246 # $USER and $PASSWD to give the get_basic_credentials routine another
2247 # chance to set $USER and $PASSWD.
2249 # mirror(): Its purpose is to deal with proxy authentication. When we
2250 # call SUPER::mirror, we relly call the mirror method in
2251 # LWP::UserAgent. LWP::UserAgent will then call
2252 # $self->get_basic_credentials or some equivalent and this will be
2253 # $self->dispatched to our own get_basic_credentials method.
2255 # Our own get_basic_credentials sets $USER and $PASSWD, two globals.
2257 # 407 stands for HTTP_PROXY_AUTHENTICATION_REQUIRED. Which means
2258 # although we have gone through our get_basic_credentials, the proxy
2259 # server refuses to connect. This could be a case where the username or
2260 # password has changed in the meantime, so I'm trying once again without
2261 # $USER and $PASSWD to give the get_basic_credentials routine another
2262 # chance to set $USER and $PASSWD.
2265 my($self,$url,$aslocal) = @_;
2266 my $result = $self->SUPER::mirror($url,$aslocal);
2267 if ($result->code == 407) {
2270 $result = $self->SUPER::mirror($url,$aslocal);
2278 #-> sub CPAN::FTP::ftp_get ;
2280 my($class,$host,$dir,$file,$target) = @_;
2282 qq[Going to fetch file [$file] from dir [$dir]
2283 on host [$host] as local [$target]\n]
2285 my $ftp = Net::FTP->new($host);
2287 $CPAN::Frontend->mywarn(" Could not connect to host '$host' with Net::FTP\n");
2290 return 0 unless defined $ftp;
2291 $ftp->debug(1) if $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG;
2292 $class->debug(qq[Going to login("anonymous","$Config::Config{cf_email}")]);
2293 unless ( $ftp->login("anonymous",$Config::Config{'cf_email'}) ){
2294 my $msg = $ftp->message;
2295 $CPAN::Frontend->mywarn(" Couldn't login on $host: $msg");
2298 unless ( $ftp->cwd($dir) ){
2299 my $msg = $ftp->message;
2300 $CPAN::Frontend->mywarn(" Couldn't cwd $dir: $msg");
2304 $class->debug(qq[Going to ->get("$file","$target")\n]) if $CPAN::DEBUG;
2305 unless ( $ftp->get($file,$target) ){
2306 my $msg = $ftp->message;
2307 $CPAN::Frontend->mywarn(" Couldn't fetch $file from $host: $msg");
2310 $ftp->quit; # it's ok if this fails
2314 # If more accuracy is wanted/needed, Chris Leach sent me this patch...
2316 # > *** /install/perl/live/lib/CPAN.pm- Wed Sep 24 13:08:48 1997
2317 # > --- /tmp/cp Wed Sep 24 13:26:40 1997
2319 # > *** 1562,1567 ****
2320 # > --- 1562,1580 ----
2321 # > return 1 if substr($url,0,4) eq "file";
2322 # > return 1 unless $url =~ m|://([^/]+)|;
2324 # > + my $proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'};
2326 # > + $proxy =~ m|://([^/:]+)|;
2328 # > + my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'};
2329 # > + if ($noproxy) {
2330 # > + if ($host !~ /$noproxy$/) {
2331 # > + $host = $proxy;
2334 # > + $host = $proxy;
2337 # > require Net::Ping;
2338 # > return 1 unless $Net::Ping::VERSION >= 2;
2342 #-> sub CPAN::FTP::localize ;
2344 my($self,$file,$aslocal,$force) = @_;
2346 Carp::croak "Usage: ->localize(cpan_file,as_local_file[,$force])"
2347 unless defined $aslocal;
2348 $self->debug("file[$file] aslocal[$aslocal] force[$force]")
2351 if ($^O eq 'MacOS') {
2352 # Comment by AK on 2000-09-03: Uniq short filenames would be
2353 # available in CHECKSUMS file
2354 my($name, $path) = File::Basename::fileparse($aslocal, '');
2355 if (length($name) > 31) {
2366 my $size = 31 - length($suf);
2367 while (length($name) > $size) {
2371 $aslocal = File::Spec->catfile($path, $name);
2375 if (-f $aslocal && -r _ && !($force & 1)){
2379 # empty file from a previous unsuccessful attempt to download it
2381 $CPAN::Frontend->mydie("Found a zero-length '$aslocal' that I could not remove.");
2386 rename $aslocal, "$aslocal.bak";
2390 my($aslocal_dir) = File::Basename::dirname($aslocal);
2391 File::Path::mkpath($aslocal_dir);
2392 $CPAN::Frontend->mywarn(qq{Warning: You are not allowed to write into }.
2393 qq{directory "$aslocal_dir".
2394 I\'ll continue, but if you encounter problems, they may be due
2395 to insufficient permissions.\n}) unless -w $aslocal_dir;
2397 # Inheritance is not easier to manage than a few if/else branches
2398 if ($CPAN::META->has_usable('LWP::UserAgent')) {
2400 CPAN::LWP::UserAgent->config;
2401 eval {$Ua = CPAN::LWP::UserAgent->new;}; # Why is has_usable still not fit enough?
2403 $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n")
2407 $Ua->proxy('ftp', $var)
2408 if $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy};
2409 $Ua->proxy('http', $var)
2410 if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy};
2413 # >>>>> On Wed, 13 Dec 2000 09:21:34 -0500, "Robison, Jonathon (J.M.)" <jrobiso2@visteon.com> said:
2415 # > I note that although CPAN.pm can use proxies, it doesn't seem equipped to
2416 # > use ones that require basic autorization.
2418 # > Example of when I use it manually in my own stuff:
2420 # > $ua->proxy(['http','ftp'], http://my.proxy.server:83');
2421 # > $req->proxy_authorization_basic("username","password");
2422 # > $res = $ua->request($req);
2426 if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy};
2430 for my $prx (qw(ftp_proxy http_proxy no_proxy)) {
2431 $ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx};
2434 # Try the list of urls for each single object. We keep a record
2435 # where we did get a file from
2436 my(@reordered,$last);
2437 $CPAN::Config->{urllist} ||= [];
2438 unless (ref $CPAN::Config->{urllist} eq 'ARRAY') {
2439 warn "Malformed urllist; ignoring. Configuration file corrupt?\n";
2441 $last = $#{$CPAN::Config->{urllist}};
2442 if ($force & 2) { # local cpans probably out of date, don't reorder
2443 @reordered = (0..$last);
2447 (substr($CPAN::Config->{urllist}[$b],0,4) eq "file")
2449 (substr($CPAN::Config->{urllist}[$a],0,4) eq "file")
2460 @levels = ($Themethod, grep {$_ ne $Themethod} qw/easy hard hardest/);
2462 @levels = qw/easy hard hardest/;
2464 @levels = qw/easy/ if $^O eq 'MacOS';
2466 for $levelno (0..$#levels) {
2467 my $level = $levels[$levelno];
2468 my $method = "host$level";
2469 my @host_seq = $level eq "easy" ?
2470 @reordered : 0..$last; # reordered has CDROM up front
2471 @host_seq = (0) unless @host_seq;
2472 my $ret = $self->$method(\@host_seq,$file,$aslocal);
2474 $Themethod = $level;
2476 # utime $now, $now, $aslocal; # too bad, if we do that, we
2477 # might alter a local mirror
2478 $self->debug("level[$level]") if $CPAN::DEBUG;
2482 last if $CPAN::Signal; # need to cleanup
2485 unless ($CPAN::Signal) {
2488 qq{Please check, if the URLs I found in your configuration file \(}.
2489 join(", ", @{$CPAN::Config->{urllist}}).
2490 qq{\) are valid. The urllist can be edited.},
2491 qq{E.g. with 'o conf urllist push ftp://myurl/'};
2492 $CPAN::Frontend->myprint(Text::Wrap::wrap("","",@mess). "\n\n");
2494 $CPAN::Frontend->myprint("Could not fetch $file\n");
2497 rename "$aslocal.bak", $aslocal;
2498 $CPAN::Frontend->myprint("Trying to get away with old file:\n" .
2499 $self->ls($aslocal));
2506 my($self,$host_seq,$file,$aslocal) = @_;
2508 HOSTEASY: for $i (@$host_seq) {
2509 my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
2510 $url .= "/" unless substr($url,-1) eq "/";
2512 $self->debug("localizing perlish[$url]") if $CPAN::DEBUG;
2513 if ($url =~ /^file:/) {
2515 if ($CPAN::META->has_inst('URI::URL')) {
2516 my $u = URI::URL->new($url);
2518 } else { # works only on Unix, is poorly constructed, but
2519 # hopefully better than nothing.
2520 # RFC 1738 says fileurl BNF is
2521 # fileurl = "file://" [ host | "localhost" ] "/" fpath
2522 # Thanks to "Mark D. Baushke" <mdb@cisco.com> for
2524 ($l = $url) =~ s|^file://[^/]*/|/|; # discard the host part
2525 $l =~ s|^file:||; # assume they
2528 $l =~ s|^/||s unless -f $l; # e.g. /P:
2529 $self->debug("without URI::URL we try local file $l") if $CPAN::DEBUG;
2531 if ( -f $l && -r _) {
2535 # Maybe mirror has compressed it?
2537 $self->debug("found compressed $l.gz") if $CPAN::DEBUG;
2538 CPAN::Tarzip->new("$l.gz")->gunzip($aslocal);
2545 if ($CPAN::META->has_usable('LWP')) {
2546 $CPAN::Frontend->myprint("Fetching with LWP:
2550 CPAN::LWP::UserAgent->config;
2551 eval { $Ua = CPAN::LWP::UserAgent->new; };
2553 $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n");
2556 my $res = $Ua->mirror($url, $aslocal);
2557 if ($res->is_success) {
2560 utime $now, $now, $aslocal; # download time is more
2561 # important than upload time
2563 } elsif ($url !~ /\.gz(?!\n)\Z/) {
2564 my $gzurl = "$url.gz";
2565 $CPAN::Frontend->myprint("Fetching with LWP:
2568 $res = $Ua->mirror($gzurl, "$aslocal.gz");
2569 if ($res->is_success &&
2570 CPAN::Tarzip->new("$aslocal.gz")->gunzip($aslocal)
2576 $CPAN::Frontend->myprint(sprintf(
2577 "LWP failed with code[%s] message[%s]\n",
2581 # Alan Burlison informed me that in firewall environments
2582 # Net::FTP can still succeed where LWP fails. So we do not
2583 # skip Net::FTP anymore when LWP is available.
2586 $CPAN::Frontend->myprint("LWP not available\n");
2588 return if $CPAN::Signal;
2589 if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
2590 # that's the nice and easy way thanks to Graham
2591 my($host,$dir,$getfile) = ($1,$2,$3);
2592 if ($CPAN::META->has_usable('Net::FTP')) {
2594 $CPAN::Frontend->myprint("Fetching with Net::FTP:
2597 $self->debug("getfile[$getfile]dir[$dir]host[$host]" .
2598 "aslocal[$aslocal]") if $CPAN::DEBUG;
2599 if (CPAN::FTP->ftp_get($host,$dir,$getfile,$aslocal)) {
2603 if ($aslocal !~ /\.gz(?!\n)\Z/) {
2604 my $gz = "$aslocal.gz";
2605 $CPAN::Frontend->myprint("Fetching with Net::FTP
2608 if (CPAN::FTP->ftp_get($host,
2612 CPAN::Tarzip->new($gz)->gunzip($aslocal)
2621 return if $CPAN::Signal;
2626 my($self,$host_seq,$file,$aslocal) = @_;
2628 # Came back if Net::FTP couldn't establish connection (or
2629 # failed otherwise) Maybe they are behind a firewall, but they
2630 # gave us a socksified (or other) ftp program...
2633 my($devnull) = $CPAN::Config->{devnull} || "";
2635 my($aslocal_dir) = File::Basename::dirname($aslocal);
2636 File::Path::mkpath($aslocal_dir);
2637 HOSTHARD: for $i (@$host_seq) {
2638 my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
2639 $url .= "/" unless substr($url,-1) eq "/";
2641 my($proto,$host,$dir,$getfile);
2643 # Courtesy Mark Conty mark_conty@cargill.com change from
2644 # if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
2646 if ($url =~ m|^([^:]+)://(.*?)/(.*)/(.*)|) {
2647 # proto not yet used
2648 ($proto,$host,$dir,$getfile) = ($1,$2,$3,$4);
2650 next HOSTHARD; # who said, we could ftp anything except ftp?
2652 next HOSTHARD if $proto eq "file"; # file URLs would have had
2653 # success above. Likely a bogus URL
2655 $self->debug("localizing funkyftpwise[$url]") if $CPAN::DEBUG;
2657 # Try the most capable first and leave ncftp* for last as it only
2659 for my $f (qw(curl wget lynx ncftpget ncftp)) {
2660 my $funkyftp = $CPAN::Config->{$f};
2661 next unless defined $funkyftp;
2662 next if $funkyftp =~ /^\s*$/;
2664 my($asl_ungz, $asl_gz);
2665 ($asl_ungz = $aslocal) =~ s/\.gz//;
2666 $asl_gz = "$asl_ungz.gz";
2668 my($src_switch) = "";
2670 my($stdout_redir) = " > $asl_ungz";
2672 $src_switch = " -source";
2673 } elsif ($f eq "ncftp"){
2674 $src_switch = " -c";
2675 } elsif ($f eq "wget"){
2676 $src_switch = " -O $asl_ungz";
2678 } elsif ($f eq 'curl'){
2679 $src_switch = ' -L';
2682 if ($f eq "ncftpget"){
2683 $chdir = "cd $aslocal_dir && ";
2686 $CPAN::Frontend->myprint(
2688 Trying with "$funkyftp$src_switch" to get
2692 "$chdir$funkyftp$src_switch \"$url\" $devnull$stdout_redir";
2693 $self->debug("system[$system]") if $CPAN::DEBUG;
2695 if (($wstatus = system($system)) == 0
2698 -s $asl_ungz # lynx returns 0 when it fails somewhere
2704 } elsif ($asl_ungz ne $aslocal) {
2705 # test gzip integrity
2706 if (CPAN::Tarzip->new($asl_ungz)->gtest) {
2707 # e.g. foo.tar is gzipped --> foo.tar.gz
2708 rename $asl_ungz, $aslocal;
2710 CPAN::Tarzip->new($asl_gz)->gzip($asl_ungz);
2715 } elsif ($url !~ /\.gz(?!\n)\Z/) {
2717 -f $asl_ungz && -s _ == 0;
2718 my $gz = "$aslocal.gz";
2719 my $gzurl = "$url.gz";
2720 $CPAN::Frontend->myprint(
2722 Trying with "$funkyftp$src_switch" to get
2725 my($system) = "$funkyftp$src_switch \"$url.gz\" $devnull > $asl_gz";
2726 $self->debug("system[$system]") if $CPAN::DEBUG;
2728 if (($wstatus = system($system)) == 0
2732 # test gzip integrity
2733 my $ct = CPAN::Tarzip->new($asl_gz);
2735 $ct->gunzip($aslocal);
2737 # somebody uncompressed file for us?
2738 rename $asl_ungz, $aslocal;
2743 unlink $asl_gz if -f $asl_gz;
2746 my $estatus = $wstatus >> 8;
2747 my $size = -f $aslocal ?
2748 ", left\n$aslocal with size ".-s _ :
2749 "\nWarning: expected file [$aslocal] doesn't exist";
2750 $CPAN::Frontend->myprint(qq{
2751 System call "$system"
2752 returned status $estatus (wstat $wstatus)$size
2755 return if $CPAN::Signal;
2756 } # transfer programs
2761 my($self,$host_seq,$file,$aslocal) = @_;
2764 my($aslocal_dir) = File::Basename::dirname($aslocal);
2765 File::Path::mkpath($aslocal_dir);
2766 my $ftpbin = $CPAN::Config->{ftp};
2767 HOSTHARDEST: for $i (@$host_seq) {
2768 unless (length $ftpbin && MM->maybe_command($ftpbin)) {
2769 $CPAN::Frontend->myprint("No external ftp command available\n\n");
2772 my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
2773 $url .= "/" unless substr($url,-1) eq "/";
2775 $self->debug("localizing ftpwise[$url]") if $CPAN::DEBUG;
2776 unless ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
2779 my($host,$dir,$getfile) = ($1,$2,$3);
2781 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
2782 $ctime,$blksize,$blocks) = stat($aslocal);
2783 $timestamp = $mtime ||= 0;
2784 my($netrc) = CPAN::FTP::netrc->new;
2785 my($netrcfile) = $netrc->netrc;
2786 my($verbose) = $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? " -v" : "";
2787 my $targetfile = File::Basename::basename($aslocal);
2793 map("cd $_", split /\//, $dir), # RFC 1738
2795 "get $getfile $targetfile",
2799 CPAN->debug("No ~/.netrc file found") if $CPAN::DEBUG;
2800 } elsif ($netrc->hasdefault || $netrc->contains($host)) {
2801 CPAN->debug(sprintf("hasdef[%d]cont($host)[%d]",
2803 $netrc->contains($host))) if $CPAN::DEBUG;
2804 if ($netrc->protected) {
2805 $CPAN::Frontend->myprint(qq{
2806 Trying with external ftp to get
2808 As this requires some features that are not thoroughly tested, we\'re
2809 not sure, that we get it right....
2813 $self->talk_ftp("$ftpbin$verbose $host",
2815 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
2816 $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
2818 if ($mtime > $timestamp) {
2819 $CPAN::Frontend->myprint("GOT $aslocal\n");
2823 $CPAN::Frontend->myprint("Hmm... Still failed!\n");
2825 return if $CPAN::Signal;
2827 $CPAN::Frontend->mywarn(qq{Your $netrcfile is not }.
2828 qq{correctly protected.\n});
2831 $CPAN::Frontend->mywarn("Your ~/.netrc neither contains $host
2832 nor does it have a default entry\n");
2835 # OK, they don't have a valid ~/.netrc. Use 'ftp -n'
2836 # then and login manually to host, using e-mail as
2838 $CPAN::Frontend->myprint(qq{Issuing "$ftpbin$verbose -n"\n});
2842 "user anonymous $Config::Config{'cf_email'}"
2844 $self->talk_ftp("$ftpbin$verbose -n", @dialog);
2845 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
2846 $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
2848 if ($mtime > $timestamp) {
2849 $CPAN::Frontend->myprint("GOT $aslocal\n");
2853 $CPAN::Frontend->myprint("Bad luck... Still failed!\n");
2855 return if $CPAN::Signal;
2856 $CPAN::Frontend->myprint("Can't access URL $url.\n\n");
2862 my($self,$command,@dialog) = @_;
2863 my $fh = FileHandle->new;
2864 $fh->open("|$command") or die "Couldn't open ftp: $!";
2865 foreach (@dialog) { $fh->print("$_\n") }
2866 $fh->close; # Wait for process to complete
2868 my $estatus = $wstatus >> 8;
2869 $CPAN::Frontend->myprint(qq{
2870 Subprocess "|$command"
2871 returned status $estatus (wstat $wstatus)
2875 # find2perl needs modularization, too, all the following is stolen
2879 my($self,$name) = @_;
2880 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
2881 $atime,$mtime,$ctime,$blksize,$blocks) = lstat($name);
2883 my($perms,%user,%group);
2887 $blocks = int(($blocks + 1) / 2);
2890 $blocks = int(($sizemm + 1023) / 1024);
2893 if (-f _) { $perms = '-'; }
2894 elsif (-d _) { $perms = 'd'; }
2895 elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
2896 elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
2897 elsif (-p _) { $perms = 'p'; }
2898 elsif (-S _) { $perms = 's'; }
2899 else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
2901 my(@rwx) = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
2902 my(@moname) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
2903 my $tmpmode = $mode;
2904 my $tmp = $rwx[$tmpmode & 7];
2906 $tmp = $rwx[$tmpmode & 7] . $tmp;
2908 $tmp = $rwx[$tmpmode & 7] . $tmp;
2909 substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
2910 substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
2911 substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
2914 my $user = $user{$uid} || $uid; # too lazy to implement lookup
2915 my $group = $group{$gid} || $gid;
2917 my($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
2919 my($moname) = $moname[$mon];
2920 if (-M _ > 365.25 / 2) {
2921 $timeyear = $year + 1900;
2924 $timeyear = sprintf("%02d:%02d", $hour, $min);
2927 sprintf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
2941 package CPAN::FTP::netrc;
2946 my $file = File::Spec->catfile($ENV{HOME},".netrc");
2948 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
2949 $atime,$mtime,$ctime,$blksize,$blocks)
2954 my($fh,@machines,$hasdefault);
2956 $fh = FileHandle->new or die "Could not create a filehandle";
2958 if($fh->open($file)){
2959 $protected = ($mode & 077) == 0;
2961 NETRC: while (<$fh>) {
2962 my(@tokens) = split " ", $_;
2963 TOKEN: while (@tokens) {
2964 my($t) = shift @tokens;
2965 if ($t eq "default"){
2969 last TOKEN if $t eq "macdef";
2970 if ($t eq "machine") {
2971 push @machines, shift @tokens;
2976 $file = $hasdefault = $protected = "";
2980 'mach' => [@machines],
2982 'hasdefault' => $hasdefault,
2983 'protected' => $protected,
2987 # CPAN::FTP::hasdefault;
2988 sub hasdefault { shift->{'hasdefault'} }
2989 sub netrc { shift->{'netrc'} }
2990 sub protected { shift->{'protected'} }
2992 my($self,$mach) = @_;
2993 for ( @{$self->{'mach'}} ) {
2994 return 1 if $_ eq $mach;
2999 package CPAN::Complete;
3003 my($text, $line, $start, $end) = @_;
3004 my(@perlret) = cpl($text, $line, $start);
3005 # find longest common match. Can anybody show me how to peruse
3006 # T::R::Gnu to have this done automatically? Seems expensive.
3007 return () unless @perlret;
3008 my($newtext) = $text;
3009 for (my $i = length($text)+1;;$i++) {
3010 last unless length($perlret[0]) && length($perlret[0]) >= $i;
3011 my $try = substr($perlret[0],0,$i);
3012 my @tries = grep {substr($_,0,$i) eq $try} @perlret;
3013 # warn "try[$try]tries[@tries]";
3014 if (@tries == @perlret) {
3020 ($newtext,@perlret);
3023 #-> sub CPAN::Complete::cpl ;
3025 my($word,$line,$pos) = @_;
3029 CPAN->debug("word [$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
3031 if ($line =~ s/^(force\s*)//) {
3036 @return = grep /^$word/, @CPAN::Complete::COMMANDS;
3037 } elsif ( $line !~ /^[\!abcdghimorutl]/ ) {
3039 } elsif ($line =~ /^(a|ls)\s/) {
3040 @return = cplx('CPAN::Author',uc($word));
3041 } elsif ($line =~ /^b\s/) {
3042 CPAN::Shell->local_bundles;
3043 @return = cplx('CPAN::Bundle',$word);
3044 } elsif ($line =~ /^d\s/) {
3045 @return = cplx('CPAN::Distribution',$word);
3046 } elsif ($line =~ m/^(
3047 [mru]|make|clean|dump|get|test|install|readme|look|cvs_import|perldoc|recent
3049 if ($word =~ /^Bundle::/) {
3050 CPAN::Shell->local_bundles;
3052 @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
3053 } elsif ($line =~ /^i\s/) {
3054 @return = cpl_any($word);
3055 } elsif ($line =~ /^reload\s/) {
3056 @return = cpl_reload($word,$line,$pos);
3057 } elsif ($line =~ /^o\s/) {
3058 @return = cpl_option($word,$line,$pos);
3059 } elsif ($line =~ m/^\S+\s/ ) {
3060 # fallback for future commands and what we have forgotten above
3061 @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
3068 #-> sub CPAN::Complete::cplx ;
3070 my($class, $word) = @_;
3071 # I believed for many years that this was sorted, today I
3072 # realized, it wasn't sorted anymore. Now (rev 1.301 / v 1.55) I
3073 # make it sorted again. Maybe sort was dropped when GNU-readline
3074 # support came in? The RCS file is difficult to read on that:-(
3075 sort grep /^\Q$word\E/, map { $_->id } $CPAN::META->all_objects($class);
3078 #-> sub CPAN::Complete::cpl_any ;
3082 cplx('CPAN::Author',$word),
3083 cplx('CPAN::Bundle',$word),
3084 cplx('CPAN::Distribution',$word),
3085 cplx('CPAN::Module',$word),
3089 #-> sub CPAN::Complete::cpl_reload ;
3091 my($word,$line,$pos) = @_;
3093 my(@words) = split " ", $line;
3094 CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
3095 my(@ok) = qw(cpan index);
3096 return @ok if @words == 1;
3097 return grep /^\Q$word\E/, @ok if @words == 2 && $word;
3100 #-> sub CPAN::Complete::cpl_option ;
3102 my($word,$line,$pos) = @_;
3104 my(@words) = split " ", $line;
3105 CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
3106 my(@ok) = qw(conf debug);
3107 return @ok if @words == 1;
3108 return grep /^\Q$word\E/, @ok if @words == 2 && length($word);
3110 } elsif ($words[1] eq 'index') {
3112 } elsif ($words[1] eq 'conf') {
3113 return CPAN::HandleConfig::cpl(@_);
3114 } elsif ($words[1] eq 'debug') {
3115 return sort grep /^\Q$word\E/i,
3116 sort keys %CPAN::DEBUG, 'all';
3120 package CPAN::Index;
3123 #-> sub CPAN::Index::force_reload ;
3126 $CPAN::Index::LAST_TIME = 0;
3130 #-> sub CPAN::Index::reload ;
3132 my($cl,$force) = @_;
3135 # XXX check if a newer one is available. (We currently read it
3136 # from time to time)
3137 for ($CPAN::Config->{index_expire}) {
3138 $_ = 0.001 unless $_ && $_ > 0.001;
3140 unless (1 || $CPAN::Have_warned->{readmetadatacache}++) {
3141 # debug here when CPAN doesn't seem to read the Metadata
3143 Carp::cluck("META-PROTOCOL[$CPAN::META->{PROTOCOL}]");
3145 unless ($CPAN::META->{PROTOCOL}) {
3146 $cl->read_metadata_cache;
3147 $CPAN::META->{PROTOCOL} ||= "1.0";
3149 if ( $CPAN::META->{PROTOCOL} < PROTOCOL ) {
3150 # warn "Setting last_time to 0";
3151 $LAST_TIME = 0; # No warning necessary
3153 return if $LAST_TIME + $CPAN::Config->{index_expire}*86400 > $time
3156 # IFF we are developing, it helps to wipe out the memory
3157 # between reloads, otherwise it is not what a user expects.
3158 undef $CPAN::META; # Neue Gruendlichkeit since v1.52(r1.274)
3159 $CPAN::META = CPAN->new;
3163 local $LAST_TIME = $time;
3164 local $CPAN::META->{PROTOCOL} = PROTOCOL;
3166 my $needshort = $^O eq "dos";
3168 $cl->rd_authindex($cl
3170 "authors/01mailrc.txt.gz",
3172 File::Spec->catfile('authors', '01mailrc.gz') :
3173 File::Spec->catfile('authors', '01mailrc.txt.gz'),
3176 $debug = "timing reading 01[".($t2 - $time)."]";
3178 return if $CPAN::Signal; # this is sometimes lengthy
3179 $cl->rd_modpacks($cl
3181 "modules/02packages.details.txt.gz",
3183 File::Spec->catfile('modules', '02packag.gz') :
3184 File::Spec->catfile('modules', '02packages.details.txt.gz'),
3187 $debug .= "02[".($t2 - $time)."]";
3189 return if $CPAN::Signal; # this is sometimes lengthy
3192 "modules/03modlist.data.gz",
3194 File::Spec->catfile('modules', '03mlist.gz') :
3195 File::Spec->catfile('modules', '03modlist.data.gz'),
3197 $cl->write_metadata_cache;
3199 $debug .= "03[".($t2 - $time)."]";
3201 CPAN->debug($debug) if $CPAN::DEBUG;
3204 $CPAN::META->{PROTOCOL} = PROTOCOL;
3207 #-> sub CPAN::Index::reload_x ;
3209 my($cl,$wanted,$localname,$force) = @_;
3210 $force |= 2; # means we're dealing with an index here
3211 CPAN::HandleConfig->load; # we should guarantee loading wherever we rely
3213 $localname ||= $wanted;
3214 my $abs_wanted = File::Spec->catfile($CPAN::Config->{'keep_source_where'},
3218 -M $abs_wanted < $CPAN::Config->{'index_expire'} &&
3221 my $s = $CPAN::Config->{'index_expire'} == 1 ? "" : "s";
3222 $cl->debug(qq{$abs_wanted younger than $CPAN::Config->{'index_expire'} }.
3223 qq{day$s. I\'ll use that.});
3226 $force |= 1; # means we're quite serious about it.
3228 return CPAN::FTP->localize($wanted,$abs_wanted,$force);
3231 #-> sub CPAN::Index::rd_authindex ;
3233 my($cl, $index_target) = @_;
3235 return unless defined $index_target;
3236 $CPAN::Frontend->myprint("Going to read $index_target\n");
3238 tie *FH, 'CPAN::Tarzip', $index_target;
3241 push @lines, split /\012/ while <FH>;
3243 my($userid,$fullname,$email) =
3244 m/alias\s+(\S+)\s+\"([^\"\<]+)\s+\<([^\>]+)\>\"/;
3245 next unless $userid && $fullname && $email;
3247 # instantiate an author object
3248 my $userobj = $CPAN::META->instance('CPAN::Author',$userid);
3249 $userobj->set('FULLNAME' => $fullname, 'EMAIL' => $email);
3250 return if $CPAN::Signal;
3255 my($self,$dist) = @_;
3256 $dist = $self->{'id'} unless defined $dist;
3257 my($ret) = $dist =~ m|(?:\w/\w\w/)?([^/]+)/|;
3261 #-> sub CPAN::Index::rd_modpacks ;
3263 my($self, $index_target) = @_;
3265 return unless defined $index_target;
3266 $CPAN::Frontend->myprint("Going to read $index_target\n");
3267 my $fh = CPAN::Tarzip->TIEHANDLE($index_target);
3270 while ($_ = $fh->READLINE) {
3272 my @ls = map {"$_\n"} split /\n/, $_;
3273 unshift @ls, "\n" x length($1) if /^(\n+)/;
3277 my($line_count,$last_updated);
3279 my $shift = shift(@lines);
3280 last if $shift =~ /^\s*$/;
3281 $shift =~ /^Line-Count:\s+(\d+)/ and $line_count = $1;
3282 $shift =~ /^Last-Updated:\s+(.+)/ and $last_updated = $1;
3284 if (not defined $line_count) {
3286 warn qq{Warning: Your $index_target does not contain a Line-Count header.
3287 Please check the validity of the index file by comparing it to more
3288 than one CPAN mirror. I'll continue but problems seem likely to
3293 } elsif ($line_count != scalar @lines) {
3295 warn sprintf qq{Warning: Your %s
3296 contains a Line-Count header of %d but I see %d lines there. Please
3297 check the validity of the index file by comparing it to more than one
3298 CPAN mirror. I'll continue but problems seem likely to happen.\a\n},
3299 $index_target, $line_count, scalar(@lines);
3302 if (not defined $last_updated) {
3304 warn qq{Warning: Your $index_target does not contain a Last-Updated header.
3305 Please check the validity of the index file by comparing it to more
3306 than one CPAN mirror. I'll continue but problems seem likely to
3314 ->myprint(sprintf qq{ Database was generated on %s\n},
3316 $DATE_OF_02 = $last_updated;
3319 if ($CPAN::META->has_inst('HTTP::Date')) {
3321 $age -= HTTP::Date::str2time($last_updated);
3323 $CPAN::Frontend->myprint(" HTTP::Date not available\n");
3324 require Time::Local;
3325 my(@d) = $last_updated =~ / (\d+) (\w+) (\d+) (\d+):(\d+):(\d+) /;
3326 $d[1] = index("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", $d[1])/4;
3327 $age -= $d[1]>=0 ? Time::Local::timegm(@d[5,4,3,0,1,2]) : 0;
3334 qq{Warning: This index file is %d days old.
3335 Please check the host you chose as your CPAN mirror for staleness.
3336 I'll continue but problems seem likely to happen.\a\n},
3339 } elsif ($age < -1) {
3343 qq{Warning: Your system date is %d days behind this index file!
3345 Timestamp index file: %s
3346 Please fix your system time, problems with the make command expected.\n},
3356 # A necessity since we have metadata_cache: delete what isn't
3358 my $secondtime = $CPAN::META->exists("CPAN::Module","CPAN");
3359 CPAN->debug("secondtime[$secondtime]") if $CPAN::DEBUG;
3363 # before 1.56 we split into 3 and discarded the rest. From
3364 # 1.57 we assign remaining text to $comment thus allowing to
3365 # influence isa_perl
3366 my($mod,$version,$dist,$comment) = split " ", $_, 4;
3367 my($bundle,$id,$userid);
3369 if ($mod eq 'CPAN' &&
3371 CPAN::Queue->exists('Bundle::CPAN') ||
3372 CPAN::Queue->exists('CPAN')
3376 if ($version > $CPAN::VERSION){
3377 $CPAN::Frontend->myprint(qq{
3378 There's a new CPAN.pm version (v$version) available!
3379 [Current version is v$CPAN::VERSION]
3380 You might want to try
3381 install Bundle::CPAN
3383 without quitting the current session. It should be a seamless upgrade
3384 while we are running...
3387 $CPAN::Frontend->myprint(qq{\n});
3389 last if $CPAN::Signal;
3390 } elsif ($mod =~ /^Bundle::(.*)/) {
3395 $id = $CPAN::META->instance('CPAN::Bundle',$mod);
3396 # Let's make it a module too, because bundles have so much
3397 # in common with modules.
3399 # Changed in 1.57_63: seems like memory bloat now without
3400 # any value, so commented out
3402 # $CPAN::META->instance('CPAN::Module',$mod);
3406 # instantiate a module object
3407 $id = $CPAN::META->instance('CPAN::Module',$mod);
3411 # Although CPAN prohibits same name with different version the
3412 # indexer may have changed the version for the same distro
3413 # since the last time ("Force Reindexing" feature)
3414 if ($id->cpan_file ne $dist
3416 $id->cpan_version ne $version
3418 $userid = $id->userid || $self->userid($dist);
3420 'CPAN_USERID' => $userid,
3421 'CPAN_VERSION' => $version,
3422 'CPAN_FILE' => $dist,
3426 # instantiate a distribution object
3427 if ($CPAN::META->exists('CPAN::Distribution',$dist)) {
3428 # we do not need CONTAINSMODS unless we do something with
3429 # this dist, so we better produce it on demand.
3431 ## my $obj = $CPAN::META->instance(
3432 ## 'CPAN::Distribution' => $dist
3434 ## $obj->{CONTAINSMODS}{$mod} = undef; # experimental
3436 $CPAN::META->instance(
3437 'CPAN::Distribution' => $dist
3439 'CPAN_USERID' => $userid,
3440 'CPAN_COMMENT' => $comment,
3444 for my $name ($mod,$dist) {
3445 CPAN->debug("exists name[$name]") if $CPAN::DEBUG;
3446 $exists{$name} = undef;
3449 return if $CPAN::Signal;
3453 for my $class (qw(CPAN::Module CPAN::Bundle CPAN::Distribution)) {
3454 for my $o ($CPAN::META->all_objects($class)) {
3455 next if exists $exists{$o->{ID}};
3456 $CPAN::META->delete($class,$o->{ID});
3457 CPAN->debug("deleting ID[$o->{ID}] in class[$class]")
3464 #-> sub CPAN::Index::rd_modlist ;
3466 my($cl,$index_target) = @_;
3467 return unless defined $index_target;
3468 $CPAN::Frontend->myprint("Going to read $index_target\n");
3469 my $fh = CPAN::Tarzip->TIEHANDLE($index_target);
3473 while ($_ = $fh->READLINE) {
3475 my @ls = map {"$_\n"} split /\n/, $_;
3476 unshift @ls, "\n" x length($1) if /^(\n+)/;
3480 my $shift = shift(@eval);
3481 if ($shift =~ /^Date:\s+(.*)/){
3482 return if $DATE_OF_03 eq $1;
3485 last if $shift =~ /^\s*$/;
3488 push @eval, q{CPAN::Modulelist->data;};
3490 my($comp) = Safe->new("CPAN::Safe1");
3491 my($eval) = join("", @eval);
3492 my $ret = $comp->reval($eval);
3493 Carp::confess($@) if $@;
3494 return if $CPAN::Signal;
3496 my $obj = $CPAN::META->instance("CPAN::Module",$_);
3497 delete $ret->{$_}{modid}; # not needed here, maybe elsewhere
3498 $obj->set(%{$ret->{$_}});
3499 return if $CPAN::Signal;
3503 #-> sub CPAN::Index::write_metadata_cache ;
3504 sub write_metadata_cache {
3506 return unless $CPAN::Config->{'cache_metadata'};
3507 return unless $CPAN::META->has_usable("Storable");
3509 foreach my $k (qw(CPAN::Bundle CPAN::Author CPAN::Module
3510 CPAN::Distribution)) {
3511 $cache->{$k} = $CPAN::META->{readonly}{$k}; # unsafe meta access, ok
3513 my $metadata_file = File::Spec->catfile($CPAN::Config->{cpan_home},"Metadata");
3514 $cache->{last_time} = $LAST_TIME;
3515 $cache->{DATE_OF_02} = $DATE_OF_02;
3516 $cache->{PROTOCOL} = PROTOCOL;
3517 $CPAN::Frontend->myprint("Going to write $metadata_file\n");
3518 eval { Storable::nstore($cache, $metadata_file) };
3519 $CPAN::Frontend->mywarn($@) if $@; # ?? missing "\n" after $@ in mywarn ??
3522 #-> sub CPAN::Index::read_metadata_cache ;
3523 sub read_metadata_cache {
3525 return unless $CPAN::Config->{'cache_metadata'};
3526 return unless $CPAN::META->has_usable("Storable");
3527 my $metadata_file = File::Spec->catfile($CPAN::Config->{cpan_home},"Metadata");
3528 return unless -r $metadata_file and -f $metadata_file;
3529 $CPAN::Frontend->myprint("Going to read $metadata_file\n");
3531 eval { $cache = Storable::retrieve($metadata_file) };
3532 $CPAN::Frontend->mywarn($@) if $@; # ?? missing "\n" after $@ in mywarn ??
3533 if (!$cache || ref $cache ne 'HASH'){
3537 if (exists $cache->{PROTOCOL}) {
3538 if (PROTOCOL > $cache->{PROTOCOL}) {
3539 $CPAN::Frontend->mywarn(sprintf("Ignoring Metadata cache written ".
3540 "with protocol v%s, requiring v%s\n",
3547 $CPAN::Frontend->mywarn("Ignoring Metadata cache written ".
3548 "with protocol v1.0\n");
3553 while(my($class,$v) = each %$cache) {
3554 next unless $class =~ /^CPAN::/;
3555 $CPAN::META->{readonly}{$class} = $v; # unsafe meta access, ok
3556 while (my($id,$ro) = each %$v) {
3557 $CPAN::META->{readwrite}{$class}{$id} ||=
3558 $class->new(ID=>$id, RO=>$ro);
3563 unless ($clcnt) { # sanity check
3564 $CPAN::Frontend->myprint("Warning: Found no data in $metadata_file\n");
3567 if ($idcnt < 1000) {
3568 $CPAN::Frontend->myprint("Warning: Found only $idcnt objects ".
3569 "in $metadata_file\n");
3572 $CPAN::META->{PROTOCOL} ||=
3573 $cache->{PROTOCOL}; # reading does not up or downgrade, but it
3574 # does initialize to some protocol
3575 $LAST_TIME = $cache->{last_time};
3576 $DATE_OF_02 = $cache->{DATE_OF_02};
3577 $CPAN::Frontend->myprint(" Database was generated on $DATE_OF_02\n")
3578 if defined $DATE_OF_02; # An old cache may not contain DATE_OF_02
3582 package CPAN::InfoObj;
3587 exists $self->{RO} and return $self->{RO};
3592 my $ro = $self->ro or return;
3593 return $ro->{CPAN_USERID};
3596 sub id { shift->{ID}; }
3598 #-> sub CPAN::InfoObj::new ;
3600 my $this = bless {}, shift;
3605 # The set method may only be used by code that reads index data or
3606 # otherwise "objective" data from the outside world. All session
3607 # related material may do anything else with instance variables but
3608 # must not touch the hash under the RO attribute. The reason is that
3609 # the RO hash gets written to Metadata file and is thus persistent.
3611 #-> sub CPAN::InfoObj::set ;
3613 my($self,%att) = @_;
3614 my $class = ref $self;
3616 # This must be ||=, not ||, because only if we write an empty
3617 # reference, only then the set method will write into the readonly
3618 # area. But for Distributions that spring into existence, maybe
3619 # because of a typo, we do not like it that they are written into
3620 # the readonly area and made permanent (at least for a while) and
3621 # that is why we do not "allow" other places to call ->set.
3622 unless ($self->id) {
3623 CPAN->debug("Bug? Empty ID, rejecting");
3626 my $ro = $self->{RO} =
3627 $CPAN::META->{readonly}{$class}{$self->id} ||= {};
3629 while (my($k,$v) = each %att) {
3634 #-> sub CPAN::InfoObj::as_glimpse ;
3638 my $class = ref($self);
3639 $class =~ s/^CPAN:://;
3640 push @m, sprintf "%-15s %s\n", $class, $self->{ID};
3644 #-> sub CPAN::InfoObj::as_string ;
3648 my $class = ref($self);
3649 $class =~ s/^CPAN:://;
3650 push @m, $class, " id = $self->{ID}\n";
3652 for (sort keys %$ro) {
3653 # next if m/^(ID|RO)$/;
3655 if ($_ eq "CPAN_USERID") {
3656 $extra .= " (".$self->author;
3657 my $email; # old perls!
3658 if ($email = $CPAN::META->instance("CPAN::Author",
3661 $extra .= " <$email>";
3663 $extra .= " <no email>";
3666 } elsif ($_ eq "FULLNAME") { # potential UTF-8 conversion
3667 push @m, sprintf " %-12s %s\n", $_, $self->fullname;
3670 next unless defined $ro->{$_};
3671 push @m, sprintf " %-12s %s%s\n", $_, $ro->{$_}, $extra;
3673 for (sort keys %$self) {
3674 next if m/^(ID|RO)$/;
3675 if (ref($self->{$_}) eq "ARRAY") {
3676 push @m, sprintf " %-12s %s\n", $_, "@{$self->{$_}}";
3677 } elsif (ref($self->{$_}) eq "HASH") {
3681 join(" ",keys %{$self->{$_}}),
3684 push @m, sprintf " %-12s %s\n", $_, $self->{$_};
3690 #-> sub CPAN::InfoObj::author ;
3693 $CPAN::META->instance("CPAN::Author",$self->cpan_userid)->fullname;
3696 #-> sub CPAN::InfoObj::dump ;
3699 require Data::Dumper;
3700 print Data::Dumper::Dumper($self);
3703 package CPAN::Author;
3706 #-> sub CPAN::Author::force
3712 #-> sub CPAN::Author::force
3715 delete $self->{force};
3718 #-> sub CPAN::Author::id
3721 my $id = $self->{ID};
3722 $CPAN::Frontend->mydie("Illegal author id[$id]") unless $id =~ /^[A-Z]/;
3726 #-> sub CPAN::Author::as_glimpse ;
3730 my $class = ref($self);
3731 $class =~ s/^CPAN:://;
3732 push @m, sprintf(qq{%-15s %s ("%s" <%s>)\n},
3740 #-> sub CPAN::Author::fullname ;
3742 shift->ro->{FULLNAME};
3746 #-> sub CPAN::Author::email ;
3747 sub email { shift->ro->{EMAIL}; }
3749 #-> sub CPAN::Author::ls ;
3752 my $glob = shift || "";
3753 my $silent = shift || 0;
3756 # adapted from CPAN::Distribution::verifyCHECKSUM ;
3757 my(@csf); # chksumfile
3758 @csf = $self->id =~ /(.)(.)(.*)/;
3759 $csf[1] = join "", @csf[0,1];
3760 $csf[2] = join "", @csf[1,2]; # ("A","AN","ANDK")
3762 @dl = $self->dir_listing([$csf[0],"CHECKSUMS"], 0, 1);
3763 unless (grep {$_->[2] eq $csf[1]} @dl) {
3764 $CPAN::Frontend->myprint("Directory $csf[1]/ does not exist\n") unless $silent ;
3767 @dl = $self->dir_listing([@csf[0,1],"CHECKSUMS"], 0, 1);
3768 unless (grep {$_->[2] eq $csf[2]} @dl) {
3769 $CPAN::Frontend->myprint("Directory $id/ does not exist\n") unless $silent;
3772 @dl = $self->dir_listing([@csf,"CHECKSUMS"], 1, 1);
3774 my $rglob = Text::Glob::glob_to_regex($glob);
3775 @dl = grep { $_->[2] =~ /$rglob/ } @dl;
3777 $CPAN::Frontend->myprint(join "", map {
3778 sprintf("%8d %10s %s/%s\n", $_->[0], $_->[1], $id, $_->[2])
3779 } sort { $a->[2] cmp $b->[2] } @dl);
3782 # returns an array of arrays, the latter contain (size,mtime,filename)
3783 #-> sub CPAN::Author::dir_listing ;
3786 my $chksumfile = shift;
3787 my $recursive = shift;
3788 my $may_ftp = shift;
3790 File::Spec->catfile($CPAN::Config->{keep_source_where},
3791 "authors", "id", @$chksumfile);
3795 # Purge and refetch old (pre-PGP) CHECKSUMS; they are a security
3796 # hazard. (Without GPG installed they are not that much better,
3798 $fh = FileHandle->new;
3799 if (open($fh, $lc_want)) {
3800 my $line = <$fh>; close $fh;
3801 unlink($lc_want) unless $line =~ /PGP/;
3805 # connect "force" argument with "index_expire".
3806 my $force = $self->{force};
3807 if (my @stat = stat $lc_want) {
3808 $force ||= $stat[9] + $CPAN::Config->{index_expire}*86400 <= time;
3812 $lc_file = CPAN::FTP->localize(
3813 "authors/id/@$chksumfile",
3818 $CPAN::Frontend->myprint("Trying $lc_want.gz\n");
3819 $chksumfile->[-1] .= ".gz";
3820 $lc_file = CPAN::FTP->localize("authors/id/@$chksumfile",
3823 $lc_file =~ s{\.gz(?!\n)\Z}{}; #};
3824 CPAN::Tarzip->new("$lc_file.gz")->gunzip($lc_file);
3830 $lc_file = $lc_want;
3831 # we *could* second-guess and if the user has a file: URL,
3832 # then we could look there. But on the other hand, if they do
3833 # have a file: URL, wy did they choose to set
3834 # $CPAN::Config->{show_upload_date} to false?
3837 # adapted from CPAN::Distribution::CHECKSUM_check_file ;
3838 $fh = FileHandle->new;
3840 if (open $fh, $lc_file){
3843 $eval =~ s/\015?\012/\n/g;
3845 my($comp) = Safe->new();
3846 $cksum = $comp->reval($eval);
3848 rename $lc_file, "$lc_file.bad";
3849 Carp::confess($@) if $@;
3851 } elsif ($may_ftp) {
3852 Carp::carp "Could not open $lc_file for reading.";
3854 # Maybe should warn: "You may want to set show_upload_date to a true value"
3858 for $f (sort keys %$cksum) {
3859 if (exists $cksum->{$f}{isdir}) {
3861 my(@dir) = @$chksumfile;
3863 push @dir, $f, "CHECKSUMS";
3865 [$_->[0], $_->[1], "$f/$_->[2]"]
3866 } $self->dir_listing(\@dir,1,$may_ftp);
3868 push @result, [ 0, "-", $f ];
3872 ($cksum->{$f}{"size"}||0),
3873 $cksum->{$f}{"mtime"}||"---",
3881 package CPAN::Distribution;
3887 my $ro = $self->ro or return;
3893 delete $self->{later};
3896 # add the A/AN/ stuff
3897 # CPAN::Distribution::normalize
3900 $s = $self->id unless defined $s;
3904 $s !~ m|[A-Z]/[A-Z-]{2}/[A-Z-]{2,}/|
3906 return $s if $s =~ m:^N/A|^Contact Author: ;
3907 $s =~ s|^(.)(.)([^/]*/)(.+)$|$1/$1$2/$1$2$3$4| or
3908 $CPAN::Frontend->mywarn("Strange distribution name [$s]\n");
3909 CPAN->debug("s[$s]") if $CPAN::DEBUG;
3917 return $id unless $id =~ m|^./../|;
3921 # mark as dirty/clean
3922 #-> sub CPAN::Distribution::color_cmd_tmps ;
3923 sub color_cmd_tmps {
3925 my($depth) = shift || 0;
3926 my($color) = shift || 0;
3927 my($ancestors) = shift || [];
3928 # a distribution needs to recurse into its prereq_pms
3930 return if exists $self->{incommandcolor}
3931 && $self->{incommandcolor}==$color;
3933 $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
3935 # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
3936 my $prereq_pm = $self->prereq_pm;
3937 if (defined $prereq_pm) {
3938 for my $pre (keys %$prereq_pm) {
3939 my $premo = CPAN::Shell->expand("Module",$pre);
3940 $premo->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
3944 delete $self->{sponsored_mods};
3945 delete $self->{badtestcnt};
3947 $self->{incommandcolor} = $color;
3950 #-> sub CPAN::Distribution::as_string ;
3953 $self->containsmods;
3955 $self->SUPER::as_string(@_);
3958 #-> sub CPAN::Distribution::containsmods ;
3961 return keys %{$self->{CONTAINSMODS}} if exists $self->{CONTAINSMODS};
3962 my $dist_id = $self->{ID};
3963 for my $mod ($CPAN::META->all_objects("CPAN::Module")) {
3964 my $mod_file = $mod->cpan_file or next;
3965 my $mod_id = $mod->{ID} or next;
3966 # warn "mod_file[$mod_file] dist_id[$dist_id] mod_id[$mod_id]";
3968 $self->{CONTAINSMODS}{$mod_id} = undef if $mod_file eq $dist_id;
3970 keys %{$self->{CONTAINSMODS}};
3973 #-> sub CPAN::Distribution::upload_date ;
3976 return $self->{UPLOAD_DATE} if exists $self->{UPLOAD_DATE};
3977 my(@local_wanted) = split(/\//,$self->id);
3978 my $filename = pop @local_wanted;
3979 push @local_wanted, "CHECKSUMS";
3980 my $author = CPAN::Shell->expand("Author",$self->cpan_userid);
3981 return unless $author;
3982 my @dl = $author->dir_listing(\@local_wanted,0,$CPAN::Config->{show_upload_date});
3984 my($dirent) = grep { $_->[2] eq $filename } @dl;
3985 # warn sprintf "dirent[%s]id[%s]", $dirent, $self->id;
3986 return unless $dirent->[1];
3987 return $self->{UPLOAD_DATE} = $dirent->[1];
3990 #-> sub CPAN::Distribution::uptodate ;
3994 foreach $c ($self->containsmods) {
3995 my $obj = CPAN::Shell->expandany($c);
3996 return 0 unless $obj->uptodate;
4001 #-> sub CPAN::Distribution::called_for ;
4004 $self->{CALLED_FOR} = $id if defined $id;
4005 return $self->{CALLED_FOR};
4008 #-> sub CPAN::Distribution::safe_chdir ;
4010 my($self,$todir) = @_;
4011 # we die if we cannot chdir and we are debuggable
4012 Carp::confess("safe_chdir called without todir argument")
4013 unless defined $todir and length $todir;
4015 $self->debug(sprintf "changed directory to %s", CPAN::anycwd())
4018 unless (-x $todir) {
4019 unless (chmod 0755, $todir) {
4020 my $cwd = CPAN::anycwd();
4021 $CPAN::Frontend->mywarn("I have neither the -x permission nor the permission ".
4022 "to change the permission; cannot chdir ".
4025 $CPAN::Frontend->mydie(qq{Could not chdir from cwd[$cwd] }.
4026 qq{to todir[$todir]: $!});
4030 $self->debug(sprintf "changed directory to %s", CPAN::anycwd())
4033 my $cwd = CPAN::anycwd();
4034 $CPAN::Frontend->mydie(qq{Could not chdir from cwd[$cwd] }.
4035 qq{to todir[$todir] (a chmod has been issued): $!});
4040 #-> sub CPAN::Distribution::get ;
4045 exists $self->{'build_dir'} and push @e,
4046 "Is already unwrapped into directory $self->{'build_dir'}";
4047 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
4049 my $sub_wd = CPAN::anycwd(); # for cleaning up as good as possible
4052 # Get the file on local disk
4057 File::Spec->catfile(
4058 $CPAN::Config->{keep_source_where},
4061 split(/\//,$self->id)
4064 $self->debug("Doing localize") if $CPAN::DEBUG;
4065 unless ($local_file =
4066 CPAN::FTP->localize("authors/id/$self->{ID}",
4069 if ($CPAN::Index::DATE_OF_02) {
4070 $note = "Note: Current database in memory was generated ".
4071 "on $CPAN::Index::DATE_OF_02\n";
4073 $CPAN::Frontend->mydie("Giving up on '$local_wanted'\n$note");
4075 $self->debug("local_file[$local_file]") if $CPAN::DEBUG;
4076 $self->{localfile} = $local_file;
4077 return if $CPAN::Signal;
4082 if ($CPAN::META->has_inst("Digest::SHA")) {
4083 $self->debug("Digest::SHA is installed, verifying");
4084 $self->verifyCHECKSUM;
4086 $self->debug("Digest::SHA is NOT installed");
4088 return if $CPAN::Signal;
4091 # Create a clean room and go there
4093 $CPAN::META->{cachemgr} ||= CPAN::CacheMgr->new(); # unsafe meta access, ok
4094 my $builddir = $CPAN::META->{cachemgr}->dir; # unsafe meta access, ok
4095 $self->safe_chdir($builddir);
4096 $self->debug("Removing tmp") if $CPAN::DEBUG;
4097 File::Path::rmtree("tmp");
4098 mkdir "tmp", 0755 or Carp::croak "Couldn't mkdir tmp: $!";
4100 $self->safe_chdir($sub_wd);
4103 $self->safe_chdir("tmp");
4108 $self->debug("local_file[$local_file]") if $CPAN::DEBUG;
4109 my $ct = CPAN::Tarzip->new($local_file);
4110 if ($local_file =~ /(\.tar\.(bz2|gz|Z)|\.tgz)(?!\n)\Z/i){
4111 $self->{was_uncompressed}++ unless $ct->gtest();
4112 $self->untar_me($ct);
4113 } elsif ( $local_file =~ /\.zip(?!\n)\Z/i ) {
4114 $self->unzip_me($ct);
4115 } elsif ( $local_file =~ /\.pm(\.(gz|Z))?(?!\n)\Z/) {
4116 $self->{was_uncompressed}++ unless $ct->gtest();
4117 $self->debug("calling pm2dir for local_file[$local_file]") if $CPAN::DEBUG;
4118 $self->pm2dir_me($local_file);
4120 $self->{archived} = "NO";
4121 $self->safe_chdir($sub_wd);
4125 # we are still in the tmp directory!
4126 # Let's check if the package has its own directory.
4127 my $dh = DirHandle->new(File::Spec->curdir)
4128 or Carp::croak("Couldn't opendir .: $!");
4129 my @readdir = grep $_ !~ /^\.\.?(?!\n)\Z/s, $dh->read; ### MAC??
4131 my ($distdir,$packagedir);
4132 if (@readdir == 1 && -d $readdir[0]) {
4133 $distdir = $readdir[0];
4134 $packagedir = File::Spec->catdir($builddir,$distdir);
4135 $self->debug("packagedir[$packagedir]builddir[$builddir]distdir[$distdir]")
4137 -d $packagedir and $CPAN::Frontend->myprint("Removing previously used ".
4139 File::Path::rmtree($packagedir);
4140 File::Copy::move($distdir,$packagedir) or
4141 Carp::confess("Couldn't move $distdir to $packagedir: $!");
4142 $self->debug(sprintf("moved distdir[%s] to packagedir[%s] -e[%s]-d[%s]",
4149 my $userid = $self->cpan_userid;
4151 CPAN->debug("no userid? self[$self]");
4154 my $pragmatic_dir = $userid . '000';
4155 $pragmatic_dir =~ s/\W_//g;
4156 $pragmatic_dir++ while -d "../$pragmatic_dir";
4157 $packagedir = File::Spec->catdir($builddir,$pragmatic_dir);
4158 $self->debug("packagedir[$packagedir]") if $CPAN::DEBUG;
4159 File::Path::mkpath($packagedir);
4161 for $f (@readdir) { # is already without "." and ".."
4162 my $to = File::Spec->catdir($packagedir,$f);
4163 File::Copy::move($f,$to) or Carp::confess("Couldn't move $f to $to: $!");
4167 $self->safe_chdir($sub_wd);
4171 $self->{'build_dir'} = $packagedir;
4172 $self->safe_chdir($builddir);
4173 File::Path::rmtree("tmp");
4175 $self->safe_chdir($packagedir);
4176 if ($CPAN::META->has_inst("Module::Signature")) {
4177 if (-f "SIGNATURE") {
4178 $self->debug("Module::Signature is installed, verifying") if $CPAN::DEBUG;
4179 my $rv = Module::Signature::verify();
4180 if ($rv != Module::Signature::SIGNATURE_OK() and
4181 $rv != Module::Signature::SIGNATURE_MISSING()) {
4182 $CPAN::Frontend->myprint(
4183 qq{\nSignature invalid for }.
4184 qq{distribution file. }.
4185 qq{Please investigate.\n\n}.
4187 $CPAN::META->instance(
4194 sprintf(qq{I'd recommend removing %s. Its signature
4195 is invalid. Maybe you have configured your 'urllist' with
4196 a bad URL. Please check this array with 'o conf urllist', and
4197 retry. For more information, try opening a subshell with
4205 $self->{signature_verify} = CPAN::Distrostatus->new("NO");
4206 $CPAN::Frontend->mywarn(Text::Wrap::wrap("","",$wrap));
4207 $CPAN::Frontend->mysleep(5) if $CPAN::Frontend->can("mysleep");
4209 $self->{signature_verify} = CPAN::Distrostatus->new("YES");
4212 $CPAN::Frontend->myprint(qq{Package came without SIGNATURE\n\n});
4215 $self->debug("Module::Signature is NOT installed") if $CPAN::DEBUG;
4217 $self->safe_chdir($builddir);
4218 return if $CPAN::Signal;
4221 my($mpl) = File::Spec->catfile($packagedir,"Makefile.PL");
4222 my($mpl_exists) = -f $mpl;
4223 unless ($mpl_exists) {
4224 # NFS has been reported to have racing problems after the
4225 # renaming of a directory in some environments.
4228 my $mpldh = DirHandle->new($packagedir)
4229 or Carp::croak("Couldn't opendir $packagedir: $!");
4230 $mpl_exists = grep /^Makefile\.PL$/, $mpldh->read;
4233 my $prefer_installer = "eumm"; # eumm|mb
4234 if (-f File::Spec->catfile($packagedir,"Build.PL")) {
4235 if ($mpl_exists) { # they *can* choose
4236 if ($CPAN::META->has_inst("Module::Build")) {
4237 $prefer_installer = $CPAN::Config->{prefer_installer};
4240 $prefer_installer = "mb";
4243 if (lc($prefer_installer) eq "mb") {
4244 $self->{modulebuild} = "YES";
4245 } elsif (! $mpl_exists) {
4246 $self->debug(sprintf("makefilepl[%s]anycwd[%s]",
4250 my($configure) = File::Spec->catfile($packagedir,"Configure");
4251 if (-f $configure) {
4252 # do we have anything to do?
4253 $self->{'configure'} = $configure;
4254 } elsif (-f File::Spec->catfile($packagedir,"Makefile")) {
4255 $CPAN::Frontend->myprint(qq{
4256 Package comes with a Makefile and without a Makefile.PL.
4257 We\'ll try to build it with that Makefile then.
4259 $self->{writemakefile} = "YES";
4262 my $cf = $self->called_for || "unknown";
4267 $cf =~ s|[/\\:]||g; # risk of filesystem damage
4268 $cf = "unknown" unless length($cf);
4269 $CPAN::Frontend->myprint(qq{Package seems to come without Makefile.PL.
4270 (The test -f "$mpl" returned false.)
4271 Writing one on our own (setting NAME to $cf)\a\n});
4272 $self->{had_no_makefile_pl}++;
4275 # Writing our own Makefile.PL
4277 my $fh = FileHandle->new;
4279 or Carp::croak("Could not open >$mpl: $!");
4281 qq{# This Makefile.PL has been autogenerated by the module CPAN.pm
4282 # because there was no Makefile.PL supplied.
4283 # Autogenerated on: }.scalar localtime().qq{
4285 use ExtUtils::MakeMaker;
4286 WriteMakefile(NAME => q[$cf]);
4296 # CPAN::Distribution::untar_me ;
4299 $self->{archived} = "tar";
4301 $self->{unwrapped} = "YES";
4303 $self->{unwrapped} = "NO";
4307 # CPAN::Distribution::unzip_me ;
4310 $self->{archived} = "zip";
4312 $self->{unwrapped} = "YES";
4314 $self->{unwrapped} = "NO";
4320 my($self,$local_file) = @_;
4321 $self->{archived} = "pm";
4322 my $to = File::Basename::basename($local_file);
4323 if ($to =~ s/\.(gz|Z)(?!\n)\Z//) {
4324 if (CPAN::Tarzip->new($local_file)->gunzip($to)) {
4325 $self->{unwrapped} = "YES";
4327 $self->{unwrapped} = "NO";
4330 File::Copy::cp($local_file,".");
4331 $self->{unwrapped} = "YES";
4335 #-> sub CPAN::Distribution::new ;
4337 my($class,%att) = @_;
4339 # $CPAN::META->{cachemgr} ||= CPAN::CacheMgr->new();
4341 my $this = { %att };
4342 return bless $this, $class;
4345 #-> sub CPAN::Distribution::look ;
4349 if ($^O eq 'MacOS') {
4350 $self->Mac::BuildTools::look;
4354 if ( $CPAN::Config->{'shell'} ) {
4355 $CPAN::Frontend->myprint(qq{
4356 Trying to open a subshell in the build directory...
4359 $CPAN::Frontend->myprint(qq{
4360 Your configuration does not define a value for subshells.
4361 Please define it with "o conf shell <your shell>"
4365 my $dist = $self->id;
4367 unless ($dir = $self->dir) {
4370 unless ($dir ||= $self->dir) {
4371 $CPAN::Frontend->mywarn(qq{
4372 Could not determine which directory to use for looking at $dist.
4376 my $pwd = CPAN::anycwd();
4377 $self->safe_chdir($dir);
4378 $CPAN::Frontend->myprint(qq{Working directory is $dir\n});
4380 local $ENV{CPAN_SHELL_LEVEL} = $ENV{CPAN_SHELL_LEVEL}||0;
4381 $ENV{CPAN_SHELL_LEVEL} += 1;
4382 unless (system($CPAN::Config->{'shell'}) == 0) {
4384 $CPAN::Frontend->mywarn("Subprocess shell exit code $code\n");
4387 $self->safe_chdir($pwd);
4390 # CPAN::Distribution::cvs_import ;
4394 my $dir = $self->dir;
4396 my $package = $self->called_for;
4397 my $module = $CPAN::META->instance('CPAN::Module', $package);
4398 my $version = $module->cpan_version;
4400 my $userid = $self->cpan_userid;
4402 my $cvs_dir = (split /\//, $dir)[-1];
4403 $cvs_dir =~ s/-\d+[^-]+(?!\n)\Z//;
4405 $CPAN::Config->{cvsroot} || $ENV{CVSROOT};
4407 $CPAN::Config->{cvs_site_perl} || $ENV{CVS_SITE_PERL};
4408 if ($cvs_site_perl) {
4409 $cvs_dir = "$cvs_site_perl/$cvs_dir";
4411 my $cvs_log = qq{"imported $package $version sources"};
4412 $version =~ s/\./_/g;
4413 my @cmd = ('cvs', '-d', $cvs_root, 'import', '-m', $cvs_log,
4414 "$cvs_dir", $userid, "v$version");
4416 my $pwd = CPAN::anycwd();
4417 chdir($dir) or $CPAN::Frontend->mydie(qq{Could not chdir to "$dir": $!});
4419 $CPAN::Frontend->myprint(qq{Working directory is $dir\n});
4421 $CPAN::Frontend->myprint(qq{@cmd\n});
4422 system(@cmd) == 0 or
4423 $CPAN::Frontend->mydie("cvs import failed");
4424 chdir($pwd) or $CPAN::Frontend->mydie(qq{Could not chdir to "$pwd": $!});
4427 #-> sub CPAN::Distribution::readme ;
4430 my($dist) = $self->id;
4431 my($sans,$suffix) = $dist =~ /(.+)\.(tgz|tar[\._-]gz|tar\.Z|zip)$/;
4432 $self->debug("sans[$sans] suffix[$suffix]\n") if $CPAN::DEBUG;
4435 File::Spec->catfile(
4436 $CPAN::Config->{keep_source_where},
4439 split(/\//,"$sans.readme"),
4441 $self->debug("Doing localize") if $CPAN::DEBUG;
4442 $local_file = CPAN::FTP->localize("authors/id/$sans.readme",
4444 or $CPAN::Frontend->mydie(qq{No $sans.readme found});;
4446 if ($^O eq 'MacOS') {
4447 Mac::BuildTools::launch_file($local_file);
4451 my $fh_pager = FileHandle->new;
4452 local($SIG{PIPE}) = "IGNORE";
4453 $fh_pager->open("|$CPAN::Config->{'pager'}")
4454 or die "Could not open pager $CPAN::Config->{'pager'}: $!";
4455 my $fh_readme = FileHandle->new;
4456 $fh_readme->open($local_file)
4457 or $CPAN::Frontend->mydie(qq{Could not open "$local_file": $!});
4458 $CPAN::Frontend->myprint(qq{
4461 with pager "$CPAN::Config->{'pager'}"
4464 $fh_pager->print(<$fh_readme>);
4468 #-> sub CPAN::Distribution::verifyCHECKSUM ;
4469 sub verifyCHECKSUM {
4473 $self->{CHECKSUM_STATUS} ||= "";
4474 $self->{CHECKSUM_STATUS} eq "OK" and push @e, "Checksum was ok";
4475 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
4477 my($lc_want,$lc_file,@local,$basename);
4478 @local = split(/\//,$self->id);
4480 push @local, "CHECKSUMS";
4482 File::Spec->catfile($CPAN::Config->{keep_source_where},
4483 "authors", "id", @local);
4488 $self->CHECKSUM_check_file($lc_want)
4490 return $self->{CHECKSUM_STATUS} = "OK";
4492 $lc_file = CPAN::FTP->localize("authors/id/@local",
4495 $CPAN::Frontend->myprint("Trying $lc_want.gz\n");
4496 $local[-1] .= ".gz";
4497 $lc_file = CPAN::FTP->localize("authors/id/@local",
4500 $lc_file =~ s/\.gz(?!\n)\Z//;
4501 CPAN::Tarzip->new("$lc_file.gz")->gunzip($lc_file);
4506 $self->CHECKSUM_check_file($lc_file);
4509 sub SIG_check_file {
4510 my($self,$chk_file) = @_;
4511 my $rv = eval { Module::Signature::_verify($chk_file) };
4513 if ($rv == Module::Signature::SIGNATURE_OK()) {
4514 $CPAN::Frontend->myprint("Signature for $chk_file ok\n");
4515 return $self->{SIG_STATUS} = "OK";
4517 $CPAN::Frontend->myprint(qq{\nSignature invalid for }.
4518 qq{distribution file. }.
4519 qq{Please investigate.\n\n}.
4521 $CPAN::META->instance(
4526 my $wrap = qq{I\'d recommend removing $chk_file. Its signature
4527 is invalid. Maybe you have configured your 'urllist' with
4528 a bad URL. Please check this array with 'o conf urllist', and
4531 $CPAN::Frontend->mydie(Text::Wrap::wrap("","",$wrap));
4535 #-> sub CPAN::Distribution::CHECKSUM_check_file ;
4536 sub CHECKSUM_check_file {
4537 my($self,$chk_file) = @_;
4538 my($cksum,$file,$basename);
4540 if ($CPAN::META->has_inst("Module::Signature") and Module::Signature->VERSION >= 0.26) {
4541 $self->debug("Module::Signature is installed, verifying");
4542 $self->SIG_check_file($chk_file);
4544 $self->debug("Module::Signature is NOT installed");
4547 $file = $self->{localfile};
4548 $basename = File::Basename::basename($file);
4549 my $fh = FileHandle->new;
4550 if (open $fh, $chk_file){
4553 $eval =~ s/\015?\012/\n/g;
4555 my($comp) = Safe->new();
4556 $cksum = $comp->reval($eval);
4558 rename $chk_file, "$chk_file.bad";
4559 Carp::confess($@) if $@;
4562 Carp::carp "Could not open $chk_file for reading";
4565 if (exists $cksum->{$basename}{sha256}) {
4566 $self->debug("Found checksum for $basename:" .
4567 "$cksum->{$basename}{sha256}\n") if $CPAN::DEBUG;
4571 my $eq = $self->eq_CHECKSUM($fh,$cksum->{$basename}{sha256});
4573 $fh = CPAN::Tarzip->TIEHANDLE($file);
4576 my $dg = Digest::SHA->new(256);
4579 while ($fh->READ($ref, 4096) > 0){
4582 my $hexdigest = $dg->hexdigest;
4583 $eq += $hexdigest eq $cksum->{$basename}{'sha256-ungz'};
4587 $CPAN::Frontend->myprint("Checksum for $file ok\n");
4588 return $self->{CHECKSUM_STATUS} = "OK";
4590 $CPAN::Frontend->myprint(qq{\nChecksum mismatch for }.
4591 qq{distribution file. }.
4592 qq{Please investigate.\n\n}.
4594 $CPAN::META->instance(
4599 my $wrap = qq{I\'d recommend removing $file. Its
4600 checksum is incorrect. Maybe you have configured your 'urllist' with
4601 a bad URL. Please check this array with 'o conf urllist', and
4604 $CPAN::Frontend->mydie(Text::Wrap::wrap("","",$wrap));
4606 # former versions just returned here but this seems a
4607 # serious threat that deserves a die
4609 # $CPAN::Frontend->myprint("\n\n");
4613 # close $fh if fileno($fh);
4615 $self->{CHECKSUM_STATUS} ||= "";
4616 if ($self->{CHECKSUM_STATUS} eq "NIL") {
4617 $CPAN::Frontend->mywarn(qq{
4618 Warning: No checksum for $basename in $chk_file.
4620 The cause for this may be that the file is very new and the checksum
4621 has not yet been calculated, but it may also be that something is
4622 going awry right now.
4624 my $answer = ExtUtils::MakeMaker::prompt("Proceed?", "yes");
4625 $answer =~ /^\s*y/i or $CPAN::Frontend->mydie("Aborted.");
4627 $self->{CHECKSUM_STATUS} = "NIL";
4632 #-> sub CPAN::Distribution::eq_CHECKSUM ;
4634 my($self,$fh,$expect) = @_;
4635 my $dg = Digest::SHA->new(256);
4637 while (read($fh, $data, 4096)){
4640 my $hexdigest = $dg->hexdigest;
4641 # warn "fh[$fh] hex[$hexdigest] aexp[$expectMD5]";
4642 $hexdigest eq $expect;
4645 #-> sub CPAN::Distribution::force ;
4647 # Both CPAN::Modules and CPAN::Distributions know if "force" is in
4648 # effect by autoinspection, not by inspecting a global variable. One
4649 # of the reason why this was chosen to work that way was the treatment
4650 # of dependencies. They should not automatically inherit the force
4651 # status. But this has the downside that ^C and die() will return to
4652 # the prompt but will not be able to reset the force_update
4653 # attributes. We try to correct for it currently in the read_metadata
4654 # routine, and immediately before we check for a Signal. I hope this
4655 # works out in one of v1.57_53ff
4658 my($self, $method) = @_;
4660 CHECKSUM_STATUS archived build_dir localfile make install unwrapped
4663 delete $self->{$att};
4665 if ($method && $method =~ /make|test|install/) {
4666 $self->{"force_update"}++; # name should probably have been force_install
4671 my($self, $method) = @_;
4672 # warn "XDEBUG: set notest for $self $method";
4673 $self->{"notest"}++; # name should probably have been force_install
4678 # warn "XDEBUG: deleting notest";
4679 delete $self->{'notest'};
4682 #-> sub CPAN::Distribution::unforce ;
4685 delete $self->{'force_update'};
4688 #-> sub CPAN::Distribution::isa_perl ;
4691 my $file = File::Basename::basename($self->id);
4692 if ($file =~ m{ ^ perl
4705 } elsif ($self->cpan_comment
4707 $self->cpan_comment =~ /isa_perl\(.+?\)/){
4713 #-> sub CPAN::Distribution::perl ;
4719 #-> sub CPAN::Distribution::make ;
4722 my $make = $self->{modulebuild} ? "Build" : "make";
4723 $CPAN::Frontend->myprint(sprintf "Running %s for %s\n", $make, $self->id);
4724 # Emergency brake if they said install Pippi and get newest perl
4725 if ($self->isa_perl) {
4727 $self->called_for ne $self->id &&
4728 ! $self->{force_update}
4730 # if we die here, we break bundles
4731 $CPAN::Frontend->mywarn(sprintf qq{
4732 The most recent version "%s" of the module "%s"
4733 comes with the current version of perl (%s).
4734 I\'ll build that only if you ask for something like
4739 $CPAN::META->instance(
4753 !$self->{archived} || $self->{archived} eq "NO" and push @e,
4754 "Is neither a tar nor a zip archive.";
4756 !$self->{unwrapped} || $self->{unwrapped} eq "NO" and push @e,
4757 "Had problems unarchiving. Please build manually";
4759 unless ($self->{force_update}) {
4760 exists $self->{signature_verify} and $self->{signature_verify}->failed
4761 and push @e, "Did not pass the signature test.";
4764 exists $self->{writemakefile} &&
4765 $self->{writemakefile} =~ m/ ^ NO\s* ( .* ) /sx and push @e,
4766 $1 || "Had some problem writing Makefile";
4768 defined $self->{'make'} and push @e,
4769 "Has already been processed within this session";
4771 exists $self->{later} and length($self->{later}) and
4772 push @e, $self->{later};
4774 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
4776 $CPAN::Frontend->myprint("\n CPAN.pm: Going to build ".$self->id."\n\n");
4777 my $builddir = $self->dir or
4778 $CPAN::Frontend->mydie("PANIC: Cannot determine build directory");
4779 chdir $builddir or Carp::croak("Couldn't chdir $builddir: $!");
4780 $self->debug("Changed directory to $builddir") if $CPAN::DEBUG;
4782 if ($^O eq 'MacOS') {
4783 Mac::BuildTools::make($self);
4788 if ($self->{'configure'}) {
4789 $system = $self->{'configure'};
4790 } elsif ($self->{modulebuild}) {
4791 my($perl) = $self->perl or die "Couldn\'t find executable perl\n";
4792 $system = "$perl Build.PL $CPAN::Config->{mbuildpl_arg}";
4794 my($perl) = $self->perl or die "Couldn\'t find executable perl\n";
4796 # This needs a handler that can be turned on or off:
4797 # $switch = "-MExtUtils::MakeMaker ".
4798 # "-Mops=:default,:filesys_read,:filesys_open,require,chdir"
4800 $system = "$perl $switch Makefile.PL $CPAN::Config->{makepl_arg}";
4802 unless (exists $self->{writemakefile}) {
4803 local($SIG{ALRM}) = sub { die "inactivity_timeout reached\n" };
4806 if ($CPAN::Config->{inactivity_timeout}) {
4808 alarm $CPAN::Config->{inactivity_timeout};
4809 local $SIG{CHLD}; # = sub { wait };
4810 if (defined($pid = fork)) {
4815 # note, this exec isn't necessary if
4816 # inactivity_timeout is 0. On the Mac I'd
4817 # suggest, we set it always to 0.
4821 $CPAN::Frontend->myprint("Cannot fork: $!");
4829 $CPAN::Frontend->myprint($@);
4830 $self->{writemakefile} = "NO $@";
4835 $ret = system($system);
4837 $self->{writemakefile} = "NO Makefile.PL returned status $ret";
4841 if (-f "Makefile" || -f "Build") {
4842 $self->{writemakefile} = "YES";
4843 delete $self->{make_clean}; # if cleaned before, enable next
4845 $self->{writemakefile} =
4846 qq{NO Makefile.PL refused to write a Makefile.};
4847 # It's probably worth it to record the reason, so let's retry
4849 # my $fh = IO::File->new("$system |"); # STDERR? STDIN?
4850 # $self->{writemakefile} .= <$fh>;
4854 delete $self->{force_update};
4857 if (my @prereq = $self->unsat_prereq){
4858 return 1 if $self->follow_prereqs(@prereq); # signal success to the queuerunner
4860 if ($self->{modulebuild}) {
4861 $system = "./Build $CPAN::Config->{mbuild_arg}";
4863 $system = join " ", _make_command(), $CPAN::Config->{make_arg};
4865 if (system($system) == 0) {
4866 $CPAN::Frontend->myprint(" $system -- OK\n");
4867 $self->{'make'} = CPAN::Distrostatus->new("YES");
4869 $self->{writemakefile} ||= "YES";
4870 $self->{'make'} = CPAN::Distrostatus->new("NO");
4871 $CPAN::Frontend->myprint(" $system -- NOT OK\n");
4876 return $CPAN::Config->{'make'} || $Config::Config{make} || 'make';
4879 sub follow_prereqs {
4881 my(@prereq) = grep {$_ ne "perl"} @_;
4882 return unless @prereq;
4884 $CPAN::Frontend->myprint("---- Unsatisfied dependencies detected ".
4885 "during [$id] -----\n");
4887 for my $p (@prereq) {
4888 $CPAN::Frontend->myprint(" $p\n");
4891 if ($CPAN::Config->{prerequisites_policy} eq "follow") {
4893 } elsif ($CPAN::Config->{prerequisites_policy} eq "ask") {
4894 require ExtUtils::MakeMaker;
4895 my $answer = ExtUtils::MakeMaker::prompt(
4896 "Shall I follow them and prepend them to the queue
4897 of modules we are processing right now?", "yes");
4898 $follow = $answer =~ /^\s*y/i;
4902 myprint(" Ignoring dependencies on modules @prereq\n");
4905 # color them as dirty
4906 for my $p (@prereq) {
4907 # warn "calling color_cmd_tmps(0,1)";
4908 CPAN::Shell->expandany($p)->color_cmd_tmps(0,1);
4910 CPAN::Queue->jumpqueue(@prereq,$id); # queue them and requeue yourself
4911 $self->{later} = "Delayed until after prerequisites";
4912 return 1; # signal success to the queuerunner
4916 #-> sub CPAN::Distribution::unsat_prereq ;
4919 my $prereq_pm = $self->prereq_pm or return;
4921 NEED: while (my($need_module, $need_version) = each %$prereq_pm) {
4922 my $nmo = $CPAN::META->instance("CPAN::Module",$need_module);
4923 # we were too demanding:
4924 next if $nmo->uptodate;
4926 # if they have not specified a version, we accept any installed one
4927 if (not defined $need_version or
4928 $need_version eq "0" or
4929 $need_version eq "undef") {
4930 next if defined $nmo->inst_file;
4933 # We only want to install prereqs if either they're not installed
4934 # or if the installed version is too old. We cannot omit this
4935 # check, because if 'force' is in effect, nobody else will check.
4936 if (defined $nmo->inst_file) {
4937 my(@all_requirements) = split /\s*,\s*/, $need_version;
4940 RQ: for my $rq (@all_requirements) {
4941 if ($rq =~ s|>=\s*||) {
4942 } elsif ($rq =~ s|>\s*||) {
4944 if (CPAN::Version->vgt($nmo->inst_version,$rq)){
4948 } elsif ($rq =~ s|!=\s*||) {
4950 if (CPAN::Version->vcmp($nmo->inst_version,$rq)){
4956 } elsif ($rq =~ m|<=?\s*|) {
4958 $CPAN::Frontend->mywarn("Downgrading not supported (rq[$rq])");
4962 if (! CPAN::Version->vgt($rq, $nmo->inst_version)){
4965 CPAN->debug(sprintf "id[%s]inst_file[%s]inst_version[%s]rq[%s]ok[%d]",
4969 CPAN::Version->readable($rq),
4973 next NEED if $ok == @all_requirements;
4976 if ($self->{sponsored_mods}{$need_module}++){
4977 # We have already sponsored it and for some reason it's still
4978 # not available. So we do nothing. Or what should we do?
4979 # if we push it again, we have a potential infinite loop
4982 push @need, $need_module;
4987 #-> sub CPAN::Distribution::read_yaml ;
4990 return $self->{yaml_content} if exists $self->{yaml_content};
4991 my $build_dir = $self->{build_dir};
4992 my $yaml = File::Spec->catfile($build_dir,"META.yml");
4993 return unless -f $yaml;
4994 if ($CPAN::META->has_inst("YAML")) {
4995 eval { $self->{yaml_content} = YAML::LoadFile($yaml); };
4997 $CPAN::Frontend->mywarn("Error while parsing META.yml: $@");
5001 return $self->{yaml_content};
5004 #-> sub CPAN::Distribution::prereq_pm ;
5007 return $self->{prereq_pm} if
5008 exists $self->{prereq_pm_detected} && $self->{prereq_pm_detected};
5009 return unless $self->{writemakefile} # no need to have succeeded
5010 # but we must have run it
5011 || $self->{mudulebuild};
5013 if (my $yaml = $self->read_yaml) {
5014 $req = $yaml->{requires};
5015 undef $req unless ref $req eq "HASH" && %$req;
5017 if ($yaml->{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) {
5018 my $eummv = do { local $^W = 0; $1+0; };
5019 if ($eummv < 6.2501) {
5020 # thanks to Slaven for digging that out: MM before
5021 # that could be wrong because it could reflect a
5028 while (my($k,$v) = each %{$req||{}}) {
5031 } elsif ($k =~ /[A-Za-z]/ &&
5033 $CPAN::META->exists("Module",$v)
5035 $CPAN::Frontend->mywarn("Suspicious key-value pair in META.yml's ".
5036 "requires hash: $k => $v; I'll take both ".
5037 "key and value as a module name\n");
5044 $req = $areq if $do_replace;
5047 delete $req->{perl};
5051 my $build_dir = $self->{build_dir} or die "Panic: no build_dir?";
5052 my $makefile = File::Spec->catfile($build_dir,"Makefile");
5056 $fh = FileHandle->new("<$makefile\0")) {
5059 last if /MakeMaker post_initialize section/;
5061 \s+PREREQ_PM\s+=>\s+(.+)
5064 # warn "Found prereq expr[$p]";
5066 # Regexp modified by A.Speer to remember actual version of file
5067 # PREREQ_PM hash key wants, then add to
5068 while ( $p =~ m/(?:\s)([\w\:]+)=>q\[(.*?)\],?/g ){
5069 # In case a prereq is mentioned twice, complain.
5070 if ( defined $req->{$1} ) {
5071 warn "Warning: PREREQ_PM mentions $1 more than once, ".
5072 "last mention wins";
5078 } elsif (-f "Build") {
5079 if ($CPAN::META->has_inst("Module::Build")) {
5080 $req = Module::Build->current->requires();
5084 $self->{prereq_pm_detected}++;
5085 return $self->{prereq_pm} = $req;
5088 #-> sub CPAN::Distribution::test ;
5093 delete $self->{force_update};
5096 # warn "XDEBUG: checking for notest: $self->{notest} $self";
5097 if ($self->{notest}) {
5098 $CPAN::Frontend->myprint("Skipping test because of notest pragma\n");
5102 my $make = $self->{modulebuild} ? "Build" : "make";
5103 $CPAN::Frontend->myprint("Running $make test\n");
5104 if (my @prereq = $self->unsat_prereq){
5105 return 1 if $self->follow_prereqs(@prereq); # signal success to the queuerunner
5109 exists $self->{make} or exists $self->{later} or push @e,
5110 "Make had some problems, maybe interrupted? Won't test";
5112 exists $self->{'make'} and
5113 $self->{'make'}->failed and
5114 push @e, "Can't test without successful make";
5116 exists $self->{build_dir} or push @e, "Has no own directory";
5117 $self->{badtestcnt} ||= 0;
5118 $self->{badtestcnt} > 0 and
5119 push @e, "Won't repeat unsuccessful test during this command";
5121 exists $self->{later} and length($self->{later}) and
5122 push @e, $self->{later};
5124 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
5126 chdir $self->{'build_dir'} or
5127 Carp::croak("Couldn't chdir to $self->{'build_dir'}");
5128 $self->debug("Changed directory to $self->{'build_dir'}")
5131 if ($^O eq 'MacOS') {
5132 Mac::BuildTools::make_test($self);
5136 local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
5138 : ($ENV{PERLLIB} || "");
5140 $CPAN::META->set_perl5lib;
5142 if ($self->{modulebuild}) {
5143 $system = "./Build test";
5145 $system = join " ", _make_command(), "test";
5147 if (system($system) == 0) {
5148 $CPAN::Frontend->myprint(" $system -- OK\n");
5149 $CPAN::META->is_tested($self->{'build_dir'});
5150 $self->{make_test} = CPAN::Distrostatus->new("YES");
5152 $self->{make_test} = CPAN::Distrostatus->new("NO");
5153 $self->{badtestcnt}++;
5154 $CPAN::Frontend->myprint(" $system -- NOT OK\n");
5158 #-> sub CPAN::Distribution::clean ;
5161 my $make = $self->{modulebuild} ? "Build" : "make";
5162 $CPAN::Frontend->myprint("Running $make clean\n");
5163 unless (exists $self->{build_dir}) {
5164 $CPAN::Frontend->mywarn("Distribution has no own directory, nothing to do.\n");
5169 exists $self->{make_clean} and $self->{make_clean} eq "YES" and
5170 push @e, "make clean already called once";
5171 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
5173 chdir $self->{'build_dir'} or
5174 Carp::croak("Couldn't chdir to $self->{'build_dir'}");
5175 $self->debug("Changed directory to $self->{'build_dir'}") if $CPAN::DEBUG;
5177 if ($^O eq 'MacOS') {
5178 Mac::BuildTools::make_clean($self);
5183 if ($self->{modulebuild}) {
5184 $system = "./Build clean";
5186 $system = join " ", _make_command(), "clean";
5188 if (system($system) == 0) {
5189 $CPAN::Frontend->myprint(" $system -- OK\n");
5193 # Jost Krieger pointed out that this "force" was wrong because
5194 # it has the effect that the next "install" on this distribution
5195 # will untar everything again. Instead we should bring the
5196 # object's state back to where it is after untarring.
5207 $self->{make_clean} = "YES";
5210 # Hmmm, what to do if make clean failed?
5212 $CPAN::Frontend->myprint(qq{ $system -- NOT OK
5214 make clean did not succeed, marking directory as unusable for further work.
5216 $self->force("make"); # so that this directory won't be used again
5221 #-> sub CPAN::Distribution::install ;
5226 delete $self->{force_update};
5229 my $make = $self->{modulebuild} ? "Build" : "make";
5230 $CPAN::Frontend->myprint("Running $make install\n");
5233 exists $self->{build_dir} or push @e, "Has no own directory";
5235 exists $self->{make} or exists $self->{later} or push @e,
5236 "Make had some problems, maybe interrupted? Won't install";
5238 exists $self->{'make'} and
5239 $self->{'make'}->failed and
5240 push @e, "make had returned bad status, install seems impossible";
5242 if (exists $self->{make_test} and
5243 $self->{make_test}->failed){
5244 if ($self->{force_update}) {
5245 $self->{make_test}->text("FAILED but failure ignored because ".
5246 "'force' in effect");
5248 push @e, "make test had returned bad status, ".
5249 "won't install without force"
5252 exists $self->{'install'} and push @e,
5253 $self->{'install'}->text eq "YES" ?
5254 "Already done" : "Already tried without success";
5256 exists $self->{later} and length($self->{later}) and
5257 push @e, $self->{later};
5259 $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
5261 chdir $self->{'build_dir'} or
5262 Carp::croak("Couldn't chdir to $self->{'build_dir'}");
5263 $self->debug("Changed directory to $self->{'build_dir'}")
5266 if ($^O eq 'MacOS') {
5267 Mac::BuildTools::make_install($self);
5272 if ($self->{modulebuild}) {
5273 my($mbuild_install_build_command) = $CPAN::Config->{'mbuild_install_build_command'} ||
5276 $mbuild_install_build_command,
5278 $CPAN::Config->{mbuild_install_arg},
5281 my($make_install_make_command) = $CPAN::Config->{'make_install_make_command'} ||
5284 $make_install_make_command,
5286 $CPAN::Config->{make_install_arg},
5290 my($stderr) = $^O =~ /Win/i ? "" : " 2>&1 ";
5291 my($pipe) = FileHandle->new("$system $stderr |");
5294 $CPAN::Frontend->myprint($_);
5299 $CPAN::Frontend->myprint(" $system -- OK\n");
5300 $CPAN::META->is_installed($self->{'build_dir'});
5301 return $self->{'install'} = CPAN::Distrostatus->new("YES");
5303 $self->{'install'} = CPAN::Distrostatus->new("NO");
5304 $CPAN::Frontend->myprint(" $system -- NOT OK\n");
5306 $makeout =~ /permission/s
5309 ! $CPAN::Config->{make_install_make_command}
5310 || $CPAN::Config->{make_install_make_command} eq $CPAN::Config->{make}
5313 $CPAN::Frontend->myprint(
5315 qq{ You may have to su }.
5316 qq{to root to install the package\n}.
5317 qq{ (Or you may want to run something like\n}.
5318 qq{ o conf make_install_make_command 'sudo make'\n}.
5319 qq{ to raise your permissions.}
5323 delete $self->{force_update};
5326 #-> sub CPAN::Distribution::dir ;
5328 shift->{'build_dir'};
5331 #-> sub CPAN::Distribution::perldoc ;
5335 my($dist) = $self->id;
5336 my $package = $self->called_for;
5338 $self->_display_url( $CPAN::Defaultdocs . $package );
5341 #-> sub CPAN::Distribution::_check_binary ;
5343 my ($dist,$shell,$binary) = @_;
5344 my ($pid,$readme,$out);
5346 $CPAN::Frontend->myprint(qq{ + _check_binary($binary)\n})
5349 $pid = open $readme, "which $binary|"
5350 or $CPAN::Frontend->mydie(qq{Could not fork 'which $binary': $!});
5354 close $readme or die "Could not run 'which $binary': $!";
5356 $CPAN::Frontend->myprint(qq{ + $out \n})
5357 if $CPAN::DEBUG && $out;
5362 #-> sub CPAN::Distribution::_display_url ;
5364 my($self,$url) = @_;
5365 my($res,$saved_file,$pid,$readme,$out);
5367 $CPAN::Frontend->myprint(qq{ + _display_url($url)\n})
5370 # should we define it in the config instead?
5371 my $html_converter = "html2text";
5373 my $web_browser = $CPAN::Config->{'lynx'} || undef;
5374 my $web_browser_out = $web_browser
5375 ? CPAN::Distribution->_check_binary($self,$web_browser)
5378 my ($tmpout,$tmperr);
5379 if (not $web_browser_out) {
5380 # web browser not found, let's try text only
5381 my $html_converter_out =
5382 CPAN::Distribution->_check_binary($self,$html_converter);
5384 if ($html_converter_out ) {
5385 # html2text found, run it
5386 $saved_file = CPAN::Distribution->_getsave_url( $self, $url );
5387 $CPAN::Frontend->myprint(qq{ERROR: problems while getting $url, $!\n})
5388 unless defined($saved_file);
5390 $pid = open $readme, "$html_converter $saved_file |"
5391 or $CPAN::Frontend->mydie(qq{
5392 Could not fork '$html_converter $saved_file': $!});
5393 my $fh = File::Temp->new(
5394 template => 'cpan_htmlconvert_XXXX',
5402 or $CPAN::Frontend->mydie(qq{Could not run '$html_converter $saved_file': $!});
5403 my $tmpin = $fh->filename;
5404 $CPAN::Frontend->myprint(sprintf(qq{
5406 saved output to %s\n},
5411 close $fh; undef $fh;
5413 or $CPAN::Frontend->mydie(qq{Could not open "$tmpin": $!});
5414 my $fh_pager = FileHandle->new;
5415 local($SIG{PIPE}) = "IGNORE";
5416 $fh_pager->open("|$CPAN::Config->{'pager'}")
5417 or $CPAN::Frontend->mydie(qq{
5418 Could not open pager $CPAN::Config->{'pager'}: $!});
5419 $CPAN::Frontend->myprint(qq{
5422 with pager "$CPAN::Config->{'pager'}"
5425 $fh_pager->print(<$fh>);
5428 # coldn't find the web browser or html converter
5429 $CPAN::Frontend->myprint(qq{
5430 You need to install lynx or $html_converter to use this feature.});
5433 # web browser found, run the action
5434 my $browser = $CPAN::Config->{'lynx'};
5435 $CPAN::Frontend->myprint(qq{system[$browser $url]})
5437 $CPAN::Frontend->myprint(qq{
5440 with browser $browser
5443 system("$browser $url");
5444 if ($saved_file) { 1 while unlink($saved_file) }
5448 #-> sub CPAN::Distribution::_getsave_url ;
5450 my($dist, $shell, $url) = @_;
5452 $CPAN::Frontend->myprint(qq{ + _getsave_url($url)\n})
5455 my $fh = File::Temp->new(
5456 template => "cpan_getsave_url_XXXX",
5460 my $tmpin = $fh->filename;
5461 if ($CPAN::META->has_usable('LWP')) {
5462 $CPAN::Frontend->myprint("Fetching with LWP:
5466 CPAN::LWP::UserAgent->config;
5467 eval { $Ua = CPAN::LWP::UserAgent->new; };
5469 $CPAN::Frontend->mywarn("ERROR: CPAN::LWP::UserAgent->new dies with $@\n");
5473 $Ua->proxy('http', $var)
5474 if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy};
5476 if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy};
5479 my $req = HTTP::Request->new(GET => $url);
5480 $req->header('Accept' => 'text/html');
5481 my $res = $Ua->request($req);
5482 if ($res->is_success) {
5483 $CPAN::Frontend->myprint(" + request successful.\n")
5485 print $fh $res->content;
5487 $CPAN::Frontend->myprint(qq{ + saved content to $tmpin \n})
5491 $CPAN::Frontend->myprint(sprintf(
5492 "LWP failed with code[%s], message[%s]\n",
5499 $CPAN::Frontend->myprint("LWP not available\n");
5504 package CPAN::Bundle;
5509 $CPAN::Frontend->myprint($self->as_string);
5514 delete $self->{later};
5515 for my $c ( $self->contains ) {
5516 my $obj = CPAN::Shell->expandany($c) or next;
5521 # mark as dirty/clean
5522 #-> sub CPAN::Bundle::color_cmd_tmps ;
5523 sub color_cmd_tmps {
5525 my($depth) = shift || 0;
5526 my($color) = shift || 0;
5527 my($ancestors) = shift || [];
5528 # a module needs to recurse to its cpan_file, a distribution needs
5529 # to recurse into its prereq_pms, a bundle needs to recurse into its modules
5531 return if exists $self->{incommandcolor}
5532 && $self->{incommandcolor}==$color;
5534 $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
5536 # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
5538 for my $c ( $self->contains ) {
5539 my $obj = CPAN::Shell->expandany($c) or next;
5540 CPAN->debug("c[$c]obj[$obj]") if $CPAN::DEBUG;
5541 $obj->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
5544 delete $self->{badtestcnt};
5546 $self->{incommandcolor} = $color;
5549 #-> sub CPAN::Bundle::as_string ;
5553 # following line must be "=", not "||=" because we have a moving target
5554 $self->{INST_VERSION} = $self->inst_version;
5555 return $self->SUPER::as_string;
5558 #-> sub CPAN::Bundle::contains ;
5561 my($inst_file) = $self->inst_file || "";
5562 my($id) = $self->id;
5563 $self->debug("inst_file[$inst_file]id[$id]") if $CPAN::DEBUG;
5564 unless ($inst_file) {
5565 # Try to get at it in the cpan directory
5566 $self->debug("no inst_file") if $CPAN::DEBUG;
5568 $CPAN::Frontend->mydie("I don't know a bundle with ID $id\n") unless
5569 $cpan_file = $self->cpan_file;
5570 if ($cpan_file eq "N/A") {
5571 $CPAN::Frontend->mydie("Bundle $id not found on disk and not on CPAN.
5572 Maybe stale symlink? Maybe removed during session? Giving up.\n");
5574 my $dist = $CPAN::META->instance('CPAN::Distribution',
5577 $self->debug($dist->as_string) if $CPAN::DEBUG;
5578 my($todir) = $CPAN::Config->{'cpan_home'};
5579 my(@me,$from,$to,$me);
5580 @me = split /::/, $self->id;
5582 $me = File::Spec->catfile(@me);
5583 $from = $self->find_bundle_file($dist->{'build_dir'},$me);
5584 $to = File::Spec->catfile($todir,$me);
5585 File::Path::mkpath(File::Basename::dirname($to));
5586 File::Copy::copy($from, $to)
5587 or Carp::confess("Couldn't copy $from to $to: $!");
5591 my $fh = FileHandle->new;
5593 open($fh,$inst_file) or die "Could not open '$inst_file': $!";
5595 $self->debug("inst_file[$inst_file]") if $CPAN::DEBUG;
5597 $in_cont = m/^=(?!head1\s+CONTENTS)/ ? 0 :
5598 m/^=head1\s+CONTENTS/ ? 1 : $in_cont;
5599 next unless $in_cont;
5604 push @result, (split " ", $_, 2)[0];
5607 delete $self->{STATUS};
5608 $self->{CONTAINS} = \@result;
5609 $self->debug("CONTAINS[@result]") if $CPAN::DEBUG;
5611 $CPAN::Frontend->mywarn(qq{
5612 The bundle file "$inst_file" may be a broken
5613 bundlefile. It seems not to contain any bundle definition.
5614 Please check the file and if it is bogus, please delete it.
5615 Sorry for the inconvenience.
5621 #-> sub CPAN::Bundle::find_bundle_file
5622 sub find_bundle_file {
5623 my($self,$where,$what) = @_;
5624 $self->debug("where[$where]what[$what]") if $CPAN::DEBUG;
5625 ### The following two lines let CPAN.pm become Bundle/CPAN.pm :-(
5626 ### my $bu = File::Spec->catfile($where,$what);
5627 ### return $bu if -f $bu;
5628 my $manifest = File::Spec->catfile($where,"MANIFEST");
5629 unless (-f $manifest) {
5630 require ExtUtils::Manifest;
5631 my $cwd = CPAN::anycwd();
5632 chdir $where or $CPAN::Frontend->mydie(qq{Could not chdir to "$where": $!});
5633 ExtUtils::Manifest::mkmanifest();
5634 chdir $cwd or $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd": $!});
5636 my $fh = FileHandle->new($manifest)
5637 or Carp::croak("Couldn't open $manifest: $!");
5640 if ($^O eq 'MacOS') {
5643 $what2 =~ s/:Bundle://;
5646 $what2 =~ s|Bundle[/\\]||;
5651 my($file) = /(\S+)/;
5652 if ($file =~ m|\Q$what\E$|) {
5654 # return File::Spec->catfile($where,$bu); # bad
5657 # retry if she managed to
5658 # have no Bundle directory
5659 $bu = $file if $file =~ m|\Q$what2\E$|;
5661 $bu =~ tr|/|:| if $^O eq 'MacOS';
5662 return File::Spec->catfile($where, $bu) if $bu;
5663 Carp::croak("Couldn't find a Bundle file in $where");
5666 # needs to work quite differently from Module::inst_file because of
5667 # cpan_home/Bundle/ directory and the possibility that we have
5668 # shadowing effect. As it makes no sense to take the first in @INC for
5669 # Bundles, we parse them all for $VERSION and take the newest.
5671 #-> sub CPAN::Bundle::inst_file ;
5676 @me = split /::/, $self->id;
5679 foreach $incdir ($CPAN::Config->{'cpan_home'},@INC) {
5680 my $bfile = File::Spec->catfile($incdir, @me);
5681 CPAN->debug("bfile[$bfile]") if $CPAN::DEBUG;
5682 next unless -f $bfile;
5683 my $foundv = MM->parse_version($bfile);
5684 if (!$bestv || CPAN::Version->vgt($foundv,$bestv)) {
5685 $self->{INST_FILE} = $bfile;
5686 $self->{INST_VERSION} = $bestv = $foundv;
5692 #-> sub CPAN::Bundle::inst_version ;
5695 $self->inst_file; # finds INST_VERSION as side effect
5696 $self->{INST_VERSION};
5699 #-> sub CPAN::Bundle::rematein ;
5701 my($self,$meth) = @_;
5702 $self->debug("self[$self] meth[$meth]") if $CPAN::DEBUG;
5703 my($id) = $self->id;
5704 Carp::croak "Can't $meth $id, don't have an associated bundle file. :-(\n"
5705 unless $self->inst_file || $self->cpan_file;
5707 for $s ($self->contains) {
5708 my($type) = $s =~ m|/| ? 'CPAN::Distribution' :
5709 $s =~ m|^Bundle::| ? 'CPAN::Bundle' : 'CPAN::Module';
5710 if ($type eq 'CPAN::Distribution') {
5711 $CPAN::Frontend->mywarn(qq{
5712 The Bundle }.$self->id.qq{ contains
5713 explicitly a file $s.
5717 # possibly noisy action:
5718 $self->debug("type[$type] s[$s]") if $CPAN::DEBUG;
5719 my $obj = $CPAN::META->instance($type,$s);
5721 if ($obj->isa('CPAN::Bundle')
5723 exists $obj->{install_failed}
5725 ref($obj->{install_failed}) eq "HASH"
5727 for (keys %{$obj->{install_failed}}) {
5728 $self->{install_failed}{$_} = undef; # propagate faiure up
5731 $fail{$s} = 1; # the bundle itself may have succeeded but
5736 $success = $obj->can("uptodate") ? $obj->uptodate : 0;
5737 $success ||= $obj->{'install'} && $obj->{'install'} eq "YES";
5739 delete $self->{install_failed}{$s};
5746 # recap with less noise
5747 if ( $meth eq "install" ) {
5750 my $raw = sprintf(qq{Bundle summary:
5751 The following items in bundle %s had installation problems:},
5754 $CPAN::Frontend->myprint(Text::Wrap::fill("","",$raw));
5755 $CPAN::Frontend->myprint("\n");
5758 for $s ($self->contains) {
5760 $paragraph .= "$s ";
5761 $self->{install_failed}{$s} = undef;
5762 $reported{$s} = undef;
5765 my $report_propagated;
5766 for $s (sort keys %{$self->{install_failed}}) {
5767 next if exists $reported{$s};
5768 $paragraph .= "and the following items had problems
5769 during recursive bundle calls: " unless $report_propagated++;
5770 $paragraph .= "$s ";
5772 $CPAN::Frontend->myprint(Text::Wrap::fill(" "," ",$paragraph));
5773 $CPAN::Frontend->myprint("\n");
5775 $self->{'install'} = 'YES';
5780 #sub CPAN::Bundle::xs_file
5782 # If a bundle contains another that contains an xs_file we have
5783 # here, we just don't bother I suppose
5787 #-> sub CPAN::Bundle::force ;
5788 sub force { shift->rematein('force',@_); }
5789 #-> sub CPAN::Bundle::notest ;
5790 sub notest { shift->rematein('notest',@_); }
5791 #-> sub CPAN::Bundle::get ;
5792 sub get { shift->rematein('get',@_); }
5793 #-> sub CPAN::Bundle::make ;
5794 sub make { shift->rematein('make',@_); }
5795 #-> sub CPAN::Bundle::test ;
5798 $self->{badtestcnt} ||= 0;
5799 $self->rematein('test',@_);
5801 #-> sub CPAN::Bundle::install ;
5804 $self->rematein('install',@_);
5806 #-> sub CPAN::Bundle::clean ;
5807 sub clean { shift->rematein('clean',@_); }
5809 #-> sub CPAN::Bundle::uptodate ;
5812 return 0 unless $self->SUPER::uptodate; # we mut have the current Bundle def
5814 foreach $c ($self->contains) {
5815 my $obj = CPAN::Shell->expandany($c);
5816 return 0 unless $obj->uptodate;
5821 #-> sub CPAN::Bundle::readme ;
5824 my($file) = $self->cpan_file or $CPAN::Frontend->myprint(qq{
5825 No File found for bundle } . $self->id . qq{\n}), return;
5826 $self->debug("self[$self] file[$file]") if $CPAN::DEBUG;
5827 $CPAN::META->instance('CPAN::Distribution',$file)->readme;
5830 package CPAN::Module;
5834 # sub CPAN::Module::userid
5839 return $ro->{userid} || $ro->{CPAN_USERID};
5841 # sub CPAN::Module::description
5844 my $ro = $self->ro or return "";
5850 delete $self->{later};
5851 if ( my $dist = CPAN::Shell->expand("Distribution", $self->cpan_file) ) {
5856 # mark as dirty/clean
5857 #-> sub CPAN::Module::color_cmd_tmps ;
5858 sub color_cmd_tmps {
5860 my($depth) = shift || 0;
5861 my($color) = shift || 0;
5862 my($ancestors) = shift || [];
5863 # a module needs to recurse to its cpan_file
5865 return if exists $self->{incommandcolor}
5866 && $self->{incommandcolor}==$color;
5867 return if $depth>=1 && $self->uptodate;
5869 $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
5871 # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
5873 if ( my $dist = CPAN::Shell->expand("Distribution", $self->cpan_file) ) {
5874 $dist->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
5877 delete $self->{badtestcnt};
5879 $self->{incommandcolor} = $color;
5882 #-> sub CPAN::Module::as_glimpse ;
5886 my $class = ref($self);
5887 $class =~ s/^CPAN:://;
5891 $CPAN::Shell::COLOR_REGISTERED
5893 $CPAN::META->has_inst("Term::ANSIColor")
5897 $color_on = Term::ANSIColor::color("green");
5898 $color_off = Term::ANSIColor::color("reset");
5900 push @m, sprintf("%-15s %s%-15s%s (%s)\n",
5909 #-> sub CPAN::Module::as_string ;
5913 CPAN->debug("$self entering as_string") if $CPAN::DEBUG;
5914 my $class = ref($self);
5915 $class =~ s/^CPAN:://;
5917 push @m, $class, " id = $self->{ID}\n";
5918 my $sprintf = " %-12s %s\n";
5919 push @m, sprintf($sprintf, 'DESCRIPTION', $self->description)
5920 if $self->description;
5921 my $sprintf2 = " %-12s %s (%s)\n";
5923 $userid = $self->userid;
5926 if ($author = CPAN::Shell->expand('Author',$userid)) {
5929 if ($m = $author->email) {
5936 $author->fullname . $email
5940 push @m, sprintf($sprintf, 'CPAN_VERSION', $self->cpan_version)
5941 if $self->cpan_version;
5942 if (my $cpan_file = $self->cpan_file){
5943 push @m, sprintf($sprintf, 'CPAN_FILE', $cpan_file);
5944 if (my $dist = CPAN::Shell->expand("Distribution",$cpan_file)) {
5945 my $upload_date = $dist->upload_date;
5947 push @m, sprintf($sprintf, 'UPLOAD_DATE', $upload_date);
5951 my $sprintf3 = " %-12s %1s%1s%1s%1s (%s,%s,%s,%s)\n";
5952 my(%statd,%stats,%statl,%stati);
5953 @statd{qw,? i c a b R M S,} = qw,unknown idea
5954 pre-alpha alpha beta released mature standard,;
5955 @stats{qw,? m d u n a,} = qw,unknown mailing-list
5956 developer comp.lang.perl.* none abandoned,;
5957 @statl{qw,? p c + o h,} = qw,unknown perl C C++ other hybrid,;
5958 @stati{qw,? f r O h,} = qw,unknown functions
5959 references+ties object-oriented hybrid,;
5960 $statd{' '} = 'unknown';
5961 $stats{' '} = 'unknown';
5962 $statl{' '} = 'unknown';
5963 $stati{' '} = 'unknown';
5972 $statd{$ro->{statd}},
5973 $stats{$ro->{stats}},
5974 $statl{$ro->{statl}},
5975 $stati{$ro->{stati}}
5976 ) if $ro && $ro->{statd};
5977 my $local_file = $self->inst_file;
5978 unless ($self->{MANPAGE}) {
5980 $self->{MANPAGE} = $self->manpage_headline($local_file);
5982 # If we have already untarred it, we should look there
5983 my $dist = $CPAN::META->instance('CPAN::Distribution',
5985 # warn "dist[$dist]";
5986 # mff=manifest file; mfh=manifest handle
5991 (-f ($mff = File::Spec->catfile($dist->{build_dir}, "MANIFEST")))
5993 $mfh = FileHandle->new($mff)
5995 CPAN->debug("mff[$mff]") if $CPAN::DEBUG;
5996 my $lfre = $self->id; # local file RE
5999 my($lfl); # local file file
6001 my(@mflines) = <$mfh>;
6006 while (length($lfre)>5 and !$lfl) {
6007 ($lfl) = grep /$lfre/, @mflines;
6008 CPAN->debug("lfl[$lfl]lfre[$lfre]") if $CPAN::DEBUG;
6011 $lfl =~ s/\s.*//; # remove comments
6012 $lfl =~ s/\s+//g; # chomp would maybe be too system-specific
6013 my $lfl_abs = File::Spec->catfile($dist->{build_dir},$lfl);
6014 # warn "lfl_abs[$lfl_abs]";
6016 $self->{MANPAGE} = $self->manpage_headline($lfl_abs);
6022 for $item (qw/MANPAGE/) {
6023 push @m, sprintf($sprintf, $item, $self->{$item})
6024 if exists $self->{$item};
6026 for $item (qw/CONTAINS/) {
6027 push @m, sprintf($sprintf, $item, join(" ",@{$self->{$item}}))
6028 if exists $self->{$item} && @{$self->{$item}};
6030 push @m, sprintf($sprintf, 'INST_FILE',
6031 $local_file || "(not installed)");
6032 push @m, sprintf($sprintf, 'INST_VERSION',
6033 $self->inst_version) if $local_file;
6037 sub manpage_headline {
6038 my($self,$local_file) = @_;
6039 my(@local_file) = $local_file;
6040 $local_file =~ s/\.pm(?!\n)\Z/.pod/;
6041 push @local_file, $local_file;
6043 for $locf (@local_file) {
6044 next unless -f $locf;
6045 my $fh = FileHandle->new($locf)
6046 or $Carp::Frontend->mydie("Couldn't open $locf: $!");
6050 $inpod = m/^=(?!head1\s+NAME\s*$)/ ? 0 :
6051 m/^=head1\s+NAME\s*$/ ? 1 : $inpod;
6064 #-> sub CPAN::Module::cpan_file ;
6065 # Note: also inherited by CPAN::Bundle
6068 CPAN->debug(sprintf "id[%s]", $self->id) if $CPAN::DEBUG;
6069 unless ($self->ro) {
6070 CPAN::Index->reload;
6073 if ($ro && defined $ro->{CPAN_FILE}){
6074 return $ro->{CPAN_FILE};
6076 my $userid = $self->userid;
6078 if ($CPAN::META->exists("CPAN::Author",$userid)) {
6079 my $author = $CPAN::META->instance("CPAN::Author",
6081 my $fullname = $author->fullname;
6082 my $email = $author->email;
6083 unless (defined $fullname && defined $email) {
6084 return sprintf("Contact Author %s",
6088 return "Contact Author $fullname <$email>";
6090 return "Contact Author $userid (Email address not available)";
6098 #-> sub CPAN::Module::cpan_version ;
6104 # Can happen with modules that are not on CPAN
6107 $ro->{CPAN_VERSION} = 'undef'
6108 unless defined $ro->{CPAN_VERSION};
6109 $ro->{CPAN_VERSION};
6112 #-> sub CPAN::Module::force ;
6115 $self->{'force_update'}++;
6120 # warn "XDEBUG: set notest for Module";
6121 $self->{'notest'}++;
6124 #-> sub CPAN::Module::rematein ;
6126 my($self,$meth) = @_;
6127 $CPAN::Frontend->myprint(sprintf("Running %s for module %s\n",
6130 my $cpan_file = $self->cpan_file;
6131 if ($cpan_file eq "N/A" || $cpan_file =~ /^Contact Author/){
6132 $CPAN::Frontend->mywarn(sprintf qq{
6133 The module %s isn\'t available on CPAN.
6135 Either the module has not yet been uploaded to CPAN, or it is
6136 temporary unavailable. Please contact the author to find out
6137 more about the status. Try 'i %s'.
6144 my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
6145 $pack->called_for($self->id);
6146 $pack->force($meth) if exists $self->{'force_update'};
6147 $pack->notest($meth) if exists $self->{'notest'};
6152 $pack->unforce if $pack->can("unforce") && exists $self->{'force_update'};
6153 $pack->unnotest if $pack->can("unnotest") && exists $self->{'notest'};
6154 delete $self->{'force_update'};
6155 delete $self->{'notest'};
6161 #-> sub CPAN::Module::perldoc ;
6162 sub perldoc { shift->rematein('perldoc') }
6163 #-> sub CPAN::Module::readme ;
6164 sub readme { shift->rematein('readme') }
6165 #-> sub CPAN::Module::look ;
6166 sub look { shift->rematein('look') }
6167 #-> sub CPAN::Module::cvs_import ;
6168 sub cvs_import { shift->rematein('cvs_import') }
6169 #-> sub CPAN::Module::get ;
6170 sub get { shift->rematein('get',@_) }
6171 #-> sub CPAN::Module::make ;
6172 sub make { shift->rematein('make') }
6173 #-> sub CPAN::Module::test ;
6176 $self->{badtestcnt} ||= 0;
6177 $self->rematein('test',@_);
6179 #-> sub CPAN::Module::uptodate ;
6182 my($latest) = $self->cpan_version;
6184 my($inst_file) = $self->inst_file;
6186 if (defined $inst_file) {
6187 $have = $self->inst_version;
6192 ! CPAN::Version->vgt($latest, $have)
6194 CPAN->debug("returning uptodate. inst_file[$inst_file] ".
6195 "latest[$latest] have[$have]") if $CPAN::DEBUG;
6200 #-> sub CPAN::Module::install ;
6206 not exists $self->{'force_update'}
6208 $CPAN::Frontend->myprint(sprintf("%s is up to date (%s).\n",
6210 $self->inst_version,
6216 if ($ro && $ro->{stats} && $ro->{stats} eq "a") {
6217 $CPAN::Frontend->mywarn(qq{
6218 \n\n\n ***WARNING***
6219 The module $self->{ID} has no active maintainer.\n\n\n
6223 $self->rematein('install') if $doit;
6225 #-> sub CPAN::Module::clean ;
6226 sub clean { shift->rematein('clean') }
6228 #-> sub CPAN::Module::inst_file ;
6232 @packpath = split /::/, $self->{ID};
6233 $packpath[-1] .= ".pm";
6234 foreach $dir (@INC) {
6235 my $pmfile = File::Spec->catfile($dir,@packpath);
6243 #-> sub CPAN::Module::xs_file ;
6247 @packpath = split /::/, $self->{ID};
6248 push @packpath, $packpath[-1];
6249 $packpath[-1] .= "." . $Config::Config{'dlext'};
6250 foreach $dir (@INC) {
6251 my $xsfile = File::Spec->catfile($dir,'auto',@packpath);
6259 #-> sub CPAN::Module::inst_version ;
6262 my $parsefile = $self->inst_file or return;
6263 local($^W) = 0 if $] < 5.00303 && $ExtUtils::MakeMaker::VERSION < 5.38;
6266 # there was a bug in 5.6.0 that let lots of unini warnings out of
6267 # parse_version. Fixed shortly after 5.6.0 by PMQS. We can remove
6268 # the following workaround after 5.6.1 is out.
6269 local($SIG{__WARN__}) = sub { my $w = shift;
6270 return if $w =~ /uninitialized/i;
6274 $have = MM->parse_version($parsefile) || "undef";
6275 $have =~ s/^ //; # since the %vd hack these two lines here are needed
6276 $have =~ s/ $//; # trailing whitespace happens all the time
6278 # My thoughts about why %vd processing should happen here
6280 # Alt1 maintain it as string with leading v:
6281 # read index files do nothing
6282 # compare it use utility for compare
6283 # print it do nothing
6285 # Alt2 maintain it as what it is
6286 # read index files convert
6287 # compare it use utility because there's still a ">" vs "gt" issue
6288 # print it use CPAN::Version for print
6290 # Seems cleaner to hold it in memory as a string starting with a "v"
6292 # If the author of this module made a mistake and wrote a quoted
6293 # "v1.13" instead of v1.13, we simply leave it at that with the
6294 # effect that *we* will treat it like a v-tring while the rest of
6295 # perl won't. Seems sensible when we consider that any action we
6296 # could take now would just add complexity.
6298 $have = CPAN::Version->readable($have);
6300 $have =~ s/\s*//g; # stringify to float around floating point issues
6301 $have; # no stringify needed, \s* above matches always
6313 CPAN - query, download and build perl modules from CPAN sites
6319 perl -MCPAN -e shell;
6325 autobundle, clean, install, make, recompile, test
6329 This module will eventually be replaced by CPANPLUS. CPANPLUS is kind
6330 of a modern rewrite from ground up with greater extensibility and more
6331 features but no full compatibility. If you're new to CPAN.pm, you
6332 probably should investigate if CPANPLUS is the better choice for you.
6333 If you're already used to CPAN.pm you're welcome to continue using it,
6334 if you accept that its development is mostly (though not completely)
6339 The CPAN module is designed to automate the make and install of perl
6340 modules and extensions. It includes some primitive searching capabilities and
6341 knows how to use Net::FTP or LWP (or lynx or an external ftp client)
6342 to fetch the raw data from the net.
6344 Modules are fetched from one or more of the mirrored CPAN
6345 (Comprehensive Perl Archive Network) sites and unpacked in a dedicated
6348 The CPAN module also supports the concept of named and versioned
6349 I<bundles> of modules. Bundles simplify the handling of sets of
6350 related modules. See Bundles below.
6352 The package contains a session manager and a cache manager. There is
6353 no status retained between sessions. The session manager keeps track
6354 of what has been fetched, built and installed in the current
6355 session. The cache manager keeps track of the disk space occupied by
6356 the make processes and deletes excess space according to a simple FIFO
6359 For extended searching capabilities there's a plugin for CPAN available,
6360 L<C<CPAN::WAIT>|CPAN::WAIT>. C<CPAN::WAIT> is a full-text search engine
6361 that indexes all documents available in CPAN authors directories. If
6362 C<CPAN::WAIT> is installed on your system, the interactive shell of
6363 CPAN.pm will enable the C<wq>, C<wr>, C<wd>, C<wl>, and C<wh> commands
6364 which send queries to the WAIT server that has been configured for your
6367 All other methods provided are accessible in a programmer style and in an
6368 interactive shell style.
6370 =head2 Interactive Mode
6372 The interactive mode is entered by running
6374 perl -MCPAN -e shell
6376 which puts you into a readline interface. You will have the most fun if
6377 you install Term::ReadKey and Term::ReadLine to enjoy both history and
6380 Once you are on the command line, type 'h' and the rest should be
6383 The function call C<shell> takes two optional arguments, one is the
6384 prompt, the second is the default initial command line (the latter
6385 only works if a real ReadLine interface module is installed).
6387 The most common uses of the interactive modes are
6391 =item Searching for authors, bundles, distribution files and modules
6393 There are corresponding one-letter commands C<a>, C<b>, C<d>, and C<m>
6394 for each of the four categories and another, C<i> for any of the
6395 mentioned four. Each of the four entities is implemented as a class
6396 with slightly differing methods for displaying an object.
6398 Arguments you pass to these commands are either strings exactly matching
6399 the identification string of an object or regular expressions that are
6400 then matched case-insensitively against various attributes of the
6401 objects. The parser recognizes a regular expression only if you
6402 enclose it between two slashes.
6404 The principle is that the number of found objects influences how an
6405 item is displayed. If the search finds one item, the result is
6406 displayed with the rather verbose method C<as_string>, but if we find
6407 more than one, we display each object with the terse method
6410 =item make, test, install, clean modules or distributions
6412 These commands take any number of arguments and investigate what is
6413 necessary to perform the action. If the argument is a distribution
6414 file name (recognized by embedded slashes), it is processed. If it is
6415 a module, CPAN determines the distribution file in which this module
6416 is included and processes that, following any dependencies named in
6417 the module's META.yml or Makefile.PL (this behavior is controlled by
6418 I<prerequisites_policy>.)
6420 Any C<make> or C<test> are run unconditionally. An
6422 install <distribution_file>
6424 also is run unconditionally. But for
6428 CPAN checks if an install is actually needed for it and prints
6429 I<module up to date> in the case that the distribution file containing
6430 the module doesn't need to be updated.
6432 CPAN also keeps track of what it has done within the current session
6433 and doesn't try to build a package a second time regardless if it
6434 succeeded or not. The C<force> pragma may precede another command
6435 (currently: C<make>, C<test>, or C<install>) and executes the
6436 command from scratch.
6440 cpan> install OpenGL
6441 OpenGL is up to date.
6442 cpan> force install OpenGL
6445 OpenGL-0.4/COPYRIGHT
6448 The C<notest> pragma may be set to skip the test part in the build
6453 cpan> notest install Tk
6455 A C<clean> command results in a
6459 being executed within the distribution file's working directory.
6461 =item get, readme, perldoc, look module or distribution
6463 C<get> downloads a distribution file without further action. C<readme>
6464 displays the README file of the associated distribution. C<Look> gets
6465 and untars (if not yet done) the distribution file, changes to the
6466 appropriate directory and opens a subshell process in that directory.
6467 C<perldoc> displays the pod documentation of the module in html or
6472 =item ls globbing_expresion
6474 The first form lists all distribution files in and below an author's
6475 CPAN directory as they are stored in the CHECKUMS files distrbute on
6478 The second form allows to limit or expand the output with shell
6479 globbing as in the following examples:
6485 The last example is very slow and outputs extra progress indicators
6486 that break the alignment of the result.
6490 The C<failed> command reports all distributions that failed on one of
6491 C<make>, C<test> or C<install> for some reason in the currently
6492 running shell session.
6496 CPAN.pm installs signal handlers for SIGINT and SIGTERM. While you are
6497 in the cpan-shell it is intended that you can press C<^C> anytime and
6498 return to the cpan-shell prompt. A SIGTERM will cause the cpan-shell
6499 to clean up and leave the shell loop. You can emulate the effect of a
6500 SIGTERM by sending two consecutive SIGINTs, which usually means by
6501 pressing C<^C> twice.
6503 CPAN.pm ignores a SIGPIPE. If the user sets inactivity_timeout, a
6504 SIGALRM is used during the run of the C<perl Makefile.PL> or C<perl
6505 Build.PL> subprocess.
6511 The commands that are available in the shell interface are methods in
6512 the package CPAN::Shell. If you enter the shell command, all your
6513 input is split by the Text::ParseWords::shellwords() routine which
6514 acts like most shells do. The first word is being interpreted as the
6515 method to be called and the rest of the words are treated as arguments
6516 to this method. Continuation lines are supported if a line ends with a
6521 C<autobundle> writes a bundle file into the
6522 C<$CPAN::Config-E<gt>{cpan_home}/Bundle> directory. The file contains
6523 a list of all modules that are both available from CPAN and currently
6524 installed within @INC. The name of the bundle file is based on the
6525 current date and a counter.
6529 recompile() is a very special command in that it takes no argument and
6530 runs the make/test/install cycle with brute force over all installed
6531 dynamically loadable extensions (aka XS modules) with 'force' in
6532 effect. The primary purpose of this command is to finish a network
6533 installation. Imagine, you have a common source tree for two different
6534 architectures. You decide to do a completely independent fresh
6535 installation. You start on one architecture with the help of a Bundle
6536 file produced earlier. CPAN installs the whole Bundle for you, but
6537 when you try to repeat the job on the second architecture, CPAN
6538 responds with a C<"Foo up to date"> message for all modules. So you
6539 invoke CPAN's recompile on the second architecture and you're done.
6541 Another popular use for C<recompile> is to act as a rescue in case your
6542 perl breaks binary compatibility. If one of the modules that CPAN uses
6543 is in turn depending on binary compatibility (so you cannot run CPAN
6544 commands), then you should try the CPAN::Nox module for recovery.
6546 =head2 The four C<CPAN::*> Classes: Author, Bundle, Module, Distribution
6548 Although it may be considered internal, the class hierarchy does matter
6549 for both users and programmer. CPAN.pm deals with above mentioned four
6550 classes, and all those classes share a set of methods. A classical
6551 single polymorphism is in effect. A metaclass object registers all
6552 objects of all kinds and indexes them with a string. The strings
6553 referencing objects have a separated namespace (well, not completely
6558 words containing a "/" (slash) Distribution
6559 words starting with Bundle:: Bundle
6560 everything else Module or Author
6562 Modules know their associated Distribution objects. They always refer
6563 to the most recent official release. Developers may mark their releases
6564 as unstable development versions (by inserting an underbar into the
6565 module version number which will also be reflected in the distribution
6566 name when you run 'make dist'), so the really hottest and newest
6567 distribution is not always the default. If a module Foo circulates
6568 on CPAN in both version 1.23 and 1.23_90, CPAN.pm offers a convenient
6569 way to install version 1.23 by saying
6573 This would install the complete distribution file (say
6574 BAR/Foo-1.23.tar.gz) with all accompanying material. But if you would
6575 like to install version 1.23_90, you need to know where the
6576 distribution file resides on CPAN relative to the authors/id/
6577 directory. If the author is BAR, this might be BAR/Foo-1.23_90.tar.gz;
6578 so you would have to say
6580 install BAR/Foo-1.23_90.tar.gz
6582 The first example will be driven by an object of the class
6583 CPAN::Module, the second by an object of class CPAN::Distribution.
6585 =head2 Programmer's interface
6587 If you do not enter the shell, the available shell commands are both
6588 available as methods (C<CPAN::Shell-E<gt>install(...)>) and as
6589 functions in the calling package (C<install(...)>).
6591 There's currently only one class that has a stable interface -
6592 CPAN::Shell. All commands that are available in the CPAN shell are
6593 methods of the class CPAN::Shell. Each of the commands that produce
6594 listings of modules (C<r>, C<autobundle>, C<u>) also return a list of
6595 the IDs of all modules within the list.
6599 =item expand($type,@things)
6601 The IDs of all objects available within a program are strings that can
6602 be expanded to the corresponding real objects with the
6603 C<CPAN::Shell-E<gt>expand("Module",@things)> method. Expand returns a
6604 list of CPAN::Module objects according to the C<@things> arguments
6605 given. In scalar context it only returns the first element of the
6608 =item expandany(@things)
6610 Like expand, but returns objects of the appropriate type, i.e.
6611 CPAN::Bundle objects for bundles, CPAN::Module objects for modules and
6612 CPAN::Distribution objects fro distributions.
6614 =item Programming Examples
6616 This enables the programmer to do operations that combine
6617 functionalities that are available in the shell.
6619 # install everything that is outdated on my disk:
6620 perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
6622 # install my favorite programs if necessary:
6623 for $mod (qw(Net::FTP Digest::SHA Data::Dumper)){
6624 my $obj = CPAN::Shell->expand('Module',$mod);
6628 # list all modules on my disk that have no VERSION number
6629 for $mod (CPAN::Shell->expand("Module","/./")){
6630 next unless $mod->inst_file;
6631 # MakeMaker convention for undefined $VERSION:
6632 next unless $mod->inst_version eq "undef";
6633 print "No VERSION in ", $mod->id, "\n";
6636 # find out which distribution on CPAN contains a module:
6637 print CPAN::Shell->expand("Module","Apache::Constants")->cpan_file
6639 Or if you want to write a cronjob to watch The CPAN, you could list
6640 all modules that need updating. First a quick and dirty way:
6642 perl -e 'use CPAN; CPAN::Shell->r;'
6644 If you don't want to get any output in the case that all modules are
6645 up to date, you can parse the output of above command for the regular
6646 expression //modules are up to date// and decide to mail the output
6647 only if it doesn't match. Ick?
6649 If you prefer to do it more in a programmer style in one single
6650 process, maybe something like this suits you better:
6652 # list all modules on my disk that have newer versions on CPAN
6653 for $mod (CPAN::Shell->expand("Module","/./")){
6654 next unless $mod->inst_file;
6655 next if $mod->uptodate;
6656 printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
6657 $mod->id, $mod->inst_version, $mod->cpan_version;
6660 If that gives you too much output every day, you maybe only want to
6661 watch for three modules. You can write
6663 for $mod (CPAN::Shell->expand("Module","/Apache|LWP|CGI/")){
6665 as the first line instead. Or you can combine some of the above
6668 # watch only for a new mod_perl module
6669 $mod = CPAN::Shell->expand("Module","mod_perl");
6670 exit if $mod->uptodate;
6671 # new mod_perl arrived, let me know all update recommendations
6676 =head2 Methods in the other Classes
6678 The programming interface for the classes CPAN::Module,
6679 CPAN::Distribution, CPAN::Bundle, and CPAN::Author is still considered
6680 beta and partially even alpha. In the following paragraphs only those
6681 methods are documented that have proven useful over a longer time and
6682 thus are unlikely to change.
6686 =item CPAN::Author::as_glimpse()
6688 Returns a one-line description of the author
6690 =item CPAN::Author::as_string()
6692 Returns a multi-line description of the author
6694 =item CPAN::Author::email()
6696 Returns the author's email address
6698 =item CPAN::Author::fullname()
6700 Returns the author's name
6702 =item CPAN::Author::name()
6704 An alias for fullname
6706 =item CPAN::Bundle::as_glimpse()
6708 Returns a one-line description of the bundle
6710 =item CPAN::Bundle::as_string()
6712 Returns a multi-line description of the bundle
6714 =item CPAN::Bundle::clean()
6716 Recursively runs the C<clean> method on all items contained in the bundle.
6718 =item CPAN::Bundle::contains()
6720 Returns a list of objects' IDs contained in a bundle. The associated
6721 objects may be bundles, modules or distributions.
6723 =item CPAN::Bundle::force($method,@args)
6725 Forces CPAN to perform a task that normally would have failed. Force
6726 takes as arguments a method name to be called and any number of
6727 additional arguments that should be passed to the called method. The
6728 internals of the object get the needed changes so that CPAN.pm does
6729 not refuse to take the action. The C<force> is passed recursively to
6730 all contained objects.
6732 =item CPAN::Bundle::get()
6734 Recursively runs the C<get> method on all items contained in the bundle
6736 =item CPAN::Bundle::inst_file()
6738 Returns the highest installed version of the bundle in either @INC or
6739 C<$CPAN::Config->{cpan_home}>. Note that this is different from
6740 CPAN::Module::inst_file.
6742 =item CPAN::Bundle::inst_version()
6744 Like CPAN::Bundle::inst_file, but returns the $VERSION
6746 =item CPAN::Bundle::uptodate()
6748 Returns 1 if the bundle itself and all its members are uptodate.
6750 =item CPAN::Bundle::install()
6752 Recursively runs the C<install> method on all items contained in the bundle
6754 =item CPAN::Bundle::make()
6756 Recursively runs the C<make> method on all items contained in the bundle
6758 =item CPAN::Bundle::readme()
6760 Recursively runs the C<readme> method on all items contained in the bundle
6762 =item CPAN::Bundle::test()
6764 Recursively runs the C<test> method on all items contained in the bundle
6766 =item CPAN::Distribution::as_glimpse()
6768 Returns a one-line description of the distribution
6770 =item CPAN::Distribution::as_string()
6772 Returns a multi-line description of the distribution
6774 =item CPAN::Distribution::clean()
6776 Changes to the directory where the distribution has been unpacked and
6777 runs C<make clean> there.
6779 =item CPAN::Distribution::containsmods()
6781 Returns a list of IDs of modules contained in a distribution file.
6782 Only works for distributions listed in the 02packages.details.txt.gz
6783 file. This typically means that only the most recent version of a
6784 distribution is covered.
6786 =item CPAN::Distribution::cvs_import()
6788 Changes to the directory where the distribution has been unpacked and
6791 cvs -d $cvs_root import -m $cvs_log $cvs_dir $userid v$version
6795 =item CPAN::Distribution::dir()
6797 Returns the directory into which this distribution has been unpacked.
6799 =item CPAN::Distribution::force($method,@args)
6801 Forces CPAN to perform a task that normally would have failed. Force
6802 takes as arguments a method name to be called and any number of
6803 additional arguments that should be passed to the called method. The
6804 internals of the object get the needed changes so that CPAN.pm does
6805 not refuse to take the action.
6807 =item CPAN::Distribution::get()
6809 Downloads the distribution from CPAN and unpacks it. Does nothing if
6810 the distribution has already been downloaded and unpacked within the
6813 =item CPAN::Distribution::install()
6815 Changes to the directory where the distribution has been unpacked and
6816 runs the external command C<make install> there. If C<make> has not
6817 yet been run, it will be run first. A C<make test> will be issued in
6818 any case and if this fails, the install will be canceled. The
6819 cancellation can be avoided by letting C<force> run the C<install> for
6822 =item CPAN::Distribution::isa_perl()
6824 Returns 1 if this distribution file seems to be a perl distribution.
6825 Normally this is derived from the file name only, but the index from
6826 CPAN can contain a hint to achieve a return value of true for other
6829 =item CPAN::Distribution::look()
6831 Changes to the directory where the distribution has been unpacked and
6832 opens a subshell there. Exiting the subshell returns.
6834 =item CPAN::Distribution::make()
6836 First runs the C<get> method to make sure the distribution is
6837 downloaded and unpacked. Changes to the directory where the
6838 distribution has been unpacked and runs the external commands C<perl
6839 Makefile.PL> or C<perl Build.PL> and C<make> there.
6841 =item CPAN::Distribution::prereq_pm()
6843 Returns the hash reference that has been announced by a distribution
6844 as the C<requires> element of the META.yml or the C<PREREQ_PM> hash in
6845 the C<Makefile.PL>. Note: works only after an attempt has been made to
6846 C<make> the distribution. Returns undef otherwise.
6848 =item CPAN::Distribution::readme()
6850 Downloads the README file associated with a distribution and runs it
6851 through the pager specified in C<$CPAN::Config->{pager}>.
6853 =item CPAN::Distribution::perldoc()
6855 Downloads the pod documentation of the file associated with a
6856 distribution (in html format) and runs it through the external
6857 command lynx specified in C<$CPAN::Config->{lynx}>. If lynx
6858 isn't available, it converts it to plain text with external
6859 command html2text and runs it through the pager specified
6860 in C<$CPAN::Config->{pager}>
6862 =item CPAN::Distribution::test()
6864 Changes to the directory where the distribution has been unpacked and
6865 runs C<make test> there.
6867 =item CPAN::Distribution::uptodate()
6869 Returns 1 if all the modules contained in the distribution are
6870 uptodate. Relies on containsmods.
6872 =item CPAN::Index::force_reload()
6874 Forces a reload of all indices.
6876 =item CPAN::Index::reload()
6878 Reloads all indices if they have not been read for more than
6879 C<$CPAN::Config->{index_expire}> days.
6881 =item CPAN::InfoObj::dump()
6883 CPAN::Author, CPAN::Bundle, CPAN::Module, and CPAN::Distribution
6884 inherit this method. It prints the data structure associated with an
6885 object. Useful for debugging. Note: the data structure is considered
6886 internal and thus subject to change without notice.
6888 =item CPAN::Module::as_glimpse()
6890 Returns a one-line description of the module
6892 =item CPAN::Module::as_string()
6894 Returns a multi-line description of the module
6896 =item CPAN::Module::clean()
6898 Runs a clean on the distribution associated with this module.
6900 =item CPAN::Module::cpan_file()
6902 Returns the filename on CPAN that is associated with the module.
6904 =item CPAN::Module::cpan_version()
6906 Returns the latest version of this module available on CPAN.
6908 =item CPAN::Module::cvs_import()
6910 Runs a cvs_import on the distribution associated with this module.
6912 =item CPAN::Module::description()
6914 Returns a 44 character description of this module. Only available for
6915 modules listed in The Module List (CPAN/modules/00modlist.long.html
6916 or 00modlist.long.txt.gz)
6918 =item CPAN::Module::force($method,@args)
6920 Forces CPAN to perform a task that normally would have failed. Force
6921 takes as arguments a method name to be called and any number of
6922 additional arguments that should be passed to the called method. The
6923 internals of the object get the needed changes so that CPAN.pm does
6924 not refuse to take the action.
6926 =item CPAN::Module::get()
6928 Runs a get on the distribution associated with this module.
6930 =item CPAN::Module::inst_file()
6932 Returns the filename of the module found in @INC. The first file found
6933 is reported just like perl itself stops searching @INC when it finds a
6936 =item CPAN::Module::inst_version()
6938 Returns the version number of the module in readable format.
6940 =item CPAN::Module::install()
6942 Runs an C<install> on the distribution associated with this module.
6944 =item CPAN::Module::look()
6946 Changes to the directory where the distribution associated with this
6947 module has been unpacked and opens a subshell there. Exiting the
6950 =item CPAN::Module::make()
6952 Runs a C<make> on the distribution associated with this module.
6954 =item CPAN::Module::manpage_headline()
6956 If module is installed, peeks into the module's manpage, reads the
6957 headline and returns it. Moreover, if the module has been downloaded
6958 within this session, does the equivalent on the downloaded module even
6959 if it is not installed.
6961 =item CPAN::Module::readme()
6963 Runs a C<readme> on the distribution associated with this module.
6965 =item CPAN::Module::perldoc()
6967 Runs a C<perldoc> on this module.
6969 =item CPAN::Module::test()
6971 Runs a C<test> on the distribution associated with this module.
6973 =item CPAN::Module::uptodate()
6975 Returns 1 if the module is installed and up-to-date.
6977 =item CPAN::Module::userid()
6979 Returns the author's ID of the module.
6983 =head2 Cache Manager
6985 Currently the cache manager only keeps track of the build directory
6986 ($CPAN::Config->{build_dir}). It is a simple FIFO mechanism that
6987 deletes complete directories below C<build_dir> as soon as the size of
6988 all directories there gets bigger than $CPAN::Config->{build_cache}
6989 (in MB). The contents of this cache may be used for later
6990 re-installations that you intend to do manually, but will never be
6991 trusted by CPAN itself. This is due to the fact that the user might
6992 use these directories for building modules on different architectures.
6994 There is another directory ($CPAN::Config->{keep_source_where}) where
6995 the original distribution files are kept. This directory is not
6996 covered by the cache manager and must be controlled by the user. If
6997 you choose to have the same directory as build_dir and as
6998 keep_source_where directory, then your sources will be deleted with
6999 the same fifo mechanism.
7003 A bundle is just a perl module in the namespace Bundle:: that does not
7004 define any functions or methods. It usually only contains documentation.
7006 It starts like a perl module with a package declaration and a $VERSION
7007 variable. After that the pod section looks like any other pod with the
7008 only difference being that I<one special pod section> exists starting with
7013 In this pod section each line obeys the format
7015 Module_Name [Version_String] [- optional text]
7017 The only required part is the first field, the name of a module
7018 (e.g. Foo::Bar, ie. I<not> the name of the distribution file). The rest
7019 of the line is optional. The comment part is delimited by a dash just
7020 as in the man page header.
7022 The distribution of a bundle should follow the same convention as
7023 other distributions.
7025 Bundles are treated specially in the CPAN package. If you say 'install
7026 Bundle::Tkkit' (assuming such a bundle exists), CPAN will install all
7027 the modules in the CONTENTS section of the pod. You can install your
7028 own Bundles locally by placing a conformant Bundle file somewhere into
7029 your @INC path. The autobundle() command which is available in the
7030 shell interface does that for you by including all currently installed
7031 modules in a snapshot bundle file.
7033 =head2 Prerequisites
7035 If you have a local mirror of CPAN and can access all files with
7036 "file:" URLs, then you only need a perl better than perl5.003 to run
7037 this module. Otherwise Net::FTP is strongly recommended. LWP may be
7038 required for non-UNIX systems or if your nearest CPAN site is
7039 associated with a URL that is not C<ftp:>.
7041 If you have neither Net::FTP nor LWP, there is a fallback mechanism
7042 implemented for an external ftp command or for an external lynx
7045 =head2 Finding packages and VERSION
7047 This module presumes that all packages on CPAN
7053 declare their $VERSION variable in an easy to parse manner. This
7054 prerequisite can hardly be relaxed because it consumes far too much
7055 memory to load all packages into the running program just to determine
7056 the $VERSION variable. Currently all programs that are dealing with
7057 version use something like this
7059 perl -MExtUtils::MakeMaker -le \
7060 'print MM->parse_version(shift)' filename
7062 If you are author of a package and wonder if your $VERSION can be
7063 parsed, please try the above method.
7067 come as compressed or gzipped tarfiles or as zip files and contain a
7068 C<Makefile.PL> or C<Build.PL> (well, we try to handle a bit more, but
7069 without much enthusiasm).
7075 The debugging of this module is a bit complex, because we have
7076 interferences of the software producing the indices on CPAN, of the
7077 mirroring process on CPAN, of packaging, of configuration, of
7078 synchronicity, and of bugs within CPAN.pm.
7080 For code debugging in interactive mode you can try "o debug" which
7081 will list options for debugging the various parts of the code. You
7082 should know that "o debug" has built-in completion support.
7084 For data debugging there is the C<dump> command which takes the same
7085 arguments as make/test/install and outputs the object's Data::Dumper
7088 =head2 Floppy, Zip, Offline Mode
7090 CPAN.pm works nicely without network too. If you maintain machines
7091 that are not networked at all, you should consider working with file:
7092 URLs. Of course, you have to collect your modules somewhere first. So
7093 you might use CPAN.pm to put together all you need on a networked
7094 machine. Then copy the $CPAN::Config->{keep_source_where} (but not
7095 $CPAN::Config->{build_dir}) directory on a floppy. This floppy is kind
7096 of a personal CPAN. CPAN.pm on the non-networked machines works nicely
7097 with this floppy. See also below the paragraph about CD-ROM support.
7099 =head1 CONFIGURATION
7101 When the CPAN module is used for the first time, a configuration
7102 dialog tries to determine a couple of site specific options. The
7103 result of the dialog is stored in a hash reference C< $CPAN::Config >
7104 in a file CPAN/Config.pm.
7106 The default values defined in the CPAN/Config.pm file can be
7107 overridden in a user specific file: CPAN/MyConfig.pm. Such a file is
7108 best placed in $HOME/.cpan/CPAN/MyConfig.pm, because $HOME/.cpan is
7109 added to the search path of the CPAN module before the use() or
7110 require() statements.
7112 The configuration dialog can be started any time later again by
7113 issuing the command C< o conf init > in the CPAN shell.
7115 Currently the following keys in the hash reference $CPAN::Config are
7118 build_cache size of cache for directories to build modules
7119 build_dir locally accessible directory to build modules
7120 index_expire after this many days refetch index files
7121 cache_metadata use serializer to cache metadata
7122 cpan_home local directory reserved for this package
7123 dontload_hash anonymous hash: modules in the keys will not be
7124 loaded by the CPAN::has_inst() routine
7125 gzip location of external program gzip
7126 histfile file to maintain history between sessions
7127 histsize maximum number of lines to keep in histfile
7128 inactivity_timeout breaks interactive Makefile.PLs or Build.PLs
7129 after this many seconds inactivity. Set to 0 to
7131 inhibit_startup_message
7132 if true, does not print the startup message
7133 keep_source_where directory in which to keep the source (if we do)
7134 make location of external make program
7135 make_arg arguments that should always be passed to 'make'
7136 make_install_make_command
7137 the make command for running 'make install', for
7139 make_install_arg same as make_arg for 'make install'
7140 makepl_arg arguments passed to 'perl Makefile.PL'
7141 mbuild_arg arguments passed to './Build'
7142 mbuild_install_arg arguments passed to './Build install'
7143 mbuild_install_build_command
7144 command to use instead of './Build' when we are
7145 in the install stage, for example 'sudo ./Build'
7146 mbuildpl_arg arguments passed to 'perl Build.PL'
7147 pager location of external program more (or any pager)
7148 prefer_installer legal values are MB and EUMM: if a module
7149 comes with both a Makefile.PL and a Build.PL, use
7150 the former (EUMM) or the latter (MB)
7151 prerequisites_policy
7152 what to do if you are missing module prerequisites
7153 ('follow' automatically, 'ask' me, or 'ignore')
7154 proxy_user username for accessing an authenticating proxy
7155 proxy_pass password for accessing an authenticating proxy
7156 scan_cache controls scanning of cache ('atstart' or 'never')
7157 tar location of external program tar
7158 term_is_latin if true internal UTF-8 is translated to ISO-8859-1
7159 (and nonsense for characters outside latin range)
7160 unzip location of external program unzip
7161 urllist arrayref to nearby CPAN sites (or equivalent locations)
7162 wait_list arrayref to a wait server to try (See CPAN::WAIT)
7163 ftp_proxy, } the three usual variables for configuring
7164 http_proxy, } proxy requests. Both as CPAN::Config variables
7165 no_proxy } and as environment variables configurable.
7167 You can set and query each of these options interactively in the cpan
7168 shell with the command set defined within the C<o conf> command:
7172 =item C<o conf E<lt>scalar optionE<gt>>
7174 prints the current value of the I<scalar option>
7176 =item C<o conf E<lt>scalar optionE<gt> E<lt>valueE<gt>>
7178 Sets the value of the I<scalar option> to I<value>
7180 =item C<o conf E<lt>list optionE<gt>>
7182 prints the current value of the I<list option> in MakeMaker's
7185 =item C<o conf E<lt>list optionE<gt> [shift|pop]>
7187 shifts or pops the array in the I<list option> variable
7189 =item C<o conf E<lt>list optionE<gt> [unshift|push|splice] E<lt>listE<gt>>
7191 works like the corresponding perl commands.
7195 =head2 Note on urllist parameter's format
7197 urllist parameters are URLs according to RFC 1738. We do a little
7198 guessing if your URL is not compliant, but if you have problems with
7199 file URLs, please try the correct format. Either:
7201 file://localhost/whatever/ftp/pub/CPAN/
7205 file:///home/ftp/pub/CPAN/
7207 =head2 urllist parameter has CD-ROM support
7209 The C<urllist> parameter of the configuration table contains a list of
7210 URLs that are to be used for downloading. If the list contains any
7211 C<file> URLs, CPAN always tries to get files from there first. This
7212 feature is disabled for index files. So the recommendation for the
7213 owner of a CD-ROM with CPAN contents is: include your local, possibly
7214 outdated CD-ROM as a C<file> URL at the end of urllist, e.g.
7216 o conf urllist push file://localhost/CDROM/CPAN
7218 CPAN.pm will then fetch the index files from one of the CPAN sites
7219 that come at the beginning of urllist. It will later check for each
7220 module if there is a local copy of the most recent version.
7222 Another peculiarity of urllist is that the site that we could
7223 successfully fetch the last file from automatically gets a preference
7224 token and is tried as the first site for the next request. So if you
7225 add a new site at runtime it may happen that the previously preferred
7226 site will be tried another time. This means that if you want to disallow
7227 a site for the next transfer, it must be explicitly removed from
7232 There's no strong security layer in CPAN.pm. CPAN.pm helps you to
7233 install foreign, unmasked, unsigned code on your machine. We compare
7234 to a checksum that comes from the net just as the distribution file
7235 itself. But we try to make it easy to add security on demand:
7237 =head2 Cryptographically signed modules
7239 Since release 1.77 CPAN.pm has been able to verify cryptographically
7240 signed module distributions using Module::Signature. The CPAN modules
7241 can be signed by their authors, thus giving more security. The simple
7242 unsigned MD5 checksums that were used before by CPAN protect mainly
7243 against accidental file corruption.
7245 You will need to have Module::Signature installed, which in turn
7246 requires that you have at least one of Crypt::OpenPGP module or the
7247 command-line F<gpg> tool installed.
7249 You will also need to be able to connect over the Internet to the public
7250 keyservers, like pgp.mit.edu, and their port 11731 (the HKP protocol).
7254 Most functions in package CPAN are exported per default. The reason
7255 for this is that the primary use is intended for the cpan shell or for
7260 When the CPAN shell enters a subshell via the look command, it sets
7261 the environment CPAN_SHELL_LEVEL to 1 or increments it if it is
7264 =head1 POPULATE AN INSTALLATION WITH LOTS OF MODULES
7266 Populating a freshly installed perl with my favorite modules is pretty
7267 easy if you maintain a private bundle definition file. To get a useful
7268 blueprint of a bundle definition file, the command autobundle can be used
7269 on the CPAN shell command line. This command writes a bundle definition
7270 file for all modules that are installed for the currently running perl
7271 interpreter. It's recommended to run this command only once and from then
7272 on maintain the file manually under a private name, say
7273 Bundle/my_bundle.pm. With a clever bundle file you can then simply say
7275 cpan> install Bundle::my_bundle
7277 then answer a few questions and then go out for a coffee.
7279 Maintaining a bundle definition file means keeping track of two
7280 things: dependencies and interactivity. CPAN.pm sometimes fails on
7281 calculating dependencies because not all modules define all MakeMaker
7282 attributes correctly, so a bundle definition file should specify
7283 prerequisites as early as possible. On the other hand, it's a bit
7284 annoying that many distributions need some interactive configuring. So
7285 what I try to accomplish in my private bundle file is to have the
7286 packages that need to be configured early in the file and the gentle
7287 ones later, so I can go out after a few minutes and leave CPAN.pm
7290 =head1 WORKING WITH CPAN.pm BEHIND FIREWALLS
7292 Thanks to Graham Barr for contributing the following paragraphs about
7293 the interaction between perl, and various firewall configurations. For
7294 further information on firewalls, it is recommended to consult the
7295 documentation that comes with the ncftp program. If you are unable to
7296 go through the firewall with a simple Perl setup, it is very likely
7297 that you can configure ncftp so that it works for your firewall.
7299 =head2 Three basic types of firewalls
7301 Firewalls can be categorized into three basic types.
7307 This is where the firewall machine runs a web server and to access the
7308 outside world you must do it via the web server. If you set environment
7309 variables like http_proxy or ftp_proxy to a values beginning with http://
7310 or in your web browser you have to set proxy information then you know
7311 you are running an http firewall.
7313 To access servers outside these types of firewalls with perl (even for
7314 ftp) you will need to use LWP.
7318 This where the firewall machine runs an ftp server. This kind of
7319 firewall will only let you access ftp servers outside the firewall.
7320 This is usually done by connecting to the firewall with ftp, then
7321 entering a username like "user@outside.host.com"
7323 To access servers outside these type of firewalls with perl you
7324 will need to use Net::FTP.
7326 =item One way visibility
7328 I say one way visibility as these firewalls try to make themselves look
7329 invisible to the users inside the firewall. An FTP data connection is
7330 normally created by sending the remote server your IP address and then
7331 listening for the connection. But the remote server will not be able to
7332 connect to you because of the firewall. So for these types of firewall
7333 FTP connections need to be done in a passive mode.
7335 There are two that I can think off.
7341 If you are using a SOCKS firewall you will need to compile perl and link
7342 it with the SOCKS library, this is what is normally called a 'socksified'
7343 perl. With this executable you will be able to connect to servers outside
7344 the firewall as if it is not there.
7348 This is the firewall implemented in the Linux kernel, it allows you to
7349 hide a complete network behind one IP address. With this firewall no
7350 special compiling is needed as you can access hosts directly.
7352 For accessing ftp servers behind such firewalls you may need to set
7353 the environment variable C<FTP_PASSIVE> to a true value, e.g.
7355 env FTP_PASSIVE=1 perl -MCPAN -eshell
7359 perl -MCPAN -e '$ENV{FTP_PASSIVE} = 1; shell'
7366 =head2 Configuring lynx or ncftp for going through a firewall
7368 If you can go through your firewall with e.g. lynx, presumably with a
7371 /usr/local/bin/lynx -pscott:tiger
7373 then you would configure CPAN.pm with the command
7375 o conf lynx "/usr/local/bin/lynx -pscott:tiger"
7377 That's all. Similarly for ncftp or ftp, you would configure something
7380 o conf ncftp "/usr/bin/ncftp -f /home/scott/ncftplogin.cfg"
7382 Your mileage may vary...
7390 I installed a new version of module X but CPAN keeps saying,
7391 I have the old version installed
7393 Most probably you B<do> have the old version installed. This can
7394 happen if a module installs itself into a different directory in the
7395 @INC path than it was previously installed. This is not really a
7396 CPAN.pm problem, you would have the same problem when installing the
7397 module manually. The easiest way to prevent this behaviour is to add
7398 the argument C<UNINST=1> to the C<make install> call, and that is why
7399 many people add this argument permanently by configuring
7401 o conf make_install_arg UNINST=1
7405 So why is UNINST=1 not the default?
7407 Because there are people who have their precise expectations about who
7408 may install where in the @INC path and who uses which @INC array. In
7409 fine tuned environments C<UNINST=1> can cause damage.
7413 I want to clean up my mess, and install a new perl along with
7414 all modules I have. How do I go about it?
7416 Run the autobundle command for your old perl and optionally rename the
7417 resulting bundle file (e.g. Bundle/mybundle.pm), install the new perl
7418 with the Configure option prefix, e.g.
7420 ./Configure -Dprefix=/usr/local/perl-5.6.78.9
7422 Install the bundle file you produced in the first step with something like
7424 cpan> install Bundle::mybundle
7430 When I install bundles or multiple modules with one command
7431 there is too much output to keep track of.
7433 You may want to configure something like
7435 o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
7436 o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"
7438 so that STDOUT is captured in a file for later inspection.
7443 I am not root, how can I install a module in a personal directory?
7445 First of all, you will want to use your own configuration, not the one
7446 that your root user installed. The following command sequence is a
7449 % mkdir -p $HOME/.cpan/CPAN
7450 % echo '$CPAN::Config={ };' > $HOME/.cpan/CPAN/MyConfig.pm
7452 [...answer all questions...]
7454 You will most probably like something like this:
7456 o conf makepl_arg "LIB=~/myperl/lib \
7457 INSTALLMAN1DIR=~/myperl/man/man1 \
7458 INSTALLMAN3DIR=~/myperl/man/man3"
7460 You can make this setting permanent like all C<o conf> settings with
7463 You will have to add ~/myperl/man to the MANPATH environment variable
7464 and also tell your perl programs to look into ~/myperl/lib, e.g. by
7467 use lib "$ENV{HOME}/myperl/lib";
7469 or setting the PERL5LIB environment variable.
7471 Another thing you should bear in mind is that the UNINST parameter
7472 should never be set if you are not root.
7476 How to get a package, unwrap it, and make a change before building it?
7478 look Sybase::Sybperl
7482 I installed a Bundle and had a couple of fails. When I
7483 retried, everything resolved nicely. Can this be fixed to work
7486 The reason for this is that CPAN does not know the dependencies of all
7487 modules when it starts out. To decide about the additional items to
7488 install, it just uses data found in the generated Makefile. An
7489 undetected missing piece breaks the process. But it may well be that
7490 your Bundle installs some prerequisite later than some depending item
7491 and thus your second try is able to resolve everything. Please note,
7492 CPAN.pm does not know the dependency tree in advance and cannot sort
7493 the queue of things to install in a topologically correct order. It
7494 resolves perfectly well IFF all modules declare the prerequisites
7495 correctly with the PREREQ_PM attribute to MakeMaker. For bundles which
7496 fail and you need to install often, it is recommended to sort the Bundle
7497 definition file manually. It is planned to improve the metadata
7498 situation for dependencies on CPAN in general, but this will still
7503 In our intranet we have many modules for internal use. How
7504 can I integrate these modules with CPAN.pm but without uploading
7505 the modules to CPAN?
7507 Have a look at the CPAN::Site module.
7511 When I run CPAN's shell, I get error msg about line 1 to 4,
7512 setting meta input/output via the /etc/inputrc file.
7514 Some versions of readline are picky about capitalization in the
7515 /etc/inputrc file and specifically RedHat 6.2 comes with a
7516 /etc/inputrc that contains the word C<on> in lowercase. Change the
7517 occurrences of C<on> to C<On> and the bug should disappear.
7521 Some authors have strange characters in their names.
7523 Internally CPAN.pm uses the UTF-8 charset. If your terminal is
7524 expecting ISO-8859-1 charset, a converter can be activated by setting
7525 term_is_latin to a true value in your config file. One way of doing so
7528 cpan> ! $CPAN::Config->{term_is_latin}=1
7530 Extended support for converters will be made available as soon as perl
7531 becomes stable with regard to charset issues.
7535 When an install fails for some reason and then I correct the error
7536 condition and retry, CPAN.pm refuses to install the module, saying
7537 C<Already tried without success>.
7539 Use the force pragma like so
7541 force install Foo::Bar
7543 This does a bit more than really needed because it untars the
7544 distribution again and runs make and test and only then install.
7546 Or, if you find this is too fast and you would prefer to do smaller
7551 first and then continue as always. C<Force get> I<forgets> previous
7558 and then 'make install' directly in the subshell.
7560 Or you leave the CPAN shell and start it again.
7562 For the really curious, by accessing internals directly, you I<could>
7564 ! delete CPAN::Shell->expand("Distribution", \
7565 CPAN::Shell->expand("Module","Foo::Bar") \
7566 ->cpan_file)->{install}
7568 but this is neither guaranteed to work in the future nor is it a
7575 If a Makefile.PL requires special customization of libraries, prompts
7576 the user for special input, etc. then you may find CPAN is not able to
7577 build the distribution. In that case it is recommended to attempt the
7578 traditional method of building a Perl module package from a shell, for
7579 example by using the 'look' command to open a subshell in the
7580 distribution's own directory.
7584 Andreas Koenig C<< <andk@cpan.org> >>
7588 Kawai,Takanori provides a Japanese translation of this manpage at
7589 http://member.nifty.ne.jp/hippo2000/perltips/CPAN.htm
7593 cpan(1), CPAN::Nox(3pm), CPAN::Version(3pm)
7599 # cperl-indent-level: 4