1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 # vim: ts=4 sts=4 sw=4:
5 $CPAN::VERSION = '1.94_5301'; # 1.94_53 + local patches for bleadperl
6 $CPAN::VERSION =~ s/_//;
8 # we need to run chdir all over and we would get at wrong libraries
12 if (File::Spec->can("rel2abs")) {
14 $inc = File::Spec->rel2abs($inc) unless ref $inc;
19 use CPAN::HandleConfig;
25 use CPAN::Distribution;
26 use CPAN::Distrostatus;
28 use CPAN::Index 1.93; # https://rt.cpan.org/Ticket/Display.html?id=43349
35 use CPAN::DeferredCode;
37 use CPAN::LWP::UserAgent;
38 use CPAN::Exception::RecursiveDependency;
39 use CPAN::Exception::yaml_not_installed;
46 use ExtUtils::MakeMaker qw(prompt); # for some unknown reason,
47 # 5.005_04 does not work without
49 use File::Basename ();
56 use Sys::Hostname qw(hostname);
57 use Text::ParseWords ();
60 # protect against "called too early"
67 require Mac::BuildTools if $^O eq 'MacOS';
68 if ($ENV{PERL5_CPAN_IS_RUNNING} && $$ != $ENV{PERL5_CPAN_IS_RUNNING}) {
69 $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} ||= $ENV{PERL5_CPAN_IS_RUNNING};
70 my @rec = _uniq split(/,/, $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION}), $$;
71 $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} = join ",", @rec;
72 # warn "# Note: Recursive call of CPAN.pm detected\n";
73 my $w = sprintf "# Note: CPAN.pm is running in process %d now", pop @rec;
79 my $sleep = @rec > 7 ? 300 : ($sleep{scalar @rec}||0);
80 my $verbose = @rec >= 4;
82 $w .= sprintf " which has been called by process %d", pop @rec;
85 $w .= ".\n\n# Sleeping $sleep seconds to protect other processes\n";
92 printf "\r#%5d", --$sleep;
97 $ENV{PERL5_CPAN_IS_RUNNING}=$$;
98 $ENV{PERL5_CPANPLUS_IS_RUNNING}=$$; # https://rt.cpan.org/Ticket/Display.html?id=23735
100 END { $CPAN::End++; &cleanup; }
103 $CPAN::Frontend ||= "CPAN::Shell";
104 unless (@CPAN::Defaultsites) {
105 @CPAN::Defaultsites = map {
106 CPAN::URL->new(TEXT => $_, FROM => "DEF")
108 "http://www.perl.org/CPAN/",
109 "ftp://ftp.perl.org/pub/CPAN/";
111 # $CPAN::iCwd (i for initial)
112 $CPAN::iCwd ||= CPAN::anycwd();
113 $CPAN::Perl ||= CPAN::find_perl();
114 $CPAN::Defaultdocs ||= "http://search.cpan.org/perldoc?";
115 $CPAN::Defaultrecent ||= "http://search.cpan.org/uploads.rdf";
116 $CPAN::Defaultrecent ||= "http://cpan.uwinnipeg.ca/htdocs/cpan.xml";
118 # our globals are getting a mess
144 @CPAN::ISA = qw(CPAN::Debug Exporter);
146 # note that these functions live in CPAN::Shell and get executed via
147 # AUTOLOAD when called directly
174 sub soft_chdir_with_alternatives ($);
177 $autoload_recursion ||= 0;
179 #-> sub CPAN::AUTOLOAD ;
180 sub AUTOLOAD { ## no critic
181 $autoload_recursion++;
185 warn "Refusing to autoload '$l' while signal pending";
186 $autoload_recursion--;
189 if ($autoload_recursion > 1) {
190 my $fullcommand = join " ", map { "'$_'" } $l, @_;
191 warn "Refusing to autoload $fullcommand in recursion\n";
192 $autoload_recursion--;
196 @export{@EXPORT} = '';
197 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
198 if (exists $export{$l}) {
201 die(qq{Unknown CPAN command "$AUTOLOAD". }.
202 qq{Type ? for help.\n});
204 $autoload_recursion--;
209 my $x = *SAVEOUT; # avoid warning
210 open($x,">&STDOUT") or die "dup failed";
216 while(defined($_=shift)) {
218 my ($m) = s/^>// ? ">" : "";
220 $_=shift unless length;
221 die "no dest" unless defined;
222 open(STDOUT,">$m$_") or die "open:$_:$!\n";
224 } elsif ( s/^\s*\|\s*// ) {
226 while(defined($_[0])){
227 $pipe .= ' ' . shift;
229 open(STDOUT,$pipe) or die "open:$pipe:$!\n";
238 return unless $redir;
240 ## redirect: unredirect and propagate errors. explicit close to wait for pipe.
242 open(STDOUT,">&SAVEOUT");
251 return grep { !$seen{$_}++ } @list;
254 #-> sub CPAN::shell ;
257 $Suppress_readline = ! -t STDIN unless defined $Suppress_readline;
258 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
260 my $oprompt = shift || CPAN::Prompt->new;
261 my $prompt = $oprompt;
262 my $commandline = shift || "";
263 $CPAN::CurrentCommandId ||= 1;
266 unless ($Suppress_readline) {
267 require Term::ReadLine;
270 $term->ReadLine eq "Term::ReadLine::Stub"
272 $term = Term::ReadLine->new('CPAN Monitor');
274 if ($term->ReadLine eq "Term::ReadLine::Gnu") {
275 my $attribs = $term->Attribs;
276 $attribs->{attempted_completion_function} = sub {
277 &CPAN::Complete::gnu_cpl;
280 $readline::rl_completion_function =
281 $readline::rl_completion_function = 'CPAN::Complete::cpl';
283 if (my $histfile = $CPAN::Config->{'histfile'}) {{
284 unless ($term->can("AddHistory")) {
285 $CPAN::Frontend->mywarn("Terminal does not support AddHistory.\n");
288 $META->readhist($term,$histfile);
290 for ($CPAN::Config->{term_ornaments}) { # alias
291 local $Term::ReadLine::termcap_nowarn = 1;
292 $term->ornaments($_) if defined;
294 # $term->OUT is autoflushed anyway
295 my $odef = select STDERR;
303 my @cwd = grep { defined $_ and length $_ }
305 File::Spec->can("tmpdir") ? File::Spec->tmpdir() : (),
306 File::Spec->rootdir();
307 my $try_detect_readline;
308 $try_detect_readline = $term->ReadLine eq "Term::ReadLine::Stub" if $term;
309 unless ($CPAN::Config->{inhibit_startup_message}) {
310 my $rl_avail = $Suppress_readline ? "suppressed" :
311 ($term->ReadLine ne "Term::ReadLine::Stub") ? "enabled" :
312 "available (maybe install Bundle::CPAN or Bundle::CPANxxl?)";
313 $CPAN::Frontend->myprint(
315 cpan shell -- CPAN exploration and modules installation (v%s)
323 my($continuation) = "";
324 my $last_term_ornaments;
325 SHELLCOMMAND: while () {
326 if ($Suppress_readline) {
327 if ($Echo_readline) {
331 last SHELLCOMMAND unless defined ($_ = <> );
332 if ($Echo_readline) {
333 # backdoor: I could not find a way to record sessions
338 last SHELLCOMMAND unless
339 defined ($_ = $term->readline($prompt, $commandline));
341 $_ = "$continuation$_" if $continuation;
343 next SHELLCOMMAND if /^$/;
345 if (/^(?:q(?:uit)?|bye|exit)\s*$/i) {
355 CPAN::Eval; # hide from the indexer
357 use vars qw($import_done);
358 CPAN->import(':DEFAULT') unless $import_done++;
359 CPAN->debug("eval[$eval]") if $CPAN::DEBUG;
366 eval { @line = Text::ParseWords::shellwords($_) };
367 warn($@), next SHELLCOMMAND if $@;
368 warn("Text::Parsewords could not parse the line [$_]"),
369 next SHELLCOMMAND unless @line;
370 $CPAN::META->debug("line[".join("|",@line)."]") if $CPAN::DEBUG;
371 my $command = shift @line;
373 local (*STDOUT)=*STDOUT;
374 @line = _redirect(@line);
375 CPAN::Shell->$command(@line)
377 my $command_error = $@;
380 if ($command_error) {
381 my $err = $command_error;
382 if (ref $err and $err->isa('CPAN::Exception::blocked_urllist')) {
383 $CPAN::Frontend->mywarn("Client not fully configured, please proceed with configuring.$err");
384 $reported_error = ref $err;
386 # I'd prefer never to arrive here and make all errors exception objects
390 my $dv = Dumpvalue->new(tick => '"');
391 Carp::cluck(sprintf "Catching error: %s", $dv->stringify($err));
402 # pragmas for classic commands
411 # only commands that tell us something about failed distros
412 # eval necessary for people without an urllist
413 eval {CPAN::Shell->failed($CPAN::CurrentCommandId,1);};
415 unless (ref $err and $reported_error eq ref $err) {
420 soft_chdir_with_alternatives(\@cwd);
421 $CPAN::Frontend->myprint("\n");
423 $CPAN::CurrentCommandId++;
427 $commandline = ""; # I do want to be able to pass a default to
428 # shell, but on the second command I see no
431 CPAN::Queue->nullify_queue;
432 if ($try_detect_readline) {
433 if ($CPAN::META->has_inst("Term::ReadLine::Gnu")
435 $CPAN::META->has_inst("Term::ReadLine::Perl")
437 delete $INC{"Term/ReadLine.pm"};
439 local($SIG{__WARN__}) = CPAN::Shell::paintdots_onreload(\$redef);
440 require Term::ReadLine;
441 $CPAN::Frontend->myprint("\n$redef subroutines in ".
442 "Term::ReadLine redefined\n");
446 if ($term and $term->can("ornaments")) {
447 for ($CPAN::Config->{term_ornaments}) { # alias
449 if (not defined $last_term_ornaments
450 or $_ != $last_term_ornaments
452 local $Term::ReadLine::termcap_nowarn = 1;
453 $term->ornaments($_);
454 $last_term_ornaments = $_;
457 undef $last_term_ornaments;
461 for my $class (qw(Module Distribution)) {
462 # again unsafe meta access?
463 for my $dm (keys %{$CPAN::META->{readwrite}{"CPAN::$class"}}) {
464 next unless $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
465 CPAN->debug("BUG: $class '$dm' was in command state, resetting");
466 delete $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
470 $GOTOSHELL = 0; # not too often
471 $META->savehist if $CPAN::term && $CPAN::term->can("GetHistory");
476 soft_chdir_with_alternatives(\@cwd);
479 #-> CPAN::soft_chdir_with_alternatives ;
480 sub soft_chdir_with_alternatives ($) {
483 my $root = File::Spec->rootdir();
484 $CPAN::Frontend->mywarn(qq{Warning: no good directory to chdir to!
485 Trying '$root' as temporary haven.
490 if (chdir $cwd->[0]) {
494 $CPAN::Frontend->mywarn(qq{Could not chdir to "$cwd->[0]": $!
495 Trying to chdir to "$cwd->[1]" instead.
499 $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd->[0]": $!});
507 if ( $Config::Config{d_flock} || $Config::Config{d_fcntl_can_lock} ) {
508 return flock $fh, $mode;
509 } elsif (!$Have_warned->{"d_flock"}++) {
510 $CPAN::Frontend->mywarn("Your OS does not seem to support locking; continuing and ignoring all locking issues\n");
511 $CPAN::Frontend->mysleep(5);
518 sub _yaml_module () {
519 my $yaml_module = $CPAN::Config->{yaml_module} || "YAML";
521 $yaml_module ne "YAML"
523 !$CPAN::META->has_inst($yaml_module)
525 # $CPAN::Frontend->mywarn("'$yaml_module' not installed, falling back to 'YAML'\n");
526 $yaml_module = "YAML";
528 if ($yaml_module eq "YAML"
530 $CPAN::META->has_inst($yaml_module)
532 $YAML::VERSION < 0.60
534 !$Have_warned->{"YAML"}++
536 $CPAN::Frontend->mywarn("Warning: YAML version '$YAML::VERSION' is too low, please upgrade!\n".
537 "I'll continue but problems are *very* likely to happen.\n"
539 $CPAN::Frontend->mysleep(5);
544 # CPAN::_yaml_loadfile
546 my($self,$local_file) = @_;
547 return +[] unless -s $local_file;
548 my $yaml_module = _yaml_module;
549 if ($CPAN::META->has_inst($yaml_module)) {
550 # temporarly enable yaml code deserialisation
552 # 5.6.2 could not do the local() with the reference
553 # so we do it manually instead
554 my $old_loadcode = ${"$yaml_module\::LoadCode"};
555 ${ "$yaml_module\::LoadCode" } = $CPAN::Config->{yaml_load_code} || 0;
558 if ($code = UNIVERSAL::can($yaml_module, "LoadFile")) {
559 eval { @yaml = $code->($local_file); };
561 # this shall not be done by the frontend
562 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
564 } elsif ($code = UNIVERSAL::can($yaml_module, "Load")) {
566 open FH, $local_file or die "Could not open '$local_file': $!";
569 eval { @yaml = $code->($ystream); };
571 # this shall not be done by the frontend
572 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
575 ${"$yaml_module\::LoadCode"} = $old_loadcode;
578 # this shall not be done by the frontend
579 die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "parse");
584 # CPAN::_yaml_dumpfile
586 my($self,$local_file,@what) = @_;
587 my $yaml_module = _yaml_module;
588 if ($CPAN::META->has_inst($yaml_module)) {
590 if (UNIVERSAL::isa($local_file, "FileHandle")) {
591 $code = UNIVERSAL::can($yaml_module, "Dump");
592 eval { print $local_file $code->(@what) };
593 } elsif ($code = UNIVERSAL::can($yaml_module, "DumpFile")) {
594 eval { $code->($local_file,@what); };
595 } elsif ($code = UNIVERSAL::can($yaml_module, "Dump")) {
597 open FH, ">$local_file" or die "Could not open '$local_file': $!";
598 print FH $code->(@what);
601 die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"dump",$@);
604 if (UNIVERSAL::isa($local_file, "FileHandle")) {
605 # I think this case does not justify a warning at all
607 die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "dump");
612 sub _init_sqlite () {
613 unless ($CPAN::META->has_inst("CPAN::SQLite")) {
614 $CPAN::Frontend->mywarn(qq{CPAN::SQLite not installed, trying to work without\n})
615 unless $Have_warned->{"CPAN::SQLite"}++;
618 require CPAN::SQLite::META; # not needed since CVS version of 2006-12-17
619 $CPAN::SQLite ||= CPAN::SQLite::META->new($CPAN::META);
623 my $negative_cache = {};
624 sub _sqlite_running {
625 if ($negative_cache->{time} && time < $negative_cache->{time} + 60) {
626 # need to cache the result, otherwise too slow
627 return $negative_cache->{fact};
629 $negative_cache = {}; # reset
631 my $ret = $CPAN::Config->{use_sqlite} && ($CPAN::SQLite || _init_sqlite());
632 return $ret if $ret; # fast anyway
633 $negative_cache->{time} = time;
634 return $negative_cache->{fact} = $ret;
638 $META ||= CPAN->new; # In case we re-eval ourselves we need the ||
640 # from here on only subs.
641 ################################################################################
643 sub _perl_fingerprint {
644 my($self,$other_fingerprint) = @_;
645 my $dll = eval {OS2::DLLname()};
648 $mtime_dll = (-f $dll ? (stat(_))[9] : '-1');
650 my $mtime_perl = (-f CPAN::find_perl ? (stat(_))[9] : '-1');
651 my $this_fingerprint = {
652 '$^X' => CPAN::find_perl,
653 sitearchexp => $Config::Config{sitearchexp},
654 'mtime_$^X' => $mtime_perl,
655 'mtime_dll' => $mtime_dll,
657 if ($other_fingerprint) {
658 if (exists $other_fingerprint->{'stat($^X)'}) { # repair fp from rev. 1.88_57
659 $other_fingerprint->{'mtime_$^X'} = $other_fingerprint->{'stat($^X)'}[9];
661 # mandatory keys since 1.88_57
662 for my $key (qw($^X sitearchexp mtime_dll mtime_$^X)) {
663 return unless $other_fingerprint->{$key} eq $this_fingerprint->{$key};
667 return $this_fingerprint;
671 sub suggest_myconfig () {
672 SUGGEST_MYCONFIG: if(!$INC{'CPAN/MyConfig.pm'}) {
673 $CPAN::Frontend->myprint("You don't seem to have a user ".
674 "configuration (MyConfig.pm) yet.\n");
675 my $new = CPAN::Shell::colorable_makemaker_prompt("Do you want to create a ".
676 "user configuration now? (Y/n)",
679 CPAN::Shell->mkmyconfig();
682 $CPAN::Frontend->mydie("OK, giving up.");
687 #-> sub CPAN::all_objects ;
689 my($mgr,$class) = @_;
690 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
691 CPAN->debug("mgr[$mgr] class[$class]") if $CPAN::DEBUG;
693 values %{ $META->{readwrite}{$class} }; # unsafe meta access, ok
696 # Called by shell, not in batch mode. In batch mode I see no risk in
697 # having many processes updating something as installations are
698 # continually checked at runtime. In shell mode I suspect it is
699 # unintentional to open more than one shell at a time
701 #-> sub CPAN::checklock ;
704 my $lockfile = File::Spec->catfile($CPAN::Config->{cpan_home},".lock");
705 if (-f $lockfile && -M _ > 0) {
706 my $fh = FileHandle->new($lockfile) or
707 $CPAN::Frontend->mydie("Could not open lockfile '$lockfile': $!");
708 my $otherpid = <$fh>;
709 my $otherhost = <$fh>;
711 if (defined $otherpid && $otherpid) {
714 if (defined $otherhost && $otherhost) {
717 my $thishost = hostname();
718 if (defined $otherhost && defined $thishost &&
719 $otherhost ne '' && $thishost ne '' &&
720 $otherhost ne $thishost) {
721 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile '$lockfile'\n".
722 "reports other host $otherhost and other ".
723 "process $otherpid.\n".
724 "Cannot proceed.\n"));
725 } elsif ($RUN_DEGRADED) {
726 $CPAN::Frontend->mywarn("Running in downgraded mode (experimental)\n");
727 } elsif (defined $otherpid && $otherpid) {
728 return if $$ == $otherpid; # should never happen
729 $CPAN::Frontend->mywarn(
731 There seems to be running another CPAN process (pid $otherpid). Contacting...
733 if (kill 0, $otherpid or $!{EPERM}) {
734 $CPAN::Frontend->mywarn(qq{Other job is running.\n});
736 CPAN::Shell::colorable_makemaker_prompt
737 (qq{Shall I try to run in downgraded }.
738 qq{mode? (Y/n)},"y");
740 $CPAN::Frontend->mywarn("Running in downgraded mode (experimental).
741 Please report if something unexpected happens\n");
743 for ($CPAN::Config) {
745 # $_->{build_dir_reuse} = 0; # 2006-11-17 akoenig Why was that?
746 $_->{commandnumber_in_prompt} = 0; # visibility
747 $_->{histfile} = ""; # who should win otherwise?
748 $_->{cache_metadata} = 0; # better would be a lock?
749 $_->{use_sqlite} = 0; # better would be a write lock!
750 $_->{auto_commit} = 0; # we are violent, do not persist
751 $_->{test_report} = 0; # Oliver Paukstadt had sent wrong reports in degraded mode
754 $CPAN::Frontend->mydie("
755 You may want to kill the other job and delete the lockfile. On UNIX try:
760 } elsif (-w $lockfile) {
762 CPAN::Shell::colorable_makemaker_prompt
763 (qq{Other job not responding. Shall I overwrite }.
764 qq{the lockfile '$lockfile'? (Y/n)},"y");
765 $CPAN::Frontend->myexit("Ok, bye\n")
766 unless $ans =~ /^y/i;
769 qq{Lockfile '$lockfile' not writable by you. }.
770 qq{Cannot proceed.\n}.
772 qq{ rm '$lockfile'\n}.
773 qq{ and then rerun us.\n}
777 $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Found invalid lockfile ".
778 "'$lockfile', please remove. Cannot proceed.\n"));
781 my $dotcpan = $CPAN::Config->{cpan_home};
782 eval { File::Path::mkpath($dotcpan);};
784 # A special case at least for Jarkko.
789 $symlinkcpan = readlink $dotcpan;
790 die "readlink $dotcpan failed: $!" unless defined $symlinkcpan;
791 eval { File::Path::mkpath($symlinkcpan); };
795 $CPAN::Frontend->mywarn(qq{
796 Working directory $symlinkcpan created.
800 unless (-d $dotcpan) {
802 Your configuration suggests "$dotcpan" as your
803 CPAN.pm working directory. I could not create this directory due
804 to this error: $firsterror\n};
806 As "$dotcpan" is a symlink to "$symlinkcpan",
807 I tried to create that, but I failed with this error: $seconderror
810 Please make sure the directory exists and is writable.
812 $CPAN::Frontend->mywarn($mess);
813 return suggest_myconfig;
815 } # $@ after eval mkpath $dotcpan
816 if (0) { # to test what happens when a race condition occurs
817 for (reverse 1..10) {
823 if (!$RUN_DEGRADED && !$self->{LOCKFH}) {
825 unless ($fh = FileHandle->new("+>>$lockfile")) {
826 if ($! =~ /Permission/) {
827 $CPAN::Frontend->mywarn(qq{
829 Your configuration suggests that CPAN.pm should use a working
831 $CPAN::Config->{cpan_home}
832 Unfortunately we could not create the lock file
834 due to permission problems.
836 Please make sure that the configuration variable
837 \$CPAN::Config->{cpan_home}
838 points to a directory where you can write a .lock file. You can set
839 this variable in either a CPAN/MyConfig.pm or a CPAN/Config.pm in your
842 return suggest_myconfig;
846 while (!CPAN::_flock($fh, LOCK_EX|LOCK_NB)) {
848 $CPAN::Frontend->mydie("Giving up\n");
850 $CPAN::Frontend->mysleep($sleep++);
851 $CPAN::Frontend->mywarn("Could not lock lockfile with flock: $!; retrying\n");
857 $fh->print($$, "\n");
858 $fh->print(hostname(), "\n");
859 $self->{LOCK} = $lockfile;
860 $self->{LOCKFH} = $fh;
865 $CPAN::Frontend->mydie("Got SIG$sig, leaving");
871 die "Got yet another signal" if $Signal > 1;
872 $CPAN::Frontend->mydie("Got another SIG$sig") if $Signal;
873 $CPAN::Frontend->mywarn("Caught SIG$sig, trying to continue\n");
877 # From: Larry Wall <larry@wall.org>
878 # Subject: Re: deprecating SIGDIE
879 # To: perl5-porters@perl.org
880 # Date: Thu, 30 Sep 1999 14:58:40 -0700 (PDT)
882 # The original intent of __DIE__ was only to allow you to substitute one
883 # kind of death for another on an application-wide basis without respect
884 # to whether you were in an eval or not. As a global backstop, it should
885 # not be used any more lightly (or any more heavily :-) than class
886 # UNIVERSAL. Any attempt to build a general exception model on it should
887 # be politely squashed. Any bug that causes every eval {} to have to be
888 # modified should be not so politely squashed.
890 # Those are my current opinions. It is also my optinion that polite
891 # arguments degenerate to personal arguments far too frequently, and that
892 # when they do, it's because both people wanted it to, or at least didn't
893 # sufficiently want it not to.
897 # global backstop to cleanup if we should really die
898 $SIG{__DIE__} = \&cleanup;
899 $self->debug("Signal handler set.") if $CPAN::DEBUG;
902 #-> sub CPAN::DESTROY ;
904 &cleanup; # need an eval?
907 #-> sub CPAN::anycwd ;
910 $getcwd = $CPAN::Config->{'getcwd'} || 'cwd';
915 sub cwd {Cwd::cwd();}
917 #-> sub CPAN::getcwd ;
918 sub getcwd {Cwd::getcwd();}
920 #-> sub CPAN::fastcwd ;
921 sub fastcwd {Cwd::fastcwd();}
923 #-> sub CPAN::backtickcwd ;
924 sub backtickcwd {my $cwd = `cwd`; chomp $cwd; $cwd}
926 #-> sub CPAN::find_perl ;
928 my($perl) = File::Spec->file_name_is_absolute($^X) ? $^X : "";
930 my $candidate = File::Spec->catfile($CPAN::iCwd,$^X);
931 $^X = $perl = $candidate if MM->maybe_command($candidate);
934 my ($component,$perl_name);
935 DIST_PERLNAME: foreach $perl_name ($^X, 'perl', 'perl5', "perl$]") {
936 PATH_COMPONENT: foreach $component (File::Spec->path(),
937 $Config::Config{'binexp'}) {
938 next unless defined($component) && $component;
939 my($abs) = File::Spec->catfile($component,$perl_name);
940 if (MM->maybe_command($abs)) {
951 #-> sub CPAN::exists ;
953 my($mgr,$class,$id) = @_;
954 CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
956 ### Carp::croak "exists called without class argument" unless $class;
958 $id =~ s/:+/::/g if $class eq "CPAN::Module";
960 if (CPAN::_sqlite_running) {
961 $exists = (exists $META->{readonly}{$class}{$id} or
962 $CPAN::SQLite->set($class, $id));
964 $exists = exists $META->{readonly}{$class}{$id};
966 $exists ||= exists $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
969 #-> sub CPAN::delete ;
971 my($mgr,$class,$id) = @_;
972 delete $META->{readonly}{$class}{$id}; # unsafe meta access, ok
973 delete $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
976 #-> sub CPAN::has_usable
977 # has_inst is sometimes too optimistic, we should replace it with this
978 # has_usable whenever a case is given
980 my($self,$mod,$message) = @_;
981 return 1 if $HAS_USABLE->{$mod};
982 my $has_inst = $self->has_inst($mod,$message);
983 return unless $has_inst;
988 # these subroutines die if they believe the installed version is unusable;
991 LWP => [ # we frequently had "Can't locate object
992 # method "new" via package "LWP::UserAgent" at
993 # (eval 69) line 2006
995 sub {require LWP::UserAgent},
996 sub {require HTTP::Request},
997 sub {require URI::URL;
998 unless (CPAN::Version->vge(URI::URL::->VERSION,0.08)) {
999 for ("Will not use URI::URL, need 0.08\n") {
1000 $CPAN::Frontend->mywarn($_);
1007 sub {require Net::FTP},
1008 sub {require Net::Config},
1010 'File::HomeDir' => [
1011 sub {require File::HomeDir;
1012 unless (CPAN::Version->vge(File::HomeDir::->VERSION, 0.52)) {
1013 for ("Will not use File::HomeDir, need 0.52\n") {
1014 $CPAN::Frontend->mywarn($_);
1021 sub {require Archive::Tar;
1022 my $demand = "1.50";
1023 unless (CPAN::Version->vge(Archive::Tar::->VERSION, $demand)) {
1024 my $atv = Archive::Tar->VERSION;
1025 for ("You have Archive::Tar $atv, but $demand or later is recommended. Please upgrade.\n") {
1026 $CPAN::Frontend->mywarn($_);
1027 # don't die, because we may need
1028 # Archive::Tar to upgrade
1035 # XXX we should probably delete from
1036 # %INC too so we can load after we
1037 # installed a new enough version --
1039 sub {require File::Temp;
1040 unless (CPAN::Version->vge(File::Temp::->VERSION,0.16)) {
1041 for ("Will not use File::Temp, need 0.16\n") {
1042 $CPAN::Frontend->mywarn($_);
1049 if ($usable->{$mod}) {
1050 for my $c (0..$#{$usable->{$mod}}) {
1051 my $code = $usable->{$mod}[$c];
1052 my $ret = eval { &$code() };
1053 $ret = "" unless defined $ret;
1055 # warn "DEBUG: c[$c]\$\@[$@]ret[$ret]";
1060 return $HAS_USABLE->{$mod} = 1;
1063 #-> sub CPAN::has_inst
1065 my($self,$mod,$message) = @_;
1066 Carp::croak("CPAN->has_inst() called without an argument")
1067 unless defined $mod;
1068 my %dont = map { $_ => 1 } keys %{$CPAN::META->{dontload_hash}||{}},
1069 keys %{$CPAN::Config->{dontload_hash}||{}},
1070 @{$CPAN::Config->{dontload_list}||[]};
1071 if (defined $message && $message eq "no" # afair only used by Nox
1075 $CPAN::META->{dontload_hash}{$mod}||=1; # unsafe meta access, ok
1083 # checking %INC is wrong, because $INC{LWP} may be true
1084 # although $INC{"URI/URL.pm"} may have failed. But as
1085 # I really want to say "bla loaded OK", I have to somehow
1087 ### warn "$file in %INC"; #debug
1089 } elsif (eval { require $file }) {
1090 # eval is good: if we haven't yet read the database it's
1091 # perfect and if we have installed the module in the meantime,
1092 # it tries again. The second require is only a NOOP returning
1093 # 1 if we had success, otherwise it's retrying
1095 my $mtime = (stat $INC{$file})[9];
1096 # privileged files loaded by has_inst; Note: we use $mtime
1097 # as a proxy for a checksum.
1098 $CPAN::Shell::reload->{$file} = $mtime;
1099 my $v = eval "\$$mod\::VERSION";
1100 $v = $v ? " (v$v)" : "";
1101 CPAN::Shell->optprint("load_module","CPAN: $mod loaded ok$v\n");
1102 if ($mod eq "CPAN::WAIT") {
1103 push @CPAN::Shell::ISA, 'CPAN::WAIT';
1106 } elsif ($mod eq "Net::FTP") {
1107 $CPAN::Frontend->mywarn(qq{
1108 Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
1110 install Bundle::libnet
1112 }) unless $Have_warned->{"Net::FTP"}++;
1113 $CPAN::Frontend->mysleep(3);
1114 } elsif ($mod eq "Digest::SHA") {
1115 if ($Have_warned->{"Digest::SHA"}++) {
1116 $CPAN::Frontend->mywarn(qq{CPAN: checksum security checks disabled }.
1117 qq{because Digest::SHA not installed.\n});
1119 $CPAN::Frontend->mywarn(qq{
1120 CPAN: checksum security checks disabled because Digest::SHA not installed.
1121 Please consider installing the Digest::SHA module.
1124 $CPAN::Frontend->mysleep(2);
1126 } elsif ($mod eq "Module::Signature") {
1127 # NOT prefs_lookup, we are not a distro
1128 my $check_sigs = $CPAN::Config->{check_sigs};
1129 if (not $check_sigs) {
1130 # they do not want us:-(
1131 } elsif (not $Have_warned->{"Module::Signature"}++) {
1132 # No point in complaining unless the user can
1133 # reasonably install and use it.
1134 if (eval { require Crypt::OpenPGP; 1 } ||
1136 defined $CPAN::Config->{'gpg'}
1138 $CPAN::Config->{'gpg'} =~ /\S/
1141 $CPAN::Frontend->mywarn(qq{
1142 CPAN: Module::Signature security checks disabled because Module::Signature
1143 not installed. Please consider installing the Module::Signature module.
1144 You may also need to be able to connect over the Internet to the public
1145 keyservers like pgp.mit.edu (port 11371).
1148 $CPAN::Frontend->mysleep(2);
1152 delete $INC{$file}; # if it inc'd LWP but failed during, say, URI
1157 #-> sub CPAN::instance ;
1159 my($mgr,$class,$id) = @_;
1160 CPAN::Index->reload;
1162 # unsafe meta access, ok?
1163 return $META->{readwrite}{$class}{$id} if exists $META->{readwrite}{$class}{$id};
1164 $META->{readwrite}{$class}{$id} ||= $class->new(ID => $id);
1172 #-> sub CPAN::cleanup ;
1174 # warn "cleanup called with arg[@_] End[$CPAN::End] Signal[$Signal]";
1175 local $SIG{__DIE__} = '';
1180 while ((undef,undef,undef,$subroutine) = caller(++$i)) {
1181 $ineval = 1, last if
1182 $subroutine eq '(eval)';
1184 return if $ineval && !$CPAN::End;
1185 return unless defined $META->{LOCK};
1186 return unless -f $META->{LOCK};
1188 close $META->{LOCKFH};
1189 unlink $META->{LOCK};
1191 # Carp::cluck("DEBUGGING");
1192 if ( $CPAN::CONFIG_DIRTY ) {
1193 $CPAN::Frontend->mywarn("Warning: Configuration not saved.\n");
1195 $CPAN::Frontend->myprint("Lockfile removed.\n");
1198 #-> sub CPAN::readhist
1200 my($self,$term,$histfile) = @_;
1201 my $histsize = $CPAN::Config->{'histsize'} || 100;
1202 $term->Attribs->{'MaxHistorySize'} = $histsize if (defined($term->Attribs->{'MaxHistorySize'}));
1203 my($fh) = FileHandle->new;
1204 open $fh, "<$histfile" or return;
1208 $term->AddHistory($_);
1213 #-> sub CPAN::savehist
1216 my($histfile,$histsize);
1217 unless ($histfile = $CPAN::Config->{'histfile'}) {
1218 $CPAN::Frontend->mywarn("No history written (no histfile specified).\n");
1221 $histsize = $CPAN::Config->{'histsize'} || 100;
1223 unless ($CPAN::term->can("GetHistory")) {
1224 $CPAN::Frontend->mywarn("Terminal does not support GetHistory.\n");
1230 my @h = $CPAN::term->GetHistory;
1231 splice @h, 0, @h-$histsize if @h>$histsize;
1232 my($fh) = FileHandle->new;
1233 open $fh, ">$histfile" or $CPAN::Frontend->mydie("Couldn't open >$histfile: $!");
1234 local $\ = local $, = "\n";
1239 #-> sub CPAN::is_tested
1241 my($self,$what,$when) = @_;
1243 Carp::cluck("DEBUG: empty what");
1246 $self->{is_tested}{$what} = $when;
1249 #-> sub CPAN::reset_tested
1250 # forget all distributions tested -- resets what gets included in PERL5LIB
1253 $self->{is_tested} = {};
1256 #-> sub CPAN::is_installed
1257 # unsets the is_tested flag: as soon as the thing is installed, it is
1258 # not needed in set_perl5lib anymore
1260 my($self,$what) = @_;
1261 delete $self->{is_tested}{$what};
1264 sub _list_sorted_descending_is_tested {
1267 { ($self->{is_tested}{$b}||0) <=> ($self->{is_tested}{$a}||0) }
1268 keys %{$self->{is_tested}}
1271 #-> sub CPAN::set_perl5lib
1272 # Notes on max environment variable length:
1273 # - Win32 : XP or later, 8191; Win2000 or NT4, 2047
1277 my($self,$for) = @_;
1279 (undef,undef,undef,$for) = caller(1);
1282 $self->{is_tested} ||= {};
1283 return unless %{$self->{is_tested}};
1284 my $env = $ENV{PERL5LIB};
1285 $env = $ENV{PERLLIB} unless defined $env;
1287 push @env, split /\Q$Config::Config{path_sep}\E/, $env if defined $env and length $env;
1288 #my @dirs = map {("$_/blib/arch", "$_/blib/lib")} keys %{$self->{is_tested}};
1289 #$CPAN::Frontend->myprint("Prepending @dirs to PERL5LIB.\n");
1291 my @dirs = map {("$_/blib/arch", "$_/blib/lib")} $self->_list_sorted_descending_is_tested;
1295 $CPAN::Frontend->optprint('perl5lib', "Prepending @dirs to PERL5LIB for '$for'\n");
1296 $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1297 } elsif (@dirs < 24 ) {
1298 my @d = map {my $cp = $_;
1299 $cp =~ s/^\Q$CPAN::Config->{build_dir}\E/%BUILDDIR%/;
1302 $CPAN::Frontend->optprint('perl5lib', "Prepending @d to PERL5LIB; ".
1303 "%BUILDDIR%=$CPAN::Config->{build_dir} ".
1306 $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1308 my $cnt = keys %{$self->{is_tested}};
1309 $CPAN::Frontend->optprint('perl5lib', "Prepending blib/arch and blib/lib of ".
1310 "$cnt build dirs to PERL5LIB; ".
1313 $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1325 CPAN - query, download and build perl modules from CPAN sites
1331 perl -MCPAN -e shell
1341 cpan> install Acme::Meta # in the shell
1343 CPAN::Shell->install("Acme::Meta"); # in perl
1347 cpan> install NWCLARK/Acme-Meta-0.02.tar.gz # in the shell
1350 install("NWCLARK/Acme-Meta-0.02.tar.gz"); # in perl
1354 $mo = CPAN::Shell->expandany($mod);
1355 $mo = CPAN::Shell->expand("Module",$mod); # same thing
1357 # distribution objects:
1359 $do = CPAN::Shell->expand("Module",$mod)->distribution;
1360 $do = CPAN::Shell->expandany($distro); # same thing
1361 $do = CPAN::Shell->expand("Distribution",
1362 $distro); # same thing
1366 The CPAN module automates or at least simplifies the make and install
1367 of perl modules and extensions. It includes some primitive searching
1368 capabilities and knows how to use Net::FTP, LWP, and certain external
1369 download clients to fetch distributions from the net.
1371 These are fetched from one or more mirrored CPAN (Comprehensive
1372 Perl Archive Network) sites and unpacked in a dedicated directory.
1374 The CPAN module also supports named and versioned
1375 I<bundles> of modules. Bundles simplify handling of sets of
1376 related modules. See Bundles below.
1378 The package contains a session manager and a cache manager. The
1379 session manager keeps track of what has been fetched, built, and
1380 installed in the current session. The cache manager keeps track of the
1381 disk space occupied by the make processes and deletes excess space
1382 using a simple FIFO mechanism.
1384 All methods provided are accessible in a programmer style and in an
1385 interactive shell style.
1387 =head2 CPAN::shell([$prompt, $command]) Starting Interactive Mode
1389 Enter interactive mode by running
1391 perl -MCPAN -e shell
1397 which puts you into a readline interface. If C<Term::ReadKey> and
1398 either of C<Term::ReadLine::Perl> or C<Term::ReadLine::Gnu> are installed,
1399 history and command completion are supported.
1401 Once at the command line, type C<h> for one-page help
1402 screen; the rest should be self-explanatory.
1404 The function call C<shell> takes two optional arguments: one the
1405 prompt, the second the default initial command line (the latter
1406 only works if a real ReadLine interface module is installed).
1408 The most common uses of the interactive modes are
1412 =item Searching for authors, bundles, distribution files and modules
1414 There are corresponding one-letter commands C<a>, C<b>, C<d>, and C<m>
1415 for each of the four categories and another, C<i> for any of the
1416 mentioned four. Each of the four entities is implemented as a class
1417 with slightly differing methods for displaying an object.
1419 Arguments to these commands are either strings exactly matching
1420 the identification string of an object, or regular expressions
1421 matched case-insensitively against various attributes of the
1422 objects. The parser only recognizes a regular expression when you
1423 enclose it with slashes.
1425 The principle is that the number of objects found influences how an
1426 item is displayed. If the search finds one item, the result is
1427 displayed with the rather verbose method C<as_string>, but if
1428 more than one is found, each object is displayed with the terse method
1433 cpan> m Acme::MetaSyntactic
1434 Module id = Acme::MetaSyntactic
1435 CPAN_USERID BOOK (Philippe Bruhat (BooK) <[...]>)
1437 CPAN_FILE B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
1438 UPLOAD_DATE 2006-11-06
1439 MANPAGE Acme::MetaSyntactic - Themed metasyntactic variables names
1440 INST_FILE /usr/local/lib/perl/5.10.0/Acme/MetaSyntactic.pm
1445 FULLNAME Philippe Bruhat (BooK)
1446 cpan> d BOOK/Acme-MetaSyntactic-0.99.tar.gz
1447 Distribution id = B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
1448 CPAN_USERID BOOK (Philippe Bruhat (BooK) <[...]>)
1449 CONTAINSMODS Acme::MetaSyntactic Acme::MetaSyntactic::Alias [...]
1450 UPLOAD_DATE 2006-11-06
1452 Module = Acme::MetaSyntactic::loremipsum (BOOK/Acme-MetaSyntactic-0.99.tar.gz)
1453 Module Text::Lorem (ADEOLA/Text-Lorem-0.3.tar.gz)
1454 Module Text::Lorem::More (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
1455 Module Text::Lorem::More::Source (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
1457 Distribution BEATNIK/Filter-NumberLines-0.02.tar.gz
1458 Module = DateTime::TimeZone::Europe::Berlin (DROLSKY/DateTime-TimeZone-0.7904.tar.gz)
1459 Module Filter::NumberLines (BEATNIK/Filter-NumberLines-0.02.tar.gz)
1462 The examples illustrate several aspects: the first three queries
1463 target modules, authors, or distros directly and yield exactly one
1464 result. The last two use regular expressions and yield several
1465 results. The last one targets all of bundles, modules, authors, and
1466 distros simultaneously. When more than one result is available, they
1467 are printed in one-line format.
1469 =item C<get>, C<make>, C<test>, C<install>, C<clean> modules or distributions
1471 These commands take any number of arguments and investigate what is
1472 necessary to perform the action. Argument processing is as follows:
1474 known module name in format Foo/Bar.pm module
1475 other embedded slash distribution
1476 - with trailing slash dot directory
1477 enclosing slashes regexp
1478 known module name in format Foo::Bar module
1480 If the argument is a distribution file name (recognized by embedded
1481 slashes), it is processed. If it is a module, CPAN determines the
1482 distribution file in which this module is included and processes that,
1483 following any dependencies named in the module's META.yml or
1484 Makefile.PL (this behavior is controlled by the configuration
1485 parameter C<prerequisites_policy>). If an argument is enclosed in
1486 slashes it is treated as a regular expression: it is expanded and if
1487 the result is a single object (distribution, bundle or module), this
1488 object is processed.
1492 install Dummy::Perl # installs the module
1493 install AUXXX/Dummy-Perl-3.14.tar.gz # installs that distribution
1494 install /Dummy-Perl-3.14/ # same if the regexp is unambiguous
1496 C<get> downloads a distribution file and untars or unzips it, C<make>
1497 builds it, C<test> runs the test suite, and C<install> installs it.
1499 Any C<make> or C<test> is run unconditionally. An
1501 install <distribution_file>
1503 is also run unconditionally. But for
1507 CPAN checks whether an install is needed and prints
1508 I<module up to date> if the distribution file containing
1509 the module doesn't need updating.
1511 CPAN also keeps track of what it has done within the current session
1512 and doesn't try to build a package a second time regardless of whether it
1513 succeeded or not. It does not repeat a test run if the test
1514 has been run successfully before. Same for install runs.
1516 The C<force> pragma may precede another command (currently: C<get>,
1517 C<make>, C<test>, or C<install>) to execute the command from scratch
1518 and attempt to continue past certain errors. See the section below on
1519 the C<force> and the C<fforce> pragma.
1521 The C<notest> pragma skips the test part in the build
1526 cpan> notest install Tk
1528 A C<clean> command results in a
1532 being executed within the distribution file's working directory.
1534 =item C<readme>, C<perldoc>, C<look> module or distribution
1536 C<readme> displays the README file of the associated distribution.
1537 C<Look> gets and untars (if not yet done) the distribution file,
1538 changes to the appropriate directory and opens a subshell process in
1539 that directory. C<perldoc> displays the module's pod documentation
1540 in html or plain text format.
1544 =item C<ls> globbing_expression
1546 The first form lists all distribution files in and below an author's
1547 CPAN directory as stored in the CHECKUMS files distributed on
1548 CPAN. The listing recurses into subdirectories.
1550 The second form limits or expands the output with shell
1551 globbing as in the following examples:
1557 The last example is very slow and outputs extra progress indicators
1558 that break the alignment of the result.
1560 Note that globbing only lists directories explicitly asked for, for
1561 example FOO/* will not list FOO/bar/Acme-Sthg-n.nn.tar.gz. This may be
1562 regarded as a bug that may be changed in some future version.
1566 The C<failed> command reports all distributions that failed on one of
1567 C<make>, C<test> or C<install> for some reason in the currently
1568 running shell session.
1570 =item Persistence between sessions
1572 If the C<YAML> or the C<YAML::Syck> module is installed a record of
1573 the internal state of all modules is written to disk after each step.
1574 The files contain a signature of the currently running perl version
1577 If the configurations variable C<build_dir_reuse> is set to a true
1578 value, then CPAN.pm reads the collected YAML files. If the stored
1579 signature matches the currently running perl, the stored state is
1580 loaded into memory such that persistence between sessions
1581 is effectively established.
1583 =item The C<force> and the C<fforce> pragma
1585 To speed things up in complex installation scenarios, CPAN.pm keeps
1586 track of what it has already done and refuses to do some things a
1587 second time. A C<get>, a C<make>, and an C<install> are not repeated.
1588 A C<test> is repeated only if the previous test was unsuccessful. The
1589 diagnostic message when CPAN.pm refuses to do something a second time
1590 is one of I<Has already been >C<unwrapped|made|tested successfully> or
1591 something similar. Another situation where CPAN refuses to act is an
1592 C<install> if the corresponding C<test> was not successful.
1594 In all these cases, the user can override this stubborn behaviour by
1595 prepending the command with the word force, for example:
1598 cpan> force make AUTHOR/Bar-3.14.tar.gz
1599 cpan> force test Baz
1600 cpan> force install Acme::Meta
1602 Each I<forced> command is executed with the corresponding part of its
1605 The C<fforce> pragma is a variant that emulates a C<force get> which
1606 erases the entire memory followed by the action specified, effectively
1607 restarting the whole get/make/test/install procedure from scratch.
1611 Interactive sessions maintain a lockfile, by default C<~/.cpan/.lock>.
1612 Batch jobs can run without a lockfile and not disturb each other.
1614 The shell offers to run in I<downgraded mode> when another process is
1615 holding the lockfile. This is an experimental feature that is not yet
1616 tested very well. This second shell then does not write the history
1617 file, does not use the metadata file, and has a different prompt.
1621 CPAN.pm installs signal handlers for SIGINT and SIGTERM. While you are
1622 in the cpan-shell, it is intended that you can press C<^C> anytime and
1623 return to the cpan-shell prompt. A SIGTERM will cause the cpan-shell
1624 to clean up and leave the shell loop. You can emulate the effect of a
1625 SIGTERM by sending two consecutive SIGINTs, which usually means by
1626 pressing C<^C> twice.
1628 CPAN.pm ignores SIGPIPE. If the user sets C<inactivity_timeout>, a
1629 SIGALRM is used during the run of the C<perl Makefile.PL> or C<perl
1630 Build.PL> subprocess. A SIGALRM is also used during module version
1631 parsing, and is controlled by C<version_timeout>.
1637 The commands available in the shell interface are methods in
1638 the package CPAN::Shell. If you enter the shell command, your
1639 input is split by the Text::ParseWords::shellwords() routine, which
1640 acts like most shells do. The first word is interpreted as the
1641 method to be invoked, and the rest of the words are treated as the method's arguments.
1642 Continuation lines are supported by ending a line with a
1647 C<autobundle> writes a bundle file into the
1648 C<$CPAN::Config-E<gt>{cpan_home}/Bundle> directory. The file contains
1649 a list of all modules that are both available from CPAN and currently
1650 installed within @INC. The name of the bundle file is based on the
1651 current date and a counter.
1655 Note: this feature is still in alpha state and may change in future
1658 This commands provides a statistical overview over recent download
1659 activities. The data for this is collected in the YAML file
1660 C<FTPstats.yml> in your C<cpan_home> directory. If no YAML module is
1661 configured or YAML not installed, no stats are provided.
1665 mkmyconfig() writes your own CPAN::MyConfig file into your C<~/.cpan/>
1666 directory so that you can save your own preferences instead of the
1669 =head2 recent ***EXPERIMENTAL COMMAND***
1671 The C<recent> command downloads a list of recent uploads to CPAN and
1672 displays them I<slowly>. While the command is running, a $SIG{INT}
1673 exits the loop after displaying the current item.
1675 B<Note>: This command requires XML::LibXML installed.
1677 B<Note>: This whole command currently is just a hack and will
1678 probably change in future versions of CPAN.pm, but the general
1679 approach will likely remain.
1681 B<Note>: See also L<smoke>
1685 recompile() is a special command that takes no argument and
1686 runs the make/test/install cycle with brute force over all installed
1687 dynamically loadable extensions (aka XS modules) with 'force' in
1688 effect. The primary purpose of this command is to finish a network
1689 installation. Imagine you have a common source tree for two different
1690 architectures. You decide to do a completely independent fresh
1691 installation. You start on one architecture with the help of a Bundle
1692 file produced earlier. CPAN installs the whole Bundle for you, but
1693 when you try to repeat the job on the second architecture, CPAN
1694 responds with a C<"Foo up to date"> message for all modules. So you
1695 invoke CPAN's recompile on the second architecture and you're done.
1697 Another popular use for C<recompile> is to act as a rescue in case your
1698 perl breaks binary compatibility. If one of the modules that CPAN uses
1699 is in turn depending on binary compatibility (so you cannot run CPAN
1700 commands), then you should try the CPAN::Nox module for recovery.
1702 =head2 report Bundle|Distribution|Module
1704 The C<report> command temporarily turns on the C<test_report> config
1705 variable, then runs the C<force test> command with the given
1706 arguments. The C<force> pragma reruns the tests and repeats
1707 every step that might have failed before.
1709 =head2 smoke ***EXPERIMENTAL COMMAND***
1711 B<*** WARNING: this command downloads and executes software from CPAN to
1712 your computer of completely unknown status. You should never do
1713 this with your normal account and better have a dedicated well
1714 separated and secured machine to do this. ***>
1716 The C<smoke> command takes the list of recent uploads to CPAN as
1717 provided by the C<recent> command and tests them all. While the
1718 command is running $SIG{INT} is defined to mean that the current item
1721 B<Note>: This whole command currently is just a hack and will
1722 probably change in future versions of CPAN.pm, but the general
1723 approach will likely remain.
1725 B<Note>: See also L<recent>
1727 =head2 upgrade [Module|/Regex/]...
1729 The C<upgrade> command first runs an C<r> command with the given
1730 arguments and then installs the newest versions of all modules that
1731 were listed by that.
1733 =head2 The four C<CPAN::*> Classes: Author, Bundle, Module, Distribution
1735 Although it may be considered internal, the class hierarchy does matter
1736 for both users and programmer. CPAN.pm deals with the four
1737 classes mentioned above, and those classes all share a set of methods. Classical
1738 single polymorphism is in effect. A metaclass object registers all
1739 objects of all kinds and indexes them with a string. The strings
1740 referencing objects have a separated namespace (well, not completely
1745 words containing a "/" (slash) Distribution
1746 words starting with Bundle:: Bundle
1747 everything else Module or Author
1749 Modules know their associated Distribution objects. They always refer
1750 to the most recent official release. Developers may mark their releases
1751 as unstable development versions (by inserting an underbar into the
1752 module version number which will also be reflected in the distribution
1753 name when you run 'make dist'), so the really hottest and newest
1754 distribution is not always the default. If a module Foo circulates
1755 on CPAN in both version 1.23 and 1.23_90, CPAN.pm offers a convenient
1756 way to install version 1.23 by saying
1760 This would install the complete distribution file (say
1761 BAR/Foo-1.23.tar.gz) with all accompanying material. But if you would
1762 like to install version 1.23_90, you need to know where the
1763 distribution file resides on CPAN relative to the authors/id/
1764 directory. If the author is BAR, this might be BAR/Foo-1.23_90.tar.gz;
1765 so you would have to say
1767 install BAR/Foo-1.23_90.tar.gz
1769 The first example will be driven by an object of the class
1770 CPAN::Module, the second by an object of class CPAN::Distribution.
1772 =head2 Integrating local directories
1774 Note: this feature is still in alpha state and may change in future
1777 Distribution objects are normally distributions from the CPAN, but
1778 there is a slightly degenerate case for Distribution objects, too, of
1779 projects held on the local disk. These distribution objects have the
1780 same name as the local directory and end with a dot. A dot by itself
1781 is also allowed for the current directory at the time CPAN.pm was
1782 used. All actions such as C<make>, C<test>, and C<install> are applied
1783 directly to that directory. This gives the command C<cpan .> an
1784 interesting touch: while the normal mantra of installing a CPAN module
1785 without CPAN.pm is one of
1787 perl Makefile.PL perl Build.PL
1788 ( go and get prerequisites )
1790 make test ./Build test
1791 make install ./Build install
1793 the command C<cpan .> does all of this at once. It figures out which
1794 of the two mantras is appropriate, fetches and installs all
1795 prerequisites, takes care of them recursively, and finally finishes the
1796 installation of the module in the current directory, be it a CPAN
1799 The typical usage case is for private modules or working copies of
1800 projects from remote repositories on the local disk.
1804 The usual shell redirection symbols C< | > and C<< > >> are recognized
1805 by the cpan shell B<only when surrounded by whitespace>. So piping to
1806 pager or redirecting output into a file works somewhat as in a normal
1807 shell, with the stipulation that you must type extra spaces.
1809 =head1 CONFIGURATION
1811 When the CPAN module is used for the first time, a configuration
1812 dialogue tries to determine a couple of site specific options. The
1813 result of the dialog is stored in a hash reference C< $CPAN::Config >
1814 in a file CPAN/Config.pm.
1816 Default values defined in the CPAN/Config.pm file can be
1817 overridden in a user specific file: CPAN/MyConfig.pm. Such a file is
1818 best placed in C<$HOME/.cpan/CPAN/MyConfig.pm>, because C<$HOME/.cpan> is
1819 added to the search path of the CPAN module before the use() or
1820 require() statements. The mkmyconfig command writes this file for you.
1822 The C<o conf> command has various bells and whistles:
1826 =item completion support
1828 If you have a ReadLine module installed, you can hit TAB at any point
1829 of the commandline and C<o conf> will offer you completion for the
1830 built-in subcommands and/or config variable names.
1832 =item displaying some help: o conf help
1834 Displays a short help
1836 =item displaying current values: o conf [KEY]
1838 Displays the current value(s) for this config variable. Without KEY,
1839 displays all subcommands and config variables.
1845 If KEY starts and ends with a slash, the string in between is
1846 treated as a regular expression and only keys matching this regex
1853 =item changing of scalar values: o conf KEY VALUE
1855 Sets the config variable KEY to VALUE. The empty string can be
1856 specified as usual in shells, with C<''> or C<"">
1860 o conf wget /usr/bin/wget
1862 =item changing of list values: o conf KEY SHIFT|UNSHIFT|PUSH|POP|SPLICE|LIST
1864 If a config variable name ends with C<list>, it is a list. C<o conf
1865 KEY shift> removes the first element of the list, C<o conf KEY pop>
1866 removes the last element of the list. C<o conf KEYS unshift LIST>
1867 prepends a list of values to the list, C<o conf KEYS push LIST>
1868 appends a list of valued to the list.
1870 Likewise, C<o conf KEY splice LIST> passes the LIST to the corresponding
1873 Finally, any other list of arguments is taken as a new list value for
1874 the KEY variable discarding the previous value.
1878 o conf urllist unshift http://cpan.dev.local/CPAN
1879 o conf urllist splice 3 1
1880 o conf urllist http://cpan1.local http://cpan2.local ftp://ftp.perl.org
1882 =item reverting to saved: o conf defaults
1884 Reverts all config variables to the state in the saved config file.
1886 =item saving the config: o conf commit
1888 Saves all config variables to the current config file (CPAN/Config.pm
1889 or CPAN/MyConfig.pm that was loaded at start).
1893 The configuration dialog can be started any time later again by
1894 issuing the command C< o conf init > in the CPAN shell. A subset of
1895 the configuration dialog can be run by issuing C<o conf init WORD>
1896 where WORD is any valid config variable or a regular expression.
1898 =head2 Config Variables
1900 The following keys in the hash reference $CPAN::Config are
1903 applypatch path to external prg
1904 auto_commit commit all changes to config variables to disk
1905 build_cache size of cache for directories to build modules
1906 build_dir locally accessible directory to build modules
1907 build_dir_reuse boolean if distros in build_dir are persistent
1908 build_requires_install_policy
1909 to install or not to install when a module is
1910 only needed for building. yes|no|ask/yes|ask/no
1911 bzip2 path to external prg
1912 cache_metadata use serializer to cache metadata
1913 check_sigs if signatures should be verified
1914 colorize_debug Term::ANSIColor attributes for debugging output
1915 colorize_output boolean if Term::ANSIColor should colorize output
1916 colorize_print Term::ANSIColor attributes for normal output
1917 colorize_warn Term::ANSIColor attributes for warnings
1918 commandnumber_in_prompt
1919 boolean if you want to see current command number
1920 commands_quote preferred character to use for quoting external
1921 commands when running them. Defaults to double
1922 quote on Windows, single tick everywhere else;
1923 can be set to space to disable quoting
1924 connect_to_internet_ok
1925 whether to ask if opening a connection is ok before
1926 urllist is specified
1927 cpan_home local directory reserved for this package
1928 curl path to external prg
1929 dontload_hash DEPRECATED
1930 dontload_list arrayref: modules in the list will not be
1931 loaded by the CPAN::has_inst() routine
1932 ftp path to external prg
1933 ftp_passive if set, the envariable FTP_PASSIVE is set for downloads
1934 ftp_proxy proxy host for ftp requests
1935 ftpstats_period max number of days to keep download statistics
1936 ftpstats_size max number of items to keep in the download statistics
1938 gpg path to external prg
1939 gzip location of external program gzip
1940 halt_on_failure stop processing after the first failure of queued
1941 items or dependencies
1942 histfile file to maintain history between sessions
1943 histsize maximum number of lines to keep in histfile
1944 http_proxy proxy host for http requests
1945 inactivity_timeout breaks interactive Makefile.PLs or Build.PLs
1946 after this many seconds inactivity. Set to 0 to
1948 index_expire refetch index files after this many days
1949 inhibit_startup_message
1950 if true, suppress the startup message
1951 keep_source_where directory in which to keep the source (if we do)
1952 load_module_verbosity
1953 report loading of optional modules used by CPAN.pm
1954 lynx path to external prg
1955 make location of external make program
1956 make_arg arguments that should always be passed to 'make'
1957 make_install_make_command
1958 the make command for running 'make install', for
1960 make_install_arg same as make_arg for 'make install'
1961 makepl_arg arguments passed to 'perl Makefile.PL'
1962 mbuild_arg arguments passed to './Build'
1963 mbuild_install_arg arguments passed to './Build install'
1964 mbuild_install_build_command
1965 command to use instead of './Build' when we are
1966 in the install stage, for example 'sudo ./Build'
1967 mbuildpl_arg arguments passed to 'perl Build.PL'
1968 ncftp path to external prg
1969 ncftpget path to external prg
1970 no_proxy don't proxy to these hosts/domains (comma separated list)
1971 pager location of external program more (or any pager)
1972 password your password if you CPAN server wants one
1973 patch path to external prg
1974 patches_dir local directory containing patch files
1975 perl5lib_verbosity verbosity level for PERL5LIB additions
1976 prefer_installer legal values are MB and EUMM: if a module comes
1977 with both a Makefile.PL and a Build.PL, use the
1978 former (EUMM) or the latter (MB); if the module
1979 comes with only one of the two, that one will be
1980 used no matter the setting
1981 prerequisites_policy
1982 what to do if you are missing module prerequisites
1983 ('follow' automatically, 'ask' me, or 'ignore')
1984 prefs_dir local directory to store per-distro build options
1985 proxy_user username for accessing an authenticating proxy
1986 proxy_pass password for accessing an authenticating proxy
1987 randomize_urllist add some randomness to the sequence of the urllist
1988 scan_cache controls scanning of cache ('atstart' or 'never')
1989 shell your favorite shell
1990 show_unparsable_versions
1991 boolean if r command tells which modules are versionless
1992 show_upload_date boolean if commands should try to determine upload date
1993 show_zero_versions boolean if r command tells for which modules $version==0
1994 tar location of external program tar
1995 tar_verbosity verbosity level for the tar command
1996 term_is_latin deprecated: if true Unicode is translated to ISO-8859-1
1997 (and nonsense for characters outside latin range)
1998 term_ornaments boolean to turn ReadLine ornamenting on/off
1999 test_report email test reports (if CPAN::Reporter is installed)
2000 trust_test_report_history
2001 skip testing when previously tested ok (according to
2002 CPAN::Reporter history)
2003 unzip location of external program unzip
2004 urllist arrayref to nearby CPAN sites (or equivalent locations)
2005 use_sqlite use CPAN::SQLite for metadata storage (fast and lean)
2006 username your username if you CPAN server wants one
2007 version_timeout stops version parsing after this many seconds.
2008 Default is 15 secs. Set to 0 to disable.
2009 wait_list arrayref to a wait server to try (See CPAN::WAIT)
2010 wget path to external prg
2011 yaml_load_code enable YAML code deserialisation via CPAN::DeferredCode
2012 yaml_module which module to use to read/write YAML files
2014 You can set and query each of these options interactively in the cpan
2015 shell with the C<o conf> or the C<o conf init> command as specified below.
2019 =item C<o conf E<lt>scalar optionE<gt>>
2021 prints the current value of the I<scalar option>
2023 =item C<o conf E<lt>scalar optionE<gt> E<lt>valueE<gt>>
2025 Sets the value of the I<scalar option> to I<value>
2027 =item C<o conf E<lt>list optionE<gt>>
2029 prints the current value of the I<list option> in MakeMaker's
2032 =item C<o conf E<lt>list optionE<gt> [shift|pop]>
2034 shifts or pops the array in the I<list option> variable
2036 =item C<o conf E<lt>list optionE<gt> [unshift|push|splice] E<lt>listE<gt>>
2038 works like the corresponding perl commands.
2040 =item interactive editing: o conf init [MATCH|LIST]
2042 Runs an interactive configuration dialog for matching variables.
2043 Without argument runs the dialog over all supported config variables.
2044 To specify a MATCH the argument must be enclosed by slashes.
2048 o conf init ftp_passive ftp_proxy
2051 Note: this method of setting config variables often provides more
2052 explanation about the functioning of a variable than the manpage.
2056 =head2 CPAN::anycwd($path): Note on config variable getcwd
2058 CPAN.pm changes the current working directory often and needs to
2059 determine its own current working directory. By default it uses
2060 Cwd::cwd, but if for some reason this doesn't work on your system,
2061 configure alternatives according to the following table:
2079 Calls the external command cwd.
2083 =head2 Note on the format of the urllist parameter
2085 urllist parameters are URLs according to RFC 1738. We do a little
2086 guessing if your URL is not compliant, but if you have problems with
2087 C<file> URLs, please try the correct format. Either:
2089 file://localhost/whatever/ftp/pub/CPAN/
2093 file:///home/ftp/pub/CPAN/
2095 =head2 The urllist parameter has CD-ROM support
2097 The C<urllist> parameter of the configuration table contains a list of
2098 URLs used for downloading. If the list contains any
2099 C<file> URLs, CPAN always tries there first. This
2100 feature is disabled for index files. So the recommendation for the
2101 owner of a CD-ROM with CPAN contents is: include your local, possibly
2102 outdated CD-ROM as a C<file> URL at the end of urllist, e.g.
2104 o conf urllist push file://localhost/CDROM/CPAN
2106 CPAN.pm will then fetch the index files from one of the CPAN sites
2107 that come at the beginning of urllist. It will later check for each
2108 module to see whether there is a local copy of the most recent version.
2110 Another peculiarity of urllist is that the site that we could
2111 successfully fetch the last file from automatically gets a preference
2112 token and is tried as the first site for the next request. So if you
2113 add a new site at runtime it may happen that the previously preferred
2114 site will be tried another time. This means that if you want to disallow
2115 a site for the next transfer, it must be explicitly removed from
2118 =head2 Maintaining the urllist parameter
2120 If you have YAML.pm (or some other YAML module configured in
2121 C<yaml_module>) installed, CPAN.pm collects a few statistical data
2122 about recent downloads. You can view the statistics with the C<hosts>
2123 command or inspect them directly by looking into the C<FTPstats.yml>
2124 file in your C<cpan_home> directory.
2126 To get some interesting statistics, it is recommended that
2127 C<randomize_urllist> be set; this introduces some amount of
2128 randomness into the URL selection.
2130 =head2 The C<requires> and C<build_requires> dependency declarations
2132 Since CPAN.pm version 1.88_51 modules declared as C<build_requires> by
2133 a distribution are treated differently depending on the config
2134 variable C<build_requires_install_policy>. By setting
2135 C<build_requires_install_policy> to C<no>, such a module is not
2136 installed. It is only built and tested, and then kept in the list of
2137 tested but uninstalled modules. As such, it is available during the
2138 build of the dependent module by integrating the path to the
2139 C<blib/arch> and C<blib/lib> directories in the environment variable
2140 PERL5LIB. If C<build_requires_install_policy> is set ti C<yes>, then
2141 both modules declared as C<requires> and those declared as
2142 C<build_requires> are treated alike. By setting to C<ask/yes> or
2143 C<ask/no>, CPAN.pm asks the user and sets the default accordingly.
2145 =head2 Configuration for individual distributions (I<Distroprefs>)
2147 (B<Note:> This feature has been introduced in CPAN.pm 1.8854 and is
2148 still considered beta quality)
2150 Distributions on CPAN usually behave according to what we call the
2151 CPAN mantra. Or since the advent of Module::Build we should talk about
2154 perl Makefile.PL perl Build.PL
2156 make test ./Build test
2157 make install ./Build install
2159 But some modules cannot be built with this mantra. They try to get
2160 some extra data from the user via the environment, extra arguments, or
2161 interactively--thus disturbing the installation of large bundles like
2162 Phalanx100 or modules with many dependencies like Plagger.
2164 The distroprefs system of C<CPAN.pm> addresses this problem by
2165 allowing the user to specify extra informations and recipes in YAML
2172 pass additional arguments to one of the four commands,
2176 set environment variables
2180 instantiate an Expect object that reads from the console, waits for
2181 some regular expressions and enters some answers
2185 temporarily override assorted C<CPAN.pm> configuration variables
2189 specify dependencies the original maintainer forgot
2193 disable the installation of an object altogether
2197 See the YAML and Data::Dumper files that come with the C<CPAN.pm>
2198 distribution in the C<distroprefs/> directory for examples.
2202 The YAML files themselves must have the C<.yml> extension; all other
2203 files are ignored (for two exceptions see I<Fallback Data::Dumper and
2204 Storable> below). The containing directory can be specified in
2205 C<CPAN.pm> in the C<prefs_dir> config variable. Try C<o conf init
2206 prefs_dir> in the CPAN shell to set and activate the distroprefs
2209 Every YAML file may contain arbitrary documents according to the YAML
2210 specification, and every document is treated as an entity that
2211 can specify the treatment of a single distribution.
2213 Filenames can be picked arbitrarily; C<CPAN.pm> always reads
2214 all files (in alphabetical order) and takes the key C<match> (see
2215 below in I<Language Specs>) as a hashref containing match criteria
2216 that determine if the current distribution matches the YAML document
2219 =head2 Fallback Data::Dumper and Storable
2221 If neither your configured C<yaml_module> nor YAML.pm is installed,
2222 CPAN.pm falls back to using Data::Dumper and Storable and looks for
2223 files with the extensions C<.dd> or C<.st> in the C<prefs_dir>
2224 directory. These files are expected to contain one or more hashrefs.
2225 For Data::Dumper generated files, this is expected to be done with by
2226 defining C<$VAR1>, C<$VAR2>, etc. The YAML shell would produce these
2229 ysh < somefile.yml > somefile.dd
2231 For Storable files the rule is that they must be constructed such that
2232 C<Storable::retrieve(file)> returns an array reference and the array
2233 elements represent one distropref object each. The conversion from
2234 YAML would look like so:
2236 perl -MYAML=LoadFile -MStorable=nstore -e '
2238 nstore(\@y, shift)' somefile.yml somefile.st
2240 In bootstrapping situations it is usually sufficient to translate only
2241 a few YAML files to Data::Dumper for crucial modules like
2242 C<YAML::Syck>, C<YAML.pm> and C<Expect.pm>. If you prefer Storable
2243 over Data::Dumper, remember to pull out a Storable version that writes
2244 an older format than all the other Storable versions that will need to
2249 The following example contains all supported keywords and structures
2250 with the exception of C<eexpect> which can be used instead of
2256 module: "Dancing::Queen"
2257 distribution: "^CHACHACHA/Dancing-"
2258 not_distribution: "\.zip$"
2259 perl: "/usr/local/cariba-perl/bin/perl"
2264 DANCING_FLOOR: "Shubiduh"
2270 - "--somearg=specialcase"
2275 - "Which is your favorite fruit"
2287 commandline: "echo SKIPPING make"
2300 WANT_TO_INSTALL: YES
2303 - "Do you really want to install"
2307 - "ABCDE/Fedcba-3.14-ABCDE-01.patch"
2313 Test::Exception: 0.25
2318 =head2 Language Specs
2320 Every YAML document represents a single hash reference. The valid keys
2321 in this hash are as follows:
2325 =item comment [scalar]
2329 =item cpanconfig [hash]
2331 Temporarily override assorted C<CPAN.pm> configuration variables.
2333 Supported are: C<build_requires_install_policy>, C<check_sigs>,
2334 C<make>, C<make_install_make_command>, C<prefer_installer>,
2335 C<test_report>. Please report as a bug when you need another one
2338 =item depends [hash] *** EXPERIMENTAL FEATURE ***
2340 All three types, namely C<configure_requires>, C<build_requires>, and
2341 C<requires> are supported in the way specified in the META.yml
2342 specification. The current implementation I<merges> the specified
2343 dependencies with those declared by the package maintainer. In a
2344 future implementation this may be changed to override the original
2347 =item disabled [boolean]
2349 Specifies that this distribution shall not be processed at all.
2351 =item features [array] *** EXPERIMENTAL FEATURE ***
2353 Experimental implementation to deal with optional_features from
2354 META.yml. Still needs coordination with installer software and
2355 currently works only for META.yml declaring C<dynamic_config=0>. Use
2360 The canonical name of a delegate distribution to install
2361 instead. Useful when a new version, although it tests OK itself,
2362 breaks something else or a developer release or a fork is already
2363 uploaded that is better than the last released version.
2365 =item install [hash]
2367 Processing instructions for the C<make install> or C<./Build install>
2368 phase of the CPAN mantra. See below under I<Processing Instructions>.
2372 Processing instructions for the C<make> or C<./Build> phase of the
2373 CPAN mantra. See below under I<Processing Instructions>.
2377 A hashref with one or more of the keys C<distribution>, C<modules>,
2378 C<perl>, C<perlconfig>, and C<env> that specify whether a document is
2379 targeted at a specific CPAN distribution or installation.
2380 Keys prefixed with C<not_> negates the corresponding match.
2382 The corresponding values are interpreted as regular expressions. The
2383 C<distribution> related one will be matched against the canonical
2384 distribution name, e.g. "AUTHOR/Foo-Bar-3.14.tar.gz".
2386 The C<module> related one will be matched against I<all> modules
2387 contained in the distribution until one module matches.
2389 The C<perl> related one will be matched against C<$^X> (but with the
2392 The value associated with C<perlconfig> is itself a hashref that is
2393 matched against corresponding values in the C<%Config::Config> hash
2394 living in the C<Config.pm> module.
2395 Keys prefixed with C<not_> negates the corresponding match.
2397 The value associated with C<env> is itself a hashref that is
2398 matched against corresponding values in the C<%ENV> hash.
2399 Keys prefixed with C<not_> negates the corresponding match.
2401 If more than one restriction of C<module>, C<distribution>, etc. is
2402 specified, the results of the separately computed match values must
2403 all match. If so, the hashref represented by the
2404 YAML document is returned as the preference structure for the current
2407 =item patches [array]
2409 An array of patches on CPAN or on the local disk to be applied in
2410 order via an external patch program. If the value for the C<-p>
2411 parameter is C<0> or C<1> is determined by reading the patch
2412 beforehand. The path to each patch is either an absolute path on the
2413 local filesystem or relative to a patch directory specified in the
2414 C<patches_dir> configuration variable or in the format of a canonical
2415 distroname. For examples please consult the distroprefs/ directory in
2416 the CPAN.pm distribution (these examples are not installed by
2419 Note: if the C<applypatch> program is installed and C<CPAN::Config>
2420 knows about it B<and> a patch is written by the C<makepatch> program,
2421 then C<CPAN.pm> lets C<applypatch> apply the patch. Both C<makepatch>
2422 and C<applypatch> are available from CPAN in the C<JV/makepatch-*>
2427 Processing instructions for the C<perl Makefile.PL> or C<perl
2428 Build.PL> phase of the CPAN mantra. See below under I<Processing
2433 Processing instructions for the C<make test> or C<./Build test> phase
2434 of the CPAN mantra. See below under I<Processing Instructions>.
2438 =head2 Processing Instructions
2444 Arguments to be added to the command line
2448 A full commandline to run via C<system()>.
2449 During execution, the environment variable PERL is set
2450 to $^X (but with an absolute path). If C<commandline> is specified,
2451 C<args> is not used.
2453 =item eexpect [hash]
2455 Extended C<expect>. This is a hash reference with four allowed keys,
2456 C<mode>, C<timeout>, C<reuse>, and C<talk>.
2458 You must install the C<Expect> module to use C<eexpect>. CPAN.pm
2459 does not install it for you.
2461 C<mode> may have the values C<deterministic> for the case where all
2462 questions come in the order written down and C<anyorder> for the case
2463 where the questions may come in any order. The default mode is
2466 C<timeout> denotes a timeout in seconds. Floating-point timeouts are
2467 OK. With C<mode=deterministic>, the timeout denotes the
2468 timeout per question; with C<mode=anyorder> it denotes the
2469 timeout per byte received from the stream or questions.
2471 C<talk> is a reference to an array that contains alternating questions
2472 and answers. Questions are regular expressions and answers are literal
2473 strings. The Expect module watches the stream from the
2474 execution of the external program (C<perl Makefile.PL>, C<perl
2475 Build.PL>, C<make>, etc.).
2477 For C<mode=deterministic>, the CPAN.pm injects the
2478 corresponding answer as soon as the stream matches the regular expression.
2480 For C<mode=anyorder> CPAN.pm answers a question as soon
2481 as the timeout is reached for the next byte in the input stream. In
2482 this mode you can use the C<reuse> parameter to decide what will
2483 happen with a question-answer pair after it has been used. In the
2484 default case (reuse=0) it is removed from the array, avoiding being
2485 used again accidentally. If you want to answer the
2486 question C<Do you really want to do that> several times, then it must
2487 be included in the array at least as often as you want this answer to
2488 be given. Setting the parameter C<reuse> to 1 makes this repetition
2493 Environment variables to be set during the command
2495 =item expect [array]
2497 You must install the C<Expect> module to use C<expect>. CPAN.pm
2498 does not install it for you.
2500 C<< expect: <array> >> is a short notation for this C<eexpect>:
2509 =head2 Schema verification with C<Kwalify>
2511 If you have the C<Kwalify> module installed (which is part of the
2512 Bundle::CPANxxl), then all your distroprefs files are checked for
2513 syntactic correctness.
2515 =head2 Example Distroprefs Files
2517 C<CPAN.pm> comes with a collection of example YAML files. Note that these
2518 are really just examples and should not be used without care because
2519 they cannot fit everybody's purpose. After all, the authors of the
2520 packages that ask questions had a need to ask, so you should watch
2521 their questions and adjust the examples to your environment and your
2522 needs. You have been warned:-)
2524 =head1 PROGRAMMER'S INTERFACE
2526 If you do not enter the shell, shell commands are
2527 available both as methods (C<CPAN::Shell-E<gt>install(...)>) and as
2528 functions in the calling package (C<install(...)>). Before calling low-level
2529 commands, it makes sense to initialize components of CPAN you need, e.g.:
2531 CPAN::HandleConfig->load;
2532 CPAN::Shell::setup_output;
2533 CPAN::Index->reload;
2535 High-level commands do such initializations automatically.
2537 There's currently only one class that has a stable interface -
2538 CPAN::Shell. All commands that are available in the CPAN shell are
2539 methods of the class CPAN::Shell. Each of the commands that produce
2540 listings of modules (C<r>, C<autobundle>, C<u>) also return a list of
2541 the IDs of all modules within the list.
2545 =item expand($type,@things)
2547 The IDs of all objects available within a program are strings that can
2548 be expanded to the corresponding real objects with the
2549 C<CPAN::Shell-E<gt>expand("Module",@things)> method. Expand returns a
2550 list of CPAN::Module objects according to the C<@things> arguments
2551 given. In scalar context, it returns only the first element of the
2554 =item expandany(@things)
2556 Like expand, but returns objects of the appropriate type, i.e.
2557 CPAN::Bundle objects for bundles, CPAN::Module objects for modules, and
2558 CPAN::Distribution objects for distributions. Note: it does not expand
2559 to CPAN::Author objects.
2561 =item Programming Examples
2563 This enables the programmer to do operations that combine
2564 functionalities that are available in the shell.
2566 # install everything that is outdated on my disk:
2567 perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
2569 # install my favorite programs if necessary:
2570 for $mod (qw(Net::FTP Digest::SHA Data::Dumper)) {
2571 CPAN::Shell->install($mod);
2574 # list all modules on my disk that have no VERSION number
2575 for $mod (CPAN::Shell->expand("Module","/./")) {
2576 next unless $mod->inst_file;
2577 # MakeMaker convention for undefined $VERSION:
2578 next unless $mod->inst_version eq "undef";
2579 print "No VERSION in ", $mod->id, "\n";
2582 # find out which distribution on CPAN contains a module:
2583 print CPAN::Shell->expand("Module","Apache::Constants")->cpan_file
2585 Or if you want to schedule a I<cron> job to watch CPAN, you could list
2586 all modules that need updating. First a quick and dirty way:
2588 perl -e 'use CPAN; CPAN::Shell->r;'
2590 If you don't want any output should all modules be
2591 up to date, parse the output of above command for the regular
2592 expression C</modules are up to date/> and decide to mail the output
2593 only if it doesn't match.
2595 If you prefer to do it more in a programmerish style in one single
2596 process, something like this may better suit you:
2598 # list all modules on my disk that have newer versions on CPAN
2599 for $mod (CPAN::Shell->expand("Module","/./")) {
2600 next unless $mod->inst_file;
2601 next if $mod->uptodate;
2602 printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
2603 $mod->id, $mod->inst_version, $mod->cpan_version;
2606 If that gives too much output every day, you may want to
2607 watch only for three modules. You can write
2609 for $mod (CPAN::Shell->expand("Module","/Apache|LWP|CGI/")) {
2611 as the first line instead. Or you can combine some of the above
2614 # watch only for a new mod_perl module
2615 $mod = CPAN::Shell->expand("Module","mod_perl");
2616 exit if $mod->uptodate;
2617 # new mod_perl arrived, let me know all update recommendations
2622 =head2 Methods in the other Classes
2626 =item CPAN::Author::as_glimpse()
2628 Returns a one-line description of the author
2630 =item CPAN::Author::as_string()
2632 Returns a multi-line description of the author
2634 =item CPAN::Author::email()
2636 Returns the author's email address
2638 =item CPAN::Author::fullname()
2640 Returns the author's name
2642 =item CPAN::Author::name()
2644 An alias for fullname
2646 =item CPAN::Bundle::as_glimpse()
2648 Returns a one-line description of the bundle
2650 =item CPAN::Bundle::as_string()
2652 Returns a multi-line description of the bundle
2654 =item CPAN::Bundle::clean()
2656 Recursively runs the C<clean> method on all items contained in the bundle.
2658 =item CPAN::Bundle::contains()
2660 Returns a list of objects' IDs contained in a bundle. The associated
2661 objects may be bundles, modules or distributions.
2663 =item CPAN::Bundle::force($method,@args)
2665 Forces CPAN to perform a task that it normally would have refused to
2666 do. Force takes as arguments a method name to be called and any number
2667 of additional arguments that should be passed to the called method.
2668 The internals of the object get the needed changes so that CPAN.pm
2669 does not refuse to take the action. The C<force> is passed recursively
2670 to all contained objects. See also the section above on the C<force>
2671 and the C<fforce> pragma.
2673 =item CPAN::Bundle::get()
2675 Recursively runs the C<get> method on all items contained in the bundle
2677 =item CPAN::Bundle::inst_file()
2679 Returns the highest installed version of the bundle in either @INC or
2680 C<< $CPAN::Config->{cpan_home} >>. Note that this is different from
2681 CPAN::Module::inst_file.
2683 =item CPAN::Bundle::inst_version()
2685 Like CPAN::Bundle::inst_file, but returns the $VERSION
2687 =item CPAN::Bundle::uptodate()
2689 Returns 1 if the bundle itself and all its members are uptodate.
2691 =item CPAN::Bundle::install()
2693 Recursively runs the C<install> method on all items contained in the bundle
2695 =item CPAN::Bundle::make()
2697 Recursively runs the C<make> method on all items contained in the bundle
2699 =item CPAN::Bundle::readme()
2701 Recursively runs the C<readme> method on all items contained in the bundle
2703 =item CPAN::Bundle::test()
2705 Recursively runs the C<test> method on all items contained in the bundle
2707 =item CPAN::Distribution::as_glimpse()
2709 Returns a one-line description of the distribution
2711 =item CPAN::Distribution::as_string()
2713 Returns a multi-line description of the distribution
2715 =item CPAN::Distribution::author
2717 Returns the CPAN::Author object of the maintainer who uploaded this
2720 =item CPAN::Distribution::pretty_id()
2722 Returns a string of the form "AUTHORID/TARBALL", where AUTHORID is the
2723 author's PAUSE ID and TARBALL is the distribution filename.
2725 =item CPAN::Distribution::base_id()
2727 Returns the distribution filename without any archive suffix. E.g
2730 =item CPAN::Distribution::clean()
2732 Changes to the directory where the distribution has been unpacked and
2733 runs C<make clean> there.
2735 =item CPAN::Distribution::containsmods()
2737 Returns a list of IDs of modules contained in a distribution file.
2738 Works only for distributions listed in the 02packages.details.txt.gz
2739 file. This typically means that just most recent version of a
2740 distribution is covered.
2742 =item CPAN::Distribution::cvs_import()
2744 Changes to the directory where the distribution has been unpacked and
2747 cvs -d $cvs_root import -m $cvs_log $cvs_dir $userid v$version
2751 =item CPAN::Distribution::dir()
2753 Returns the directory into which this distribution has been unpacked.
2755 =item CPAN::Distribution::force($method,@args)
2757 Forces CPAN to perform a task that it normally would have refused to
2758 do. Force takes as arguments a method name to be called and any number
2759 of additional arguments that should be passed to the called method.
2760 The internals of the object get the needed changes so that CPAN.pm
2761 does not refuse to take the action. See also the section above on the
2762 C<force> and the C<fforce> pragma.
2764 =item CPAN::Distribution::get()
2766 Downloads the distribution from CPAN and unpacks it. Does nothing if
2767 the distribution has already been downloaded and unpacked within the
2770 =item CPAN::Distribution::install()
2772 Changes to the directory where the distribution has been unpacked and
2773 runs the external command C<make install> there. If C<make> has not
2774 yet been run, it will be run first. A C<make test> is issued in
2775 any case and if this fails, the install is cancelled. The
2776 cancellation can be avoided by letting C<force> run the C<install> for
2779 This install method only has the power to install the distribution if
2780 there are no dependencies in the way. To install an object along with all
2781 its dependencies, use CPAN::Shell->install.
2783 Note that install() gives no meaningful return value. See uptodate().
2785 =item CPAN::Distribution::install_tested()
2787 Install all distributions that have tested sucessfully but
2788 not yet installed. See also C<is_tested>.
2790 =item CPAN::Distribution::isa_perl()
2792 Returns 1 if this distribution file seems to be a perl distribution.
2793 Normally this is derived from the file name only, but the index from
2794 CPAN can contain a hint to achieve a return value of true for other
2797 =item CPAN::Distribution::look()
2799 Changes to the directory where the distribution has been unpacked and
2800 opens a subshell there. Exiting the subshell returns.
2802 =item CPAN::Distribution::make()
2804 First runs the C<get> method to make sure the distribution is
2805 downloaded and unpacked. Changes to the directory where the
2806 distribution has been unpacked and runs the external commands C<perl
2807 Makefile.PL> or C<perl Build.PL> and C<make> there.
2809 =item CPAN::Distribution::perldoc()
2811 Downloads the pod documentation of the file associated with a
2812 distribution (in HTML format) and runs it through the external
2813 command I<lynx> specified in C<< $CPAN::Config->{lynx} >>. If I<lynx>
2814 isn't available, it converts it to plain text with the external
2815 command I<html2text> and runs it through the pager specified
2816 in C<< $CPAN::Config->{pager} >>.
2818 =item CPAN::Distribution::prefs()
2820 Returns the hash reference from the first matching YAML file that the
2821 user has deposited in the C<prefs_dir/> directory. The first
2822 succeeding match wins. The files in the C<prefs_dir/> are processed
2823 alphabetically, and the canonical distroname (e.g.
2824 AUTHOR/Foo-Bar-3.14.tar.gz) is matched against the regular expressions
2825 stored in the $root->{match}{distribution} attribute value.
2826 Additionally all module names contained in a distribution are matched
2827 against the regular expressions in the $root->{match}{module} attribute
2828 value. The two match values are ANDed together. Each of the two
2829 attributes are optional.
2831 =item CPAN::Distribution::prereq_pm()
2833 Returns the hash reference that has been announced by a distribution
2834 as the C<requires> and C<build_requires> elements. These can be
2835 declared either by the C<META.yml> (if authoritative) or can be
2836 deposited after the run of C<Build.PL> in the file C<./_build/prereqs>
2837 or after the run of C<Makfile.PL> written as the C<PREREQ_PM> hash in
2838 a comment in the produced C<Makefile>. I<Note>: this method only works
2839 after an attempt has been made to C<make> the distribution. Returns
2842 =item CPAN::Distribution::readme()
2844 Downloads the README file associated with a distribution and runs it
2845 through the pager specified in C<< $CPAN::Config->{pager} >>.
2847 =item CPAN::Distribution::reports()
2849 Downloads report data for this distribution from www.cpantesters.org
2850 and displays a subset of them.
2852 =item CPAN::Distribution::read_yaml()
2854 Returns the content of the META.yml of this distro as a hashref. Note:
2855 works only after an attempt has been made to C<make> the distribution.
2856 Returns undef otherwise. Also returns undef if the content of META.yml
2857 is not authoritative. (The rules about what exactly makes the content
2858 authoritative are still in flux.)
2860 =item CPAN::Distribution::test()
2862 Changes to the directory where the distribution has been unpacked and
2863 runs C<make test> there.
2865 =item CPAN::Distribution::uptodate()
2867 Returns 1 if all the modules contained in the distribution are
2868 uptodate. Relies on containsmods.
2870 =item CPAN::Index::force_reload()
2872 Forces a reload of all indices.
2874 =item CPAN::Index::reload()
2876 Reloads all indices if they have not been read for more than
2877 C<< $CPAN::Config->{index_expire} >> days.
2879 =item CPAN::InfoObj::dump()
2881 CPAN::Author, CPAN::Bundle, CPAN::Module, and CPAN::Distribution
2882 inherit this method. It prints the data structure associated with an
2883 object. Useful for debugging. Note: the data structure is considered
2884 internal and thus subject to change without notice.
2886 =item CPAN::Module::as_glimpse()
2888 Returns a one-line description of the module in four columns: The
2889 first column contains the word C<Module>, the second column consists
2890 of one character: an equals sign if this module is already installed
2891 and uptodate, a less-than sign if this module is installed but can be
2892 upgraded, and a space if the module is not installed. The third column
2893 is the name of the module and the fourth column gives maintainer or
2894 distribution information.
2896 =item CPAN::Module::as_string()
2898 Returns a multi-line description of the module
2900 =item CPAN::Module::clean()
2902 Runs a clean on the distribution associated with this module.
2904 =item CPAN::Module::cpan_file()
2906 Returns the filename on CPAN that is associated with the module.
2908 =item CPAN::Module::cpan_version()
2910 Returns the latest version of this module available on CPAN.
2912 =item CPAN::Module::cvs_import()
2914 Runs a cvs_import on the distribution associated with this module.
2916 =item CPAN::Module::description()
2918 Returns a 44 character description of this module. Only available for
2919 modules listed in The Module List (CPAN/modules/00modlist.long.html
2920 or 00modlist.long.txt.gz)
2922 =item CPAN::Module::distribution()
2924 Returns the CPAN::Distribution object that contains the current
2925 version of this module.
2927 =item CPAN::Module::dslip_status()
2929 Returns a hash reference. The keys of the hash are the letters C<D>,
2930 C<S>, C<L>, C<I>, and <P>, for development status, support level,
2931 language, interface and public licence respectively. The data for the
2932 DSLIP status are collected by pause.perl.org when authors register
2933 their namespaces. The values of the 5 hash elements are one-character
2934 words whose meaning is described in the table below. There are also 5
2935 hash elements C<DV>, C<SV>, C<LV>, C<IV>, and <PV> that carry a more
2936 verbose value of the 5 status variables.
2938 Where the 'DSLIP' characters have the following meanings:
2940 D - Development Stage (Note: *NO IMPLIED TIMESCALES*):
2941 i - Idea, listed to gain consensus or as a placeholder
2942 c - under construction but pre-alpha (not yet released)
2943 a/b - Alpha/Beta testing
2945 M - Mature (no rigorous definition)
2946 S - Standard, supplied with Perl 5
2951 u - Usenet newsgroup comp.lang.perl.modules
2952 n - None known, try comp.lang.perl.modules
2953 a - abandoned; volunteers welcome to take over maintainance
2956 p - Perl-only, no compiler needed, should be platform independent
2957 c - C and perl, a C compiler will be needed
2958 h - Hybrid, written in perl with optional C code, no compiler needed
2959 + - C++ and perl, a C++ compiler will be needed
2960 o - perl and another language other than C or C++
2963 f - plain Functions, no references used
2964 h - hybrid, object and function interfaces available
2965 n - no interface at all (huh?)
2966 r - some use of unblessed References or ties
2967 O - Object oriented using blessed references and/or inheritance
2970 p - Standard-Perl: user may choose between GPL and Artistic
2971 g - GPL: GNU General Public License
2972 l - LGPL: "GNU Lesser General Public License" (previously known as
2973 "GNU Library General Public License")
2974 b - BSD: The BSD License
2975 a - Artistic license alone
2976 2 - Artistic license 2.0 or later
2977 o - open source: appoved by www.opensource.org
2978 d - allows distribution without restrictions
2979 r - restricted distribtion
2980 n - no license at all
2982 =item CPAN::Module::force($method,@args)
2984 Forces CPAN to perform a task it would normally refuse to
2985 do. Force takes as arguments a method name to be invoked and any number
2986 of additional arguments to pass that method.
2987 The internals of the object get the needed changes so that CPAN.pm
2988 does not refuse to take the action. See also the section above on the
2989 C<force> and the C<fforce> pragma.
2991 =item CPAN::Module::get()
2993 Runs a get on the distribution associated with this module.
2995 =item CPAN::Module::inst_file()
2997 Returns the filename of the module found in @INC. The first file found
2998 is reported, just as perl itself stops searching @INC once it finds a
3001 =item CPAN::Module::available_file()
3003 Returns the filename of the module found in PERL5LIB or @INC. The
3004 first file found is reported. The advantage of this method over
3005 C<inst_file> is that modules that have been tested but not yet
3006 installed are included because PERL5LIB keeps track of tested modules.
3008 =item CPAN::Module::inst_version()
3010 Returns the version number of the installed module in readable format.
3012 =item CPAN::Module::available_version()
3014 Returns the version number of the available module in readable format.
3016 =item CPAN::Module::install()
3018 Runs an C<install> on the distribution associated with this module.
3020 =item CPAN::Module::look()
3022 Changes to the directory where the distribution associated with this
3023 module has been unpacked and opens a subshell there. Exiting the
3026 =item CPAN::Module::make()
3028 Runs a C<make> on the distribution associated with this module.
3030 =item CPAN::Module::manpage_headline()
3032 If module is installed, peeks into the module's manpage, reads the
3033 headline, and returns it. Moreover, if the module has been downloaded
3034 within this session, does the equivalent on the downloaded module even
3035 if it hasn't been installed yet.
3037 =item CPAN::Module::perldoc()
3039 Runs a C<perldoc> on this module.
3041 =item CPAN::Module::readme()
3043 Runs a C<readme> on the distribution associated with this module.
3045 =item CPAN::Module::reports()
3047 Calls the reports() method on the associated distribution object.
3049 =item CPAN::Module::test()
3051 Runs a C<test> on the distribution associated with this module.
3053 =item CPAN::Module::uptodate()
3055 Returns 1 if the module is installed and up-to-date.
3057 =item CPAN::Module::userid()
3059 Returns the author's ID of the module.
3063 =head2 Cache Manager
3065 Currently the cache manager only keeps track of the build directory
3066 ($CPAN::Config->{build_dir}). It is a simple FIFO mechanism that
3067 deletes complete directories below C<build_dir> as soon as the size of
3068 all directories there gets bigger than $CPAN::Config->{build_cache}
3069 (in MB). The contents of this cache may be used for later
3070 re-installations that you intend to do manually, but will never be
3071 trusted by CPAN itself. This is due to the fact that the user might
3072 use these directories for building modules on different architectures.
3074 There is another directory ($CPAN::Config->{keep_source_where}) where
3075 the original distribution files are kept. This directory is not
3076 covered by the cache manager and must be controlled by the user. If
3077 you choose to have the same directory as build_dir and as
3078 keep_source_where directory, then your sources will be deleted with
3079 the same fifo mechanism.
3083 A bundle is just a perl module in the namespace Bundle:: that does not
3084 define any functions or methods. It usually only contains documentation.
3086 It starts like a perl module with a package declaration and a $VERSION
3087 variable. After that the pod section looks like any other pod with the
3088 only difference being that I<one special pod section> exists starting with
3093 In this pod section each line obeys the format
3095 Module_Name [Version_String] [- optional text]
3097 The only required part is the first field, the name of a module
3098 (e.g. Foo::Bar, ie. I<not> the name of the distribution file). The rest
3099 of the line is optional. The comment part is delimited by a dash just
3100 as in the man page header.
3102 The distribution of a bundle should follow the same convention as
3103 other distributions.
3105 Bundles are treated specially in the CPAN package. If you say 'install
3106 Bundle::Tkkit' (assuming such a bundle exists), CPAN will install all
3107 the modules in the CONTENTS section of the pod. You can install your
3108 own Bundles locally by placing a conformant Bundle file somewhere into
3109 your @INC path. The autobundle() command which is available in the
3110 shell interface does that for you by including all currently installed
3111 modules in a snapshot bundle file.
3113 =head1 PREREQUISITES
3115 If you have a local mirror of CPAN and can access all files with
3116 "file:" URLs, then you only need a perl later than perl5.003 to run
3117 this module. Otherwise Net::FTP is strongly recommended. LWP may be
3118 required for non-UNIX systems, or if your nearest CPAN site is
3119 associated with a URL that is not C<ftp:>.
3121 If you have neither Net::FTP nor LWP, there is a fallback mechanism
3122 implemented for an external ftp command or for an external lynx
3127 =head2 Finding packages and VERSION
3129 This module presumes that all packages on CPAN
3135 declare their $VERSION variable in an easy to parse manner. This
3136 prerequisite can hardly be relaxed because it consumes far too much
3137 memory to load all packages into the running program just to determine
3138 the $VERSION variable. Currently all programs that are dealing with
3139 version use something like this
3141 perl -MExtUtils::MakeMaker -le \
3142 'print MM->parse_version(shift)' filename
3144 If you are author of a package and wonder if your $VERSION can be
3145 parsed, please try the above method.
3149 come as compressed or gzipped tarfiles or as zip files and contain a
3150 C<Makefile.PL> or C<Build.PL> (well, we try to handle a bit more, but
3151 with little enthusiasm).
3157 Debugging this module is more than a bit complex due to interference from
3158 the software producing the indices on CPAN, the mirroring process on CPAN,
3159 packaging, configuration, synchronicity, and even (gasp!) due to bugs
3160 within the CPAN.pm module itself.
3162 For debugging the code of CPAN.pm itself in interactive mode, some
3163 debugging aid can be turned on for most packages within
3168 =item o debug package...
3170 sets debug mode for packages.
3172 =item o debug -package...
3174 unsets debug mode for packages.
3178 turns debugging on for all packages.
3180 =item o debug number
3184 which sets the debugging packages directly. Note that C<o debug 0>
3185 turns debugging off.
3187 What seems a successful strategy is the combination of C<reload
3188 cpan> and the debugging switches. Add a new debug statement while
3189 running in the shell and then issue a C<reload cpan> and see the new
3190 debugging messages immediately without losing the current context.
3192 C<o debug> without an argument lists the valid package names and the
3193 current set of packages in debugging mode. C<o debug> has built-in
3196 For debugging of CPAN data there is the C<dump> command which takes
3197 the same arguments as make/test/install and outputs each object's
3198 Data::Dumper dump. If an argument looks like a perl variable and
3199 contains one of C<$>, C<@> or C<%>, it is eval()ed and fed to
3200 Data::Dumper directly.
3202 =head2 Floppy, Zip, Offline Mode
3204 CPAN.pm works nicely without network access, too. If you maintain machines
3205 that are not networked at all, you should consider working with C<file:>
3206 URLs. You'll have to collect your modules somewhere first. So
3207 you might use CPAN.pm to put together all you need on a networked
3208 machine. Then copy the $CPAN::Config->{keep_source_where} (but not
3209 $CPAN::Config->{build_dir}) directory on a floppy. This floppy is kind
3210 of a personal CPAN. CPAN.pm on the non-networked machines works nicely
3211 with this floppy. See also below the paragraph about CD-ROM support.
3213 =head2 Basic Utilities for Programmers
3217 =item has_inst($module)
3219 Returns true if the module is installed. Used to load all modules into
3220 the running CPAN.pm that are considered optional. The config variable
3221 C<dontload_list> intercepts the C<has_inst()> call such
3222 that an optional module is not loaded despite being available. For
3223 example, the following command will prevent C<YAML.pm> from being
3226 cpan> o conf dontload_list push YAML
3228 See the source for details.
3230 =item has_usable($module)
3232 Returns true if the module is installed and in a usable state. Only
3233 useful for a handful of modules that are used internally. See the
3236 =item instance($module)
3238 The constructor for all the singletons used to represent modules,
3239 distributions, authors, and bundles. If the object already exists, this
3240 method returns the object; otherwise, it calls the constructor.
3246 There's no strong security layer in CPAN.pm. CPAN.pm helps you to
3247 install foreign, unmasked, unsigned code on your machine. We compare
3248 to a checksum that comes from the net just as the distribution file
3249 itself. But we try to make it easy to add security on demand:
3251 =head2 Cryptographically signed modules
3253 Since release 1.77, CPAN.pm has been able to verify cryptographically
3254 signed module distributions using Module::Signature. The CPAN modules
3255 can be signed by their authors, thus giving more security. The simple
3256 unsigned MD5 checksums that were used before by CPAN protect mainly
3257 against accidental file corruption.
3259 You will need to have Module::Signature installed, which in turn
3260 requires that you have at least one of Crypt::OpenPGP module or the
3261 command-line F<gpg> tool installed.
3263 You will also need to be able to connect over the Internet to the public
3264 keyservers, like pgp.mit.edu, and their port 11731 (the HKP protocol).
3266 The configuration parameter check_sigs is there to turn signature
3271 Most functions in package CPAN are exported by default. The reason
3272 for this is that the primary use is intended for the cpan shell or for
3277 When the CPAN shell enters a subshell via the look command, it sets
3278 the environment CPAN_SHELL_LEVEL to 1, or increments that variable if it is
3281 When CPAN runs, it sets the environment variable PERL5_CPAN_IS_RUNNING
3282 to the ID of the running process. It also sets
3283 PERL5_CPANPLUS_IS_RUNNING to prevent runaway processes which could
3284 happen with older versions of Module::Install.
3286 When running C<perl Makefile.PL>, the environment variable
3287 C<PERL5_CPAN_IS_EXECUTING> is set to the full path of the
3288 C<Makefile.PL> that is being executed. This prevents runaway processes
3289 with newer versions of Module::Install.
3291 When the config variable ftp_passive is set, all downloads will be run
3292 with the environment variable FTP_PASSIVE set to this value. This is
3293 in general a good idea as it influences both Net::FTP and LWP based
3294 connections. The same effect can be achieved by starting the cpan
3295 shell with this environment variable set. For Net::FTP alone, one can
3296 also always set passive mode by running libnetcfg.
3298 =head1 POPULATE AN INSTALLATION WITH LOTS OF MODULES
3300 Populating a freshly installed perl with one's favorite modules is pretty
3301 easy if you maintain a private bundle definition file. To get a useful
3302 blueprint of a bundle definition file, the command autobundle can be used
3303 on the CPAN shell command line. This command writes a bundle definition
3304 file for all modules installed for the current perl
3305 interpreter. It's recommended to run this command once only, and from then
3306 on maintain the file manually under a private name, say
3307 Bundle/my_bundle.pm. With a clever bundle file you can then simply say
3309 cpan> install Bundle::my_bundle
3311 then answer a few questions and go out for coffee (possibly
3312 even in a different city).
3314 Maintaining a bundle definition file means keeping track of two
3315 things: dependencies and interactivity. CPAN.pm sometimes fails on
3316 calculating dependencies because not all modules define all MakeMaker
3317 attributes correctly, so a bundle definition file should specify
3318 prerequisites as early as possible. On the other hand, it's
3319 annoying that so many distributions need some interactive configuring. So
3320 what you can try to accomplish in your private bundle file is to have the
3321 packages that need to be configured early in the file and the gentle
3322 ones later, so you can go out for cofeee after a few minutes and leave CPAN.pm
3323 to churn away untended.
3325 =head1 WORKING WITH CPAN.pm BEHIND FIREWALLS
3327 Thanks to Graham Barr for contributing the following paragraphs about
3328 the interaction between perl, and various firewall configurations. For
3329 further information on firewalls, it is recommended to consult the
3330 documentation that comes with the I<ncftp> program. If you are unable to
3331 go through the firewall with a simple Perl setup, it is likely
3332 that you can configure I<ncftp> so that it works through your firewall.
3334 =head2 Three basic types of firewalls
3336 Firewalls can be categorized into three basic types.
3342 This is when the firewall machine runs a web server, and to access the
3343 outside world, you must do so via that web server. If you set environment
3344 variables like http_proxy or ftp_proxy to values beginning with http://,
3345 or in your web browser you've proxy information set, then you know
3346 you are running behind an http firewall.
3348 To access servers outside these types of firewalls with perl (even for
3353 This where the firewall machine runs an ftp server. This kind of
3354 firewall will only let you access ftp servers outside the firewall.
3355 This is usually done by connecting to the firewall with ftp, then
3356 entering a username like "user@outside.host.com".
3358 To access servers outside these type of firewalls with perl, you
3361 =item One-way visibility
3363 One-way visibility means these firewalls try to make themselves
3364 invisible to users inside the firewall. An FTP data connection is
3365 normally created by sending your IP address to the remote server and then
3366 listening for the return connection. But the remote server will not be able to
3367 connect to you because of the firewall. For these types of firewall,
3368 FTP connections need to be done in a passive mode.
3370 There are two that I can think off.
3376 If you are using a SOCKS firewall, you will need to compile perl and link
3377 it with the SOCKS library. This is what is normally called a 'socksified'
3378 perl. With this executable you will be able to connect to servers outside
3379 the firewall as if it were not there.
3383 This is when the firewall implemented in the kernel (via NAT, or networking
3384 address translation), it allows you to hide a complete network behind one
3385 IP address. With this firewall no special compiling is needed as you can
3386 access hosts directly.
3388 For accessing ftp servers behind such firewalls you usually need to
3389 set the environment variable C<FTP_PASSIVE> or the config variable
3390 ftp_passive to a true value.
3396 =head2 Configuring lynx or ncftp for going through a firewall
3398 If you can go through your firewall with e.g. lynx, presumably with a
3401 /usr/local/bin/lynx -pscott:tiger
3403 then you would configure CPAN.pm with the command
3405 o conf lynx "/usr/local/bin/lynx -pscott:tiger"
3407 That's all. Similarly for ncftp or ftp, you would configure something
3410 o conf ncftp "/usr/bin/ncftp -f /home/scott/ncftplogin.cfg"
3412 Your mileage may vary...
3420 I installed a new version of module X but CPAN keeps saying,
3421 I have the old version installed
3423 Probably you B<do> have the old version installed. This can
3424 happen if a module installs itself into a different directory in the
3425 @INC path than it was previously installed. This is not really a
3426 CPAN.pm problem, you would have the same problem when installing the
3427 module manually. The easiest way to prevent this behaviour is to add
3428 the argument C<UNINST=1> to the C<make install> call, and that is why
3429 many people add this argument permanently by configuring
3431 o conf make_install_arg UNINST=1
3435 So why is UNINST=1 not the default?
3437 Because there are people who have their precise expectations about who
3438 may install where in the @INC path and who uses which @INC array. In
3439 fine tuned environments C<UNINST=1> can cause damage.
3443 I want to clean up my mess, and install a new perl along with
3444 all modules I have. How do I go about it?
3446 Run the autobundle command for your old perl and optionally rename the
3447 resulting bundle file (e.g. Bundle/mybundle.pm), install the new perl
3448 with the Configure option prefix, e.g.
3450 ./Configure -Dprefix=/usr/local/perl-5.6.78.9
3452 Install the bundle file you produced in the first step with something like
3454 cpan> install Bundle::mybundle
3460 When I install bundles or multiple modules with one command
3461 there is too much output to keep track of.
3463 You may want to configure something like
3465 o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
3466 o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"
3468 so that STDOUT is captured in a file for later inspection.
3473 I am not root, how can I install a module in a personal directory?
3475 First of all, you will want to use your own configuration, not the one
3476 that your root user installed. If you do not have permission to write
3477 in the cpan directory that root has configured, you will be asked if
3478 you want to create your own config. Answering "yes" will bring you into
3479 CPAN's configuration stage, using the system config for all defaults except
3480 things that have to do with CPAN's work directory, saving your choices to
3481 your MyConfig.pm file.
3483 You can also manually initiate this process with the following command:
3485 % perl -MCPAN -e 'mkmyconfig'
3491 from the CPAN shell.
3493 You will most probably also want to configure something like this:
3495 o conf makepl_arg "LIB=~/myperl/lib \
3496 INSTALLMAN1DIR=~/myperl/man/man1 \
3497 INSTALLMAN3DIR=~/myperl/man/man3 \
3498 INSTALLSCRIPT=~/myperl/bin \
3499 INSTALLBIN=~/myperl/bin"
3501 and then the equivalent command for Module::Build, which is
3503 o conf mbuildpl_arg "--lib=~/myperl/lib \
3504 --installman1dir=~/myperl/man/man1 \
3505 --installman3dir=~/myperl/man/man3 \
3506 --installscript=~/myperl/bin \
3507 --installbin=~/myperl/bin"
3509 You can make this setting permanent like all C<o conf> settings with
3510 C<o conf commit> or by setting C<auto_commit> beforehand.
3512 You will have to add ~/myperl/man to the MANPATH environment variable
3513 and also tell your perl programs to look into ~/myperl/lib, e.g. by
3516 use lib "$ENV{HOME}/myperl/lib";
3518 or setting the PERL5LIB environment variable.
3520 While we're speaking about $ENV{HOME}, it might be worth mentioning,
3521 that for Windows we use the File::HomeDir module that provides an
3522 equivalent to the concept of the home directory on Unix.
3524 Another thing you should bear in mind is that the UNINST parameter can
3525 be dangerous when you are installing into a private area because you
3526 might accidentally remove modules that other people depend on that are
3527 not using the private area.
3531 How to get a package, unwrap it, and make a change before building it?
3533 Have a look at the C<look> (!) command.
3537 I installed a Bundle and had a couple of fails. When I
3538 retried, everything resolved nicely. Can this be fixed to work
3541 The reason for this is that CPAN does not know the dependencies of all
3542 modules when it starts out. To decide about the additional items to
3543 install, it just uses data found in the META.yml file or the generated
3544 Makefile. An undetected missing piece breaks the process. But it may
3545 well be that your Bundle installs some prerequisite later than some
3546 depending item and thus your second try is able to resolve everything.
3547 Please note, CPAN.pm does not know the dependency tree in advance and
3548 cannot sort the queue of things to install in a topologically correct
3549 order. It resolves perfectly well B<if> all modules declare the
3550 prerequisites correctly with the PREREQ_PM attribute to MakeMaker or
3551 the C<requires> stanza of Module::Build. For bundles which fail and
3552 you need to install often, it is recommended to sort the Bundle
3553 definition file manually.
3557 In our intranet, we have many modules for internal use. How
3558 can I integrate these modules with CPAN.pm but without uploading
3559 the modules to CPAN?
3561 Have a look at the CPAN::Site module.
3565 When I run CPAN's shell, I get an error message about things in my
3566 C</etc/inputrc> (or C<~/.inputrc>) file.
3568 These are readline issues and can only be fixed by studying readline
3569 configuration on your architecture and adjusting the referenced file
3570 accordingly. Please make a backup of the C</etc/inputrc> or C<~/.inputrc>
3571 and edit them. Quite often harmless changes like uppercasing or
3572 lowercasing some arguments solves the problem.
3576 Some authors have strange characters in their names.
3578 Internally CPAN.pm uses the UTF-8 charset. If your terminal is
3579 expecting ISO-8859-1 charset, a converter can be activated by setting
3580 term_is_latin to a true value in your config file. One way of doing so
3583 cpan> o conf term_is_latin 1
3585 If other charset support is needed, please file a bugreport against
3586 CPAN.pm at rt.cpan.org and describe your needs. Maybe we can extend
3587 the support or maybe UTF-8 terminals become widely available.
3589 Note: this config variable is deprecated and will be removed in a
3590 future version of CPAN.pm. It will be replaced with the conventions
3591 around the family of $LANG and $LC_* environment variables.
3595 When an install fails for some reason and then I correct the error
3596 condition and retry, CPAN.pm refuses to install the module, saying
3597 C<Already tried without success>.
3599 Use the force pragma like so
3601 force install Foo::Bar
3607 and then C<make install> directly in the subshell.
3611 How do I install a "DEVELOPER RELEASE" of a module?
3613 By default, CPAN will install the latest non-developer release of a
3614 module. If you want to install a dev release, you have to specify the
3615 partial path starting with the author id to the tarball you wish to
3618 cpan> install KWILLIAMS/Module-Build-0.27_07.tar.gz
3620 Note that you can use the C<ls> command to get this path listed.
3624 How do I install a module and all its dependencies from the commandline,
3625 without being prompted for anything, despite my CPAN configuration
3628 CPAN uses ExtUtils::MakeMaker's prompt() function to ask its questions, so
3629 if you set the PERL_MM_USE_DEFAULT environment variable, you shouldn't be
3630 asked any questions at all (assuming the modules you are installing are
3631 nice about obeying that variable as well):
3633 % PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'
3637 How do I create a Module::Build based Build.PL derived from an
3638 ExtUtils::MakeMaker focused Makefile.PL?
3640 http://search.cpan.org/dist/Module-Build-Convert/
3644 I'm frequently irritated with the CPAN shell's inability to help me
3645 select a good mirror.
3647 The urllist config parameter is yours. You can add and remove sites at
3648 will. You should find out which sites have the best uptodateness,
3649 bandwidth, reliability, etc. and are topologically close to you. Some
3650 people prefer fast downloads, others uptodateness, others reliability.
3651 You decide which to try in which order.
3653 Henk P. Penning maintains a site that collects data about CPAN sites:
3655 http://www.cs.uu.nl/people/henkp/mirmon/cpan.html
3657 Also, feel free to play with experimental features. Run
3659 o conf init randomize_urllist ftpstats_period ftpstats_size
3661 and choose your favorite parameters. After a few downloads running the
3662 C<hosts> command will probably assist you in choosing the best mirror
3667 Why do I get asked the same questions every time I start the shell?
3669 You can make your configuration changes permanent by calling the
3670 command C<o conf commit>. Alternatively set the C<auto_commit>
3671 variable to true by running C<o conf init auto_commit> and answering
3672 the following question with yes.
3676 Older versions of CPAN.pm had the original root directory of all
3677 tarballs in the build directory. Now there are always random
3678 characters appended to these directory names. Why was this done?
3680 The random characters are provided by File::Temp and ensure that each
3681 module's individual build directory is unique. This makes running
3682 CPAN.pm in concurrent processes simultaneously safe.
3686 Speaking of the build directory. Do I have to clean it up myself?
3688 You have the choice to set the config variable C<scan_cache> to
3689 C<never>. Then you must clean it up yourself. The other possible
3690 value, C<atstart> only cleans up the build directory when you start
3691 the CPAN shell. If you never start up the CPAN shell, you probably
3692 also have to clean up the build directory yourself.
3696 =head1 COMPATIBILITY
3698 =head2 OLD PERL VERSIONS
3700 CPAN.pm is regularly tested to run under 5.004, 5.005, and assorted
3701 newer versions. It is getting more and more difficult to get the
3702 minimal prerequisites working on older perls. It is close to
3703 impossible to get the whole Bundle::CPAN working there. If you're in
3704 the position to have only these old versions, be advised that CPAN is
3705 designed to work fine without the Bundle::CPAN installed.
3707 To get things going, note that GBARR/Scalar-List-Utils-1.18.tar.gz is
3708 compatible with ancient perls and that File::Temp is listed as a
3709 prerequisite but CPAN has reasonable workarounds if it is missing.
3713 This module and its competitor, the CPANPLUS module, are both much
3714 cooler than the other. CPAN.pm is older. CPANPLUS was designed to be
3715 more modular, but it was never intended to be compatible with CPAN.pm.
3717 =head1 SECURITY ADVICE
3719 This software enables you to upgrade software on your computer and so
3720 is inherently dangerous because the newly installed software may
3721 contain bugs and may alter the way your computer works or even make it
3722 unusable. Please consider backing up your data before every upgrade.
3726 Please report bugs via L<http://rt.cpan.org/>
3728 Before submitting a bug, please make sure that the traditional method
3729 of building a Perl module package from a shell by following the
3730 installation instructions of that package still works in your
3735 Andreas Koenig C<< <andk@cpan.org> >>
3739 This program is free software; you can redistribute it and/or
3740 modify it under the same terms as Perl itself.
3742 See L<http://www.perl.com/perl/misc/Artistic.html>
3746 Kawai,Takanori provides a Japanese translation of this manpage at
3747 L<http://homepage3.nifty.com/hippo2000/perltips/CPAN.htm>
3751 L<cpan>, L<CPAN::Nox>, L<CPAN::Version>