xref: /openbsd/gnu/usr.bin/perl/cpan/CPAN/lib/CPAN.pm (revision e0680481)
1# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2# vim: ts=4 sts=4 sw=4:
3use strict;
4package CPAN;
5$CPAN::VERSION = '2.36';
6$CPAN::VERSION =~ s/_//;
7
8# we need to run chdir all over and we would get at wrong libraries
9# there
10use File::Spec ();
11BEGIN {
12    if (File::Spec->can("rel2abs")) {
13        for my $inc (@INC) {
14            $inc = File::Spec->rel2abs($inc) unless ref $inc;
15        }
16    }
17    $SIG{WINCH} = 'IGNORE' if exists $SIG{WINCH};
18}
19use CPAN::Author;
20use CPAN::HandleConfig;
21use CPAN::Version;
22use CPAN::Bundle;
23use CPAN::CacheMgr;
24use CPAN::Complete;
25use CPAN::Debug;
26use CPAN::Distribution;
27use CPAN::Distrostatus;
28use CPAN::FTP;
29use CPAN::Index 1.93; # https://rt.cpan.org/Ticket/Display.html?id=43349
30use CPAN::InfoObj;
31use CPAN::Module;
32use CPAN::Prompt;
33use CPAN::URL;
34use CPAN::Queue;
35use CPAN::Tarzip;
36use CPAN::DeferredCode;
37use CPAN::Shell;
38use CPAN::LWP::UserAgent;
39use CPAN::Exception::RecursiveDependency;
40use CPAN::Exception::yaml_not_installed;
41use CPAN::Exception::yaml_process_error;
42
43use Carp ();
44use Config ();
45use Cwd qw(chdir);
46use DirHandle ();
47use Exporter ();
48use ExtUtils::MakeMaker qw(prompt); # for some unknown reason,
49                                    # 5.005_04 does not work without
50                                    # this
51use File::Basename ();
52use File::Copy ();
53use File::Find;
54use File::Path ();
55use FileHandle ();
56use Fcntl qw(:flock);
57use Safe ();
58use Sys::Hostname qw(hostname);
59use Text::ParseWords ();
60use Text::Wrap ();
61
62# protect against "called too early"
63sub find_perl ();
64sub anycwd ();
65sub _uniq;
66
67no lib ".";
68
69require Mac::BuildTools if $^O eq 'MacOS';
70if ($ENV{PERL5_CPAN_IS_RUNNING} && $$ != $ENV{PERL5_CPAN_IS_RUNNING}) {
71    $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} ||= $ENV{PERL5_CPAN_IS_RUNNING};
72    my @rec = _uniq split(/,/, $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION}), $$;
73    $ENV{PERL5_CPAN_IS_RUNNING_IN_RECURSION} = join ",", @rec;
74    # warn "# Note: Recursive call of CPAN.pm detected\n";
75    my $w = sprintf "# Note: CPAN.pm is running in process %d now", pop @rec;
76    my %sleep = (
77                 5 => 30,
78                 6 => 60,
79                 7 => 120,
80                );
81    my $sleep = @rec > 7 ? 300 : ($sleep{scalar @rec}||0);
82    my $verbose = @rec >= 4;
83    while (@rec) {
84        $w .= sprintf " which has been called by process %d", pop @rec;
85    }
86    if ($sleep) {
87        $w .= ".\n\n# Sleeping $sleep seconds to protect other processes\n";
88    }
89    if ($verbose) {
90        warn $w;
91    }
92    local $| = 1;
93    my $have_been_sleeping = 0;
94    while ($sleep > 0) {
95        printf "\r#%5d", --$sleep;
96        sleep 1;
97	++$have_been_sleeping;
98    }
99    print "\n" if $have_been_sleeping;
100}
101$ENV{PERL5_CPAN_IS_RUNNING}=$$;
102$ENV{PERL5_CPANPLUS_IS_RUNNING}=$$; # https://rt.cpan.org/Ticket/Display.html?id=23735
103
104END { $CPAN::End++; &cleanup; }
105
106$CPAN::Signal ||= 0;
107$CPAN::Frontend ||= "CPAN::Shell";
108unless (@CPAN::Defaultsites) {
109    @CPAN::Defaultsites = map {
110        CPAN::URL->new(TEXT => $_, FROM => "DEF")
111    }
112        "http://www.perl.org/CPAN/",
113        "ftp://ftp.perl.org/pub/CPAN/";
114}
115# $CPAN::iCwd (i for initial)
116$CPAN::iCwd ||= CPAN::anycwd();
117$CPAN::Perl ||= CPAN::find_perl();
118$CPAN::Defaultdocs ||= "http://search.cpan.org/perldoc?";
119$CPAN::Defaultrecent ||= "http://search.cpan.org/uploads.rdf";
120$CPAN::Defaultrecent ||= "http://cpan.uwinnipeg.ca/htdocs/cpan.xml";
121
122# our globals are getting a mess
123use vars qw(
124            $AUTOLOAD
125            $Be_Silent
126            $CONFIG_DIRTY
127            $Defaultdocs
128            $Echo_readline
129            $Frontend
130            $GOTOSHELL
131            $HAS_USABLE
132            $Have_warned
133            $MAX_RECURSION
134            $META
135            $RUN_DEGRADED
136            $Signal
137            $SQLite
138            $Suppress_readline
139            $VERSION
140            $autoload_recursion
141            $term
142            @Defaultsites
143            @EXPORT
144           );
145
146$MAX_RECURSION = 32;
147
148@CPAN::ISA = qw(CPAN::Debug Exporter);
149
150# note that these functions live in CPAN::Shell and get executed via
151# AUTOLOAD when called directly
152@EXPORT = qw(
153             autobundle
154             bundle
155             clean
156             cvs_import
157             expand
158             force
159             fforce
160             get
161             install
162             install_tested
163             is_tested
164             make
165             mkmyconfig
166             notest
167             perldoc
168             readme
169             recent
170             recompile
171             report
172             shell
173             smoke
174             test
175             upgrade
176            );
177
178sub soft_chdir_with_alternatives ($);
179
180{
181    $autoload_recursion ||= 0;
182
183    #-> sub CPAN::AUTOLOAD ;
184    sub AUTOLOAD { ## no critic
185        $autoload_recursion++;
186        my($l) = $AUTOLOAD;
187        $l =~ s/.*:://;
188        if ($CPAN::Signal) {
189            warn "Refusing to autoload '$l' while signal pending";
190            $autoload_recursion--;
191            return;
192        }
193        if ($autoload_recursion > 1) {
194            my $fullcommand = join " ", map { "'$_'" } $l, @_;
195            warn "Refusing to autoload $fullcommand in recursion\n";
196            $autoload_recursion--;
197            return;
198        }
199        my(%export);
200        @export{@EXPORT} = '';
201        CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
202        if (exists $export{$l}) {
203            CPAN::Shell->$l(@_);
204        } else {
205            die(qq{Unknown CPAN command "$AUTOLOAD". }.
206                qq{Type ? for help.\n});
207        }
208        $autoload_recursion--;
209    }
210}
211
212{
213    my $x = *SAVEOUT; # avoid warning
214    open($x,">&STDOUT") or die "dup failed";
215    my $redir = 0;
216    sub _redirect(@) {
217        #die if $redir;
218        local $_;
219        push(@_,undef);
220        while(defined($_=shift)) {
221            if (s/^\s*>//){
222                my ($m) = s/^>// ? ">" : "";
223                s/\s+//;
224                $_=shift unless length;
225                die "no dest" unless defined;
226                open(STDOUT,">$m$_") or die "open:$_:$!\n";
227                $redir=1;
228            } elsif ( s/^\s*\|\s*// ) {
229                my $pipe="| $_";
230                while(defined($_[0])){
231                    $pipe .= ' ' . shift;
232                }
233                open(STDOUT,$pipe) or die "open:$pipe:$!\n";
234                $redir=1;
235            } else {
236                push(@_,$_);
237            }
238        }
239        return @_;
240    }
241    sub _unredirect {
242        return unless $redir;
243        $redir = 0;
244        ## redirect: unredirect and propagate errors.  explicit close to wait for pipe.
245        close(STDOUT);
246        open(STDOUT,">&SAVEOUT");
247        die "$@" if "$@";
248        ## redirect: done
249    }
250}
251
252sub _uniq {
253    my(@list) = @_;
254    my %seen;
255    return grep { !$seen{$_}++ } @list;
256}
257
258#-> sub CPAN::shell ;
259sub shell {
260    my($self) = @_;
261    $Suppress_readline = ! -t STDIN unless defined $Suppress_readline;
262    CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
263
264    my $oprompt = shift || CPAN::Prompt->new;
265    my $prompt = $oprompt;
266    my $commandline = shift || "";
267    $CPAN::CurrentCommandId ||= 1;
268
269    local($^W) = 1;
270    unless ($Suppress_readline) {
271        require Term::ReadLine;
272        if (! $term
273            or
274            $term->ReadLine eq "Term::ReadLine::Stub"
275           ) {
276            $term = Term::ReadLine->new('CPAN Monitor');
277        }
278        if ($term->ReadLine eq "Term::ReadLine::Gnu") {
279            my $attribs = $term->Attribs;
280            $attribs->{attempted_completion_function} = sub {
281                &CPAN::Complete::gnu_cpl;
282            }
283        } else {
284            $readline::rl_completion_function =
285                $readline::rl_completion_function = 'CPAN::Complete::cpl';
286        }
287        if (my $histfile = $CPAN::Config->{'histfile'}) {{
288            unless ($term->can("AddHistory")) {
289                $CPAN::Frontend->mywarn("Terminal does not support AddHistory.\n");
290                unless ($CPAN::META->has_inst('Term::ReadLine::Perl')) {
291                    $CPAN::Frontend->mywarn("\nTo fix that, maybe try>  install Term::ReadLine::Perl\n\n");
292                }
293                last;
294            }
295            $META->readhist($term,$histfile);
296        }}
297        for ($CPAN::Config->{term_ornaments}) { # alias
298            local $Term::ReadLine::termcap_nowarn = 1;
299            $term->ornaments($_) if defined;
300        }
301        # $term->OUT is autoflushed anyway
302        my $odef = select STDERR;
303        $| = 1;
304        select STDOUT;
305        $| = 1;
306        select $odef;
307    }
308
309    $META->checklock();
310    my @cwd = grep { defined $_ and length $_ }
311        CPAN::anycwd(),
312              File::Spec->can("tmpdir") ? File::Spec->tmpdir() : (),
313                    File::Spec->rootdir();
314    my $try_detect_readline;
315    $try_detect_readline = $term->ReadLine eq "Term::ReadLine::Stub" if $term;
316    unless ($CPAN::Config->{inhibit_startup_message}) {
317        my $rl_avail = $Suppress_readline ? "suppressed" :
318            ($term->ReadLine ne "Term::ReadLine::Stub") ? "enabled" :
319                "available (maybe install Bundle::CPAN or Bundle::CPANxxl?)";
320        $CPAN::Frontend->myprint(
321                                 sprintf qq{
322cpan shell -- CPAN exploration and modules installation (v%s)
323Enter 'h' for help.
324
325},
326                                 $CPAN::VERSION,
327                                )
328    }
329    my($continuation) = "";
330    my $last_term_ornaments;
331  SHELLCOMMAND: while () {
332        if ($Suppress_readline) {
333            if ($Echo_readline) {
334                $|=1;
335            }
336            print $prompt;
337            last SHELLCOMMAND unless defined ($_ = <> );
338            if ($Echo_readline) {
339                # backdoor: I could not find a way to record sessions
340                print $_;
341            }
342            chomp;
343        } else {
344            last SHELLCOMMAND unless
345                defined ($_ = $term->readline($prompt, $commandline));
346        }
347        $_ = "$continuation$_" if $continuation;
348        s/^\s+//;
349        next SHELLCOMMAND if /^$/;
350        s/^\s*\?\s*/help /;
351        if (/^(?:q(?:uit)?|bye|exit)\s*$/i) {
352            last SHELLCOMMAND;
353        } elsif (s/\\$//s) {
354            chomp;
355            $continuation = $_;
356            $prompt = "    > ";
357        } elsif (/^\!/) {
358            s/^\!//;
359            my($eval) = $_;
360            package
361                CPAN::Eval; # hide from the indexer
362            use strict;
363            use vars qw($import_done);
364            CPAN->import(':DEFAULT') unless $import_done++;
365            CPAN->debug("eval[$eval]") if $CPAN::DEBUG;
366            eval($eval);
367            warn $@ if $@;
368            $continuation = "";
369            $prompt = $oprompt;
370        } elsif (/./) {
371            my(@line);
372            eval { @line = Text::ParseWords::shellwords($_) };
373            warn($@), next SHELLCOMMAND if $@;
374            warn("Text::Parsewords could not parse the line [$_]"),
375                next SHELLCOMMAND unless @line;
376            $CPAN::META->debug("line[".join("|",@line)."]") if $CPAN::DEBUG;
377            my $command = shift @line;
378            eval {
379                local (*STDOUT)=*STDOUT;
380                @line = _redirect(@line);
381                CPAN::Shell->$command(@line)
382              };
383            my $command_error = $@;
384            _unredirect;
385            my $reported_error;
386            if ($command_error) {
387                my $err = $command_error;
388                if (ref $err and $err->isa('CPAN::Exception::blocked_urllist')) {
389                    $CPAN::Frontend->mywarn("Client not fully configured, please proceed with configuring.$err");
390                    $reported_error = ref $err;
391                } else {
392                    # I'd prefer never to arrive here and make all errors exception objects
393                    if ($err =~ /\S/) {
394                        require Carp;
395                        require Dumpvalue;
396                        my $dv = Dumpvalue->new(tick => '"');
397                        Carp::cluck(sprintf "Catching error: %s", $dv->stringify($err));
398                    }
399                }
400            }
401            if ($command =~ /^(
402                             # classic commands
403                             make
404                             |test
405                             |install
406                             |clean
407
408                             # pragmas for classic commands
409                             |ff?orce
410                             |notest
411
412                             # compounds
413                             |report
414                             |smoke
415                             |upgrade
416                            )$/x) {
417                # only commands that tell us something about failed distros
418                # eval necessary for people without an urllist
419                eval {CPAN::Shell->failed($CPAN::CurrentCommandId,1);};
420                if (my $err = $@) {
421                    unless (ref $err and $reported_error eq ref $err) {
422                        die $@;
423                    }
424                }
425            }
426            soft_chdir_with_alternatives(\@cwd);
427            $CPAN::Frontend->myprint("\n");
428            $continuation = "";
429            $CPAN::CurrentCommandId++;
430            $prompt = $oprompt;
431        }
432    } continue {
433        $commandline = ""; # I do want to be able to pass a default to
434                           # shell, but on the second command I see no
435                           # use in that
436        $Signal=0;
437        CPAN::Queue->nullify_queue;
438        if ($try_detect_readline) {
439            if ($CPAN::META->has_inst("Term::ReadLine::Gnu")
440                ||
441                $CPAN::META->has_inst("Term::ReadLine::Perl")
442            ) {
443                delete $INC{"Term/ReadLine.pm"};
444                my $redef = 0;
445                local($SIG{__WARN__}) = CPAN::Shell::paintdots_onreload(\$redef);
446                require Term::ReadLine;
447                $CPAN::Frontend->myprint("\n$redef subroutines in ".
448                                         "Term::ReadLine redefined\n");
449                $GOTOSHELL = 1;
450            }
451        }
452        if ($term and $term->can("ornaments")) {
453            for ($CPAN::Config->{term_ornaments}) { # alias
454                if (defined $_) {
455                    if (not defined $last_term_ornaments
456                        or $_ != $last_term_ornaments
457                    ) {
458                        local $Term::ReadLine::termcap_nowarn = 1;
459                        $term->ornaments($_);
460                        $last_term_ornaments = $_;
461                    }
462                } else {
463                    undef $last_term_ornaments;
464                }
465            }
466        }
467        for my $class (qw(Module Distribution)) {
468            # again unsafe meta access?
469            for my $dm (sort keys %{$CPAN::META->{readwrite}{"CPAN::$class"}}) {
470                next unless $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
471                CPAN->debug("BUG: $class '$dm' was in command state, resetting");
472                delete $CPAN::META->{readwrite}{"CPAN::$class"}{$dm}{incommandcolor};
473            }
474        }
475        if ($GOTOSHELL) {
476            $GOTOSHELL = 0; # not too often
477            $META->savehist if $CPAN::term && $CPAN::term->can("GetHistory");
478            @_ = ($oprompt,"");
479            goto &shell;
480        }
481    }
482    soft_chdir_with_alternatives(\@cwd);
483}
484
485#-> CPAN::soft_chdir_with_alternatives ;
486sub soft_chdir_with_alternatives ($) {
487    my($cwd) = @_;
488    unless (@$cwd) {
489        my $root = File::Spec->rootdir();
490        $CPAN::Frontend->mywarn(qq{Warning: no good directory to chdir to!
491Trying '$root' as temporary haven.
492});
493        push @$cwd, $root;
494    }
495    while () {
496        if (chdir "$cwd->[0]") {
497            return;
498        } else {
499            if (@$cwd>1) {
500                $CPAN::Frontend->mywarn(qq{Could not chdir to "$cwd->[0]": $!
501Trying to chdir to "$cwd->[1]" instead.
502});
503                shift @$cwd;
504            } else {
505                $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd->[0]": $!});
506            }
507        }
508    }
509}
510
511sub _flock {
512    my($fh,$mode) = @_;
513    if ( $Config::Config{d_flock} || $Config::Config{d_fcntl_can_lock} ) {
514        return flock $fh, $mode;
515    } elsif (!$Have_warned->{"d_flock"}++) {
516        $CPAN::Frontend->mywarn("Your OS does not seem to support locking; continuing and ignoring all locking issues\n");
517        $CPAN::Frontend->mysleep(5);
518        return 1;
519    } else {
520        return 1;
521    }
522}
523
524sub _yaml_module () {
525    my $yaml_module = $CPAN::Config->{yaml_module} || "YAML";
526    if (
527        $yaml_module ne "YAML"
528        &&
529        !$CPAN::META->has_inst($yaml_module)
530       ) {
531        # $CPAN::Frontend->mywarn("'$yaml_module' not installed, falling back to 'YAML'\n");
532        $yaml_module = "YAML";
533    }
534    if ($yaml_module eq "YAML"
535        &&
536        $CPAN::META->has_inst($yaml_module)
537        &&
538        $YAML::VERSION < 0.60
539        &&
540        !$Have_warned->{"YAML"}++
541       ) {
542        $CPAN::Frontend->mywarn("Warning: YAML version '$YAML::VERSION' is too low, please upgrade!\n".
543                                "I'll continue but problems are *very* likely to happen.\n"
544                               );
545        $CPAN::Frontend->mysleep(5);
546    }
547    return $yaml_module;
548}
549
550# CPAN::_yaml_loadfile
551sub _yaml_loadfile {
552    my($self,$local_file,$opt) = @_;
553    return +[] unless -s $local_file;
554    my $opt_loadblessed = $opt->{loadblessed} || $CPAN::Config->{yaml_load_code} || 0;
555    my $yaml_module = _yaml_module;
556    if ($CPAN::META->has_inst($yaml_module)) {
557        # temporarily enable yaml code deserialisation
558        no strict 'refs';
559        # 5.6.2 could not do the local() with the reference
560        # so we do it manually instead
561        my $old_loadcode = ${"$yaml_module\::LoadCode"};
562        my $old_loadblessed = ${"$yaml_module\::LoadBlessed"};
563        ${ "$yaml_module\::LoadCode" } = $CPAN::Config->{yaml_load_code} || 0;
564        ${ "$yaml_module\::LoadBlessed" } = $opt_loadblessed ? 1 : 0;
565
566        my ($code, @yaml);
567        if ($code = UNIVERSAL::can($yaml_module, "LoadFile")) {
568            eval { @yaml = $code->($local_file); };
569            if ($@) {
570                # this shall not be done by the frontend
571                die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
572            }
573        } elsif ($code = UNIVERSAL::can($yaml_module, "Load")) {
574            local *FH;
575            if (open FH, $local_file) {
576                local $/;
577                my $ystream = <FH>;
578                eval { @yaml = $code->($ystream); };
579                if ($@) {
580                    # this shall not be done by the frontend
581                    die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"parse",$@);
582                }
583            } else {
584                $CPAN::Frontend->mywarn("Could not open '$local_file': $!");
585            }
586        }
587        ${"$yaml_module\::LoadCode"} = $old_loadcode;
588        ${"$yaml_module\::LoadBlessed"} = $old_loadblessed;
589        return \@yaml;
590    } else {
591        # this shall not be done by the frontend
592        die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "parse");
593    }
594    return +[];
595}
596
597# CPAN::_yaml_dumpfile
598sub _yaml_dumpfile {
599    my($self,$local_file,@what) = @_;
600    my $yaml_module = _yaml_module;
601    if ($CPAN::META->has_inst($yaml_module)) {
602        my $code;
603        if (UNIVERSAL::isa($local_file, "FileHandle")) {
604            $code = UNIVERSAL::can($yaml_module, "Dump");
605            eval { print $local_file $code->(@what) };
606        } elsif ($code = UNIVERSAL::can($yaml_module, "DumpFile")) {
607            eval { $code->($local_file,@what); };
608        } elsif ($code = UNIVERSAL::can($yaml_module, "Dump")) {
609            local *FH;
610            open FH, ">$local_file" or die "Could not open '$local_file': $!";
611            print FH $code->(@what);
612        }
613        if ($@) {
614            die CPAN::Exception::yaml_process_error->new($yaml_module,$local_file,"dump",$@);
615        }
616    } else {
617        if (UNIVERSAL::isa($local_file, "FileHandle")) {
618            # I think this case does not justify a warning at all
619        } else {
620            die CPAN::Exception::yaml_not_installed->new($yaml_module, $local_file, "dump");
621        }
622    }
623}
624
625sub _init_sqlite () {
626    unless ($CPAN::META->has_inst("CPAN::SQLite")) {
627        $CPAN::Frontend->mywarn(qq{CPAN::SQLite not installed, trying to work without\n})
628            unless $Have_warned->{"CPAN::SQLite"}++;
629        return;
630    }
631    require CPAN::SQLite::META; # not needed since CVS version of 2006-12-17
632    $CPAN::SQLite ||= CPAN::SQLite::META->new($CPAN::META);
633}
634
635{
636    my $negative_cache = {};
637    sub _sqlite_running {
638        if ($negative_cache->{time} && time < $negative_cache->{time} + 60) {
639            # need to cache the result, otherwise too slow
640            return $negative_cache->{fact};
641        } else {
642            $negative_cache = {}; # reset
643        }
644        my $ret = $CPAN::Config->{use_sqlite} && ($CPAN::SQLite || _init_sqlite());
645        return $ret if $ret; # fast anyway
646        $negative_cache->{time} = time;
647        return $negative_cache->{fact} = $ret;
648    }
649}
650
651$META ||= CPAN->new; # In case we re-eval ourselves we need the ||
652
653# from here on only subs.
654################################################################################
655
656sub _perl_fingerprint {
657    my($self,$other_fingerprint) = @_;
658    my $dll = eval {OS2::DLLname()};
659    my $mtime_dll = 0;
660    if (defined $dll) {
661        $mtime_dll = (-f $dll ? (stat(_))[9] : '-1');
662    }
663    my $mtime_perl = (-f CPAN::find_perl ? (stat(_))[9] : '-1');
664    my $this_fingerprint = {
665                            '$^X' => CPAN::find_perl,
666                            sitearchexp => $Config::Config{sitearchexp},
667                            'mtime_$^X' => $mtime_perl,
668                            'mtime_dll' => $mtime_dll,
669                           };
670    if ($other_fingerprint) {
671        if (exists $other_fingerprint->{'stat($^X)'}) { # repair fp from rev. 1.88_57
672            $other_fingerprint->{'mtime_$^X'} = $other_fingerprint->{'stat($^X)'}[9];
673        }
674        # mandatory keys since 1.88_57
675        for my $key (qw($^X sitearchexp mtime_dll mtime_$^X)) {
676            return unless $other_fingerprint->{$key} eq $this_fingerprint->{$key};
677        }
678        return 1;
679    } else {
680        return $this_fingerprint;
681    }
682}
683
684sub suggest_myconfig () {
685  SUGGEST_MYCONFIG: if(!$INC{'CPAN/MyConfig.pm'}) {
686        $CPAN::Frontend->myprint("You don't seem to have a user ".
687                                 "configuration (MyConfig.pm) yet.\n");
688        my $new = CPAN::Shell::colorable_makemaker_prompt("Do you want to create a ".
689                                              "user configuration now? (Y/n)",
690                                              "yes");
691        if($new =~ m{^y}i) {
692            CPAN::Shell->mkmyconfig();
693            return &checklock;
694        } else {
695            $CPAN::Frontend->mydie("OK, giving up.");
696        }
697    }
698}
699
700#-> sub CPAN::all_objects ;
701sub all_objects {
702    my($mgr,$class) = @_;
703    CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
704    CPAN->debug("mgr[$mgr] class[$class]") if $CPAN::DEBUG;
705    CPAN::Index->reload;
706    values %{ $META->{readwrite}{$class} }; # unsafe meta access, ok
707}
708
709# Called by shell, not in batch mode. In batch mode I see no risk in
710# having many processes updating something as installations are
711# continually checked at runtime. In shell mode I suspect it is
712# unintentional to open more than one shell at a time
713
714#-> sub CPAN::checklock ;
715sub checklock {
716    my($self) = @_;
717    my $lockfile = File::Spec->catfile($CPAN::Config->{cpan_home},".lock");
718    if (-f $lockfile && -M _ > 0) {
719        my $fh = FileHandle->new($lockfile) or
720            $CPAN::Frontend->mydie("Could not open lockfile '$lockfile': $!");
721        my $otherpid  = <$fh>;
722        my $otherhost = <$fh>;
723        $fh->close;
724        if (defined $otherpid && length $otherpid) {
725            chomp $otherpid;
726        }
727        if (defined $otherhost && length $otherhost) {
728            chomp $otherhost;
729        }
730        my $thishost  = hostname();
731        my $ask_if_degraded_wanted = 0;
732        if (defined $otherhost && defined $thishost &&
733            $otherhost ne '' && $thishost ne '' &&
734            $otherhost ne $thishost) {
735            $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile '$lockfile'\n".
736                                           "reports other host $otherhost and other ".
737                                           "process $otherpid.\n".
738                                           "Cannot proceed.\n"));
739        } elsif ($RUN_DEGRADED) {
740            $CPAN::Frontend->mywarn("Running in downgraded mode (experimental)\n");
741        } elsif (defined $otherpid && $otherpid) {
742            return if $$ == $otherpid; # should never happen
743            $CPAN::Frontend->mywarn(
744                                    qq{
745There seems to be running another CPAN process (pid $otherpid).  Contacting...
746});
747            if (kill 0, $otherpid or $!{EPERM}) {
748                $CPAN::Frontend->mywarn(qq{Other job is running.\n});
749                $ask_if_degraded_wanted = 1;
750            } elsif (-w $lockfile) {
751                my($ans) =
752                    CPAN::Shell::colorable_makemaker_prompt
753                        (qq{Other job not responding. Shall I overwrite }.
754                        qq{the lockfile '$lockfile'? (Y/n)},"y");
755            $CPAN::Frontend->myexit("Ok, bye\n")
756                unless $ans =~ /^y/i;
757            } else {
758                Carp::croak(
759                    qq{Lockfile '$lockfile' not writable by you. }.
760                    qq{Cannot proceed.\n}.
761                    qq{    On UNIX try:\n}.
762                    qq{    rm '$lockfile'\n}.
763                    qq{  and then rerun us.\n}
764                );
765            }
766        } elsif ($^O eq "MSWin32") {
767            $CPAN::Frontend->mywarn(
768                                    qq{
769There seems to be running another CPAN process according to '$lockfile'.
770});
771            $ask_if_degraded_wanted = 1;
772        } else {
773            $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Found invalid lockfile ".
774                                           "'$lockfile', please remove. Cannot proceed.\n"));
775        }
776        if ($ask_if_degraded_wanted) {
777            my($ans) =
778                CPAN::Shell::colorable_makemaker_prompt
779                    (qq{Shall I try to run in downgraded }.
780                     qq{mode? (Y/n)},"y");
781            if ($ans =~ /^y/i) {
782                $CPAN::Frontend->mywarn("Running in downgraded mode (experimental).
783Please report if something unexpected happens\n");
784                $RUN_DEGRADED = 1;
785                for ($CPAN::Config) {
786                    # XXX
787                    # $_->{build_dir_reuse} = 0; # 2006-11-17 akoenig Why was that?
788                    $_->{commandnumber_in_prompt} = 0; # visibility
789                    $_->{histfile}       = "";  # who should win otherwise?
790                    $_->{cache_metadata} = 0;   # better would be a lock?
791                    $_->{use_sqlite}     = 0;   # better would be a write lock!
792                    $_->{auto_commit}    = 0;   # we are violent, do not persist
793                    $_->{test_report}    = 0;   # Oliver Paukstadt had sent wrong reports in degraded mode
794                }
795            } else {
796                my $msg = "You may want to kill the other job and delete the lockfile.";
797                if (defined $otherpid) {
798                    $msg .= " Something like:
799    kill $otherpid
800    rm $lockfile
801";
802                }
803                $CPAN::Frontend->mydie("\n$msg");
804            }
805        }
806    }
807    my $dotcpan = $CPAN::Config->{cpan_home};
808    eval { File::Path::mkpath($dotcpan);};
809    if ($@) {
810        # A special case at least for Jarkko.
811        my $firsterror = $@;
812        my $seconderror;
813        my $symlinkcpan;
814        if (-l $dotcpan) {
815            $symlinkcpan = readlink $dotcpan;
816            die "readlink $dotcpan failed: $!" unless defined $symlinkcpan;
817            eval { File::Path::mkpath($symlinkcpan); };
818            if ($@) {
819                $seconderror = $@;
820            } else {
821                $CPAN::Frontend->mywarn(qq{
822Working directory $symlinkcpan created.
823});
824            }
825        }
826        unless (-d $dotcpan) {
827            my $mess = qq{
828Your configuration suggests "$dotcpan" as your
829CPAN.pm working directory. I could not create this directory due
830to this error: $firsterror\n};
831            $mess .= qq{
832As "$dotcpan" is a symlink to "$symlinkcpan",
833I tried to create that, but I failed with this error: $seconderror
834} if $seconderror;
835            $mess .= qq{
836Please make sure the directory exists and is writable.
837};
838            $CPAN::Frontend->mywarn($mess);
839            return suggest_myconfig;
840        }
841    } # $@ after eval mkpath $dotcpan
842    if (0) { # to test what happens when a race condition occurs
843        for (reverse 1..10) {
844            print $_, "\n";
845            sleep 1;
846        }
847    }
848    # locking
849    if (!$RUN_DEGRADED && !$self->{LOCKFH}) {
850        my $fh;
851        unless ($fh = FileHandle->new("+>>$lockfile")) {
852            $CPAN::Frontend->mywarn(qq{
853
854Your configuration suggests that CPAN.pm should use a working
855directory of
856    $CPAN::Config->{cpan_home}
857Unfortunately we could not create the lock file
858    $lockfile
859due to '$!'.
860
861Please make sure that the configuration variable
862    \$CPAN::Config->{cpan_home}
863points to a directory where you can write a .lock file. You can set
864this variable in either a CPAN/MyConfig.pm or a CPAN/Config.pm in your
865\@INC path;
866});
867            return suggest_myconfig;
868        }
869        my $sleep = 1;
870        while (!CPAN::_flock($fh, LOCK_EX|LOCK_NB)) {
871            my $err = $! || "unknown error";
872            if ($sleep>3) {
873                $CPAN::Frontend->mydie("Could not lock '$lockfile' with flock: $err; giving up\n");
874            }
875            $CPAN::Frontend->mysleep($sleep+=0.1);
876            $CPAN::Frontend->mywarn("Could not lock '$lockfile' with flock: $err; retrying\n");
877        }
878
879        seek $fh, 0, 0;
880        truncate $fh, 0;
881        $fh->autoflush(1);
882        $fh->print($$, "\n");
883        $fh->print(hostname(), "\n");
884        $self->{LOCK} = $lockfile;
885        $self->{LOCKFH} = $fh;
886    }
887    $SIG{TERM} = sub {
888        my $sig = shift;
889        &cleanup;
890        $CPAN::Frontend->mydie("Got SIG$sig, leaving");
891    };
892    $SIG{INT} = sub {
893      # no blocks!!!
894        my $sig = shift;
895        &cleanup if $Signal;
896        die "Got yet another signal" if $Signal > 1;
897        $CPAN::Frontend->mydie("Got another SIG$sig") if $Signal;
898        $CPAN::Frontend->mywarn("Caught SIG$sig, trying to continue\n");
899        $Signal++;
900    };
901
902#       From: Larry Wall <larry@wall.org>
903#       Subject: Re: deprecating SIGDIE
904#       To: perl5-porters@perl.org
905#       Date: Thu, 30 Sep 1999 14:58:40 -0700 (PDT)
906#
907#       The original intent of __DIE__ was only to allow you to substitute one
908#       kind of death for another on an application-wide basis without respect
909#       to whether you were in an eval or not.  As a global backstop, it should
910#       not be used any more lightly (or any more heavily :-) than class
911#       UNIVERSAL.  Any attempt to build a general exception model on it should
912#       be politely squashed.  Any bug that causes every eval {} to have to be
913#       modified should be not so politely squashed.
914#
915#       Those are my current opinions.  It is also my opinion that polite
916#       arguments degenerate to personal arguments far too frequently, and that
917#       when they do, it's because both people wanted it to, or at least didn't
918#       sufficiently want it not to.
919#
920#       Larry
921
922    # global backstop to cleanup if we should really die
923    $SIG{__DIE__} = \&cleanup;
924    $self->debug("Signal handler set.") if $CPAN::DEBUG;
925}
926
927#-> sub CPAN::DESTROY ;
928sub DESTROY {
929    &cleanup; # need an eval?
930}
931
932#-> sub CPAN::anycwd ;
933sub anycwd () {
934    my $getcwd;
935    $getcwd = $CPAN::Config->{'getcwd'} || 'cwd';
936    CPAN->$getcwd();
937}
938
939#-> sub CPAN::cwd ;
940sub cwd {Cwd::cwd();}
941
942#-> sub CPAN::getcwd ;
943sub getcwd {Cwd::getcwd();}
944
945#-> sub CPAN::fastcwd ;
946sub fastcwd {Cwd::fastcwd();}
947
948#-> sub CPAN::getdcwd ;
949sub getdcwd {Cwd::getdcwd();}
950
951#-> sub CPAN::backtickcwd ;
952sub backtickcwd {my $cwd = `cwd`; chomp $cwd; $cwd}
953
954# Adapted from Probe::Perl
955#-> sub CPAN::_perl_is_same
956sub _perl_is_same {
957  my ($perl) = @_;
958  return MM->maybe_command($perl)
959    && `$perl -MConfig=myconfig -e print -e myconfig` eq Config->myconfig;
960}
961
962# Adapted in part from Probe::Perl
963#-> sub CPAN::find_perl ;
964sub find_perl () {
965    if ( File::Spec->file_name_is_absolute($^X) ) {
966        return $^X;
967    }
968    else {
969        my $exe = $Config::Config{exe_ext};
970        my @candidates = (
971            File::Spec->catfile($CPAN::iCwd,$^X),
972            $Config::Config{'perlpath'},
973        );
974        for my $perl_name ($^X, 'perl', 'perl5', "perl$]") {
975            for my $path (File::Spec->path(), $Config::Config{'binexp'}) {
976                if ( defined($path) && length $path && -d $path ) {
977                    my $perl = File::Spec->catfile($path,$perl_name);
978                    push @candidates, $perl;
979                    # try with extension if not provided already
980                    if ($^O eq 'VMS') {
981                        # VMS might have a file version at the end
982                        push @candidates, $perl . $exe
983                            unless $perl =~ m/$exe(;\d+)?$/i;
984                    } elsif (defined $exe && length $exe) {
985                        push @candidates, $perl . $exe
986                            unless $perl =~ m/$exe$/i;
987                    }
988                }
989            }
990        }
991        for my $perl ( @candidates ) {
992            if (MM->maybe_command($perl) && _perl_is_same($perl)) {
993                $^X = $perl;
994                return $perl;
995            }
996        }
997    }
998    return $^X; # default fall back
999}
1000
1001#-> sub CPAN::exists ;
1002sub exists {
1003    my($mgr,$class,$id) = @_;
1004    CPAN::HandleConfig->load unless $CPAN::Config_loaded++;
1005    CPAN::Index->reload;
1006    ### Carp::croak "exists called without class argument" unless $class;
1007    $id ||= "";
1008    $id =~ s/:+/::/g if $class eq "CPAN::Module";
1009    my $exists;
1010    if (CPAN::_sqlite_running) {
1011        $exists = (exists $META->{readonly}{$class}{$id} or
1012                   $CPAN::SQLite->set($class, $id));
1013    } else {
1014        $exists =  exists $META->{readonly}{$class}{$id};
1015    }
1016    $exists ||= exists $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
1017}
1018
1019#-> sub CPAN::delete ;
1020sub delete {
1021  my($mgr,$class,$id) = @_;
1022  delete $META->{readonly}{$class}{$id}; # unsafe meta access, ok
1023  delete $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
1024}
1025
1026#-> sub CPAN::has_usable
1027# has_inst is sometimes too optimistic, we should replace it with this
1028# has_usable whenever a case is given
1029sub has_usable {
1030    my($self,$mod,$message) = @_;
1031    return 1 if $HAS_USABLE->{$mod};
1032    my $has_inst = $self->has_inst($mod,$message);
1033    return unless $has_inst;
1034    my $usable;
1035    $usable = {
1036
1037               #
1038               # most of these subroutines warn on the frontend, then
1039               # die if the installed version is unusable for some
1040               # reason; has_usable() then returns false when it caught
1041               # an exception, otherwise returns true and caches that;
1042               #
1043               'CPAN::Meta' => [
1044                            sub {
1045                                require CPAN::Meta;
1046                                unless (CPAN::Version->vge(CPAN::Meta->VERSION, 2.110350)) {
1047                                    for ("Will not use CPAN::Meta, need version 2.110350\n") {
1048                                        $CPAN::Frontend->mywarn($_);
1049                                        die $_;
1050                                    }
1051                                }
1052                            },
1053                           ],
1054
1055               'CPAN::Meta::Requirements' => [
1056                            sub {
1057                                if (defined $CPAN::Meta::Requirements::VERSION
1058                                    && CPAN::Version->vlt($CPAN::Meta::Requirements::VERSION, "2.120920")
1059                                   ) {
1060                                    delete $INC{"CPAN/Meta/Requirements.pm"};
1061                                }
1062                                require CPAN::Meta::Requirements;
1063                                unless (CPAN::Version->vge(CPAN::Meta::Requirements->VERSION, 2.120920)) {
1064                                    for ("Will not use CPAN::Meta::Requirements, need version 2.120920\n") {
1065                                        $CPAN::Frontend->mywarn($_);
1066                                        die $_;
1067                                    }
1068                                }
1069                            },
1070                           ],
1071
1072               'CPAN::Reporter' => [
1073                            sub {
1074                                if (defined $CPAN::Reporter::VERSION
1075                                    && CPAN::Version->vlt($CPAN::Reporter::VERSION, "1.2011")
1076                                   ) {
1077                                    delete $INC{"CPAN/Reporter.pm"};
1078                                }
1079                                require CPAN::Reporter;
1080                                unless (CPAN::Version->vge(CPAN::Reporter->VERSION, "1.2011")) {
1081                                    for ("Will not use CPAN::Reporter, need version 1.2011\n") {
1082                                        $CPAN::Frontend->mywarn($_);
1083                                        die $_;
1084                                    }
1085                                }
1086                            },
1087                           ],
1088
1089               LWP => [ # we frequently had "Can't locate object
1090                        # method "new" via package "LWP::UserAgent" at
1091                        # (eval 69) line 2006
1092                       sub {require LWP},
1093                       sub {require LWP::UserAgent},
1094                       sub {require HTTP::Request},
1095                       sub {require URI::URL;
1096                            unless (CPAN::Version->vge(URI::URL::->VERSION,0.08)) {
1097                                for ("Will not use URI::URL, need 0.08\n") {
1098                                    $CPAN::Frontend->mywarn($_);
1099                                    die $_;
1100                                }
1101                            }
1102                       },
1103                      ],
1104               'Net::FTP' => [
1105                            sub {
1106                                my $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy};
1107                                if ($var and $var =~ /^http:/i) {
1108                                    # rt #110833
1109                                    for ("Net::FTP cannot handle http proxy") {
1110                                        $CPAN::Frontend->mywarn($_);
1111                                        die $_;
1112                                    }
1113                                }
1114                            },
1115                            sub {require Net::FTP},
1116                            sub {require Net::Config},
1117                           ],
1118               'IO::Socket::SSL' => [
1119                                 sub {
1120                                     require IO::Socket::SSL;
1121                                     unless (CPAN::Version->vge(IO::Socket::SSL::->VERSION,1.56)) {
1122                                         for ("Will not use IO::Socket::SSL, need 1.56\n") {
1123                                             $CPAN::Frontend->mywarn($_);
1124                                             die $_;
1125                                         }
1126                                     }
1127                                 }
1128                                ],
1129               'Net::SSLeay' => [
1130                                 sub {
1131                                     require Net::SSLeay;
1132                                     unless (CPAN::Version->vge(Net::SSLeay::->VERSION,1.49)) {
1133                                         for ("Will not use Net::SSLeay, need 1.49\n") {
1134                                             $CPAN::Frontend->mywarn($_);
1135                                             die $_;
1136                                         }
1137                                     }
1138                                 }
1139                                ],
1140               'HTTP::Tiny' => [
1141                            sub {
1142                                require HTTP::Tiny;
1143                                unless (CPAN::Version->vge(HTTP::Tiny->VERSION, 0.005)) {
1144                                    for ("Will not use HTTP::Tiny, need version 0.005\n") {
1145                                        $CPAN::Frontend->mywarn($_);
1146                                        die $_;
1147                                    }
1148                                }
1149                            },
1150                           ],
1151               'File::HomeDir' => [
1152                                   sub {require File::HomeDir;
1153                                        unless (CPAN::Version->vge(File::HomeDir::->VERSION, 0.52)) {
1154                                            for ("Will not use File::HomeDir, need 0.52\n") {
1155                                                $CPAN::Frontend->mywarn($_);
1156                                                die $_;
1157                                            }
1158                                        }
1159                                    },
1160                                  ],
1161               'Archive::Tar' => [
1162                                  sub {require Archive::Tar;
1163                                       my $demand = "1.50";
1164                                       unless (CPAN::Version->vge(Archive::Tar::->VERSION, $demand)) {
1165                                            my $atv = Archive::Tar->VERSION;
1166                                            for ("You have Archive::Tar $atv, but $demand or later is recommended. Please upgrade.\n") {
1167                                                $CPAN::Frontend->mywarn($_);
1168                                            # don't die, because we may need
1169                                            # Archive::Tar to upgrade
1170                                            }
1171
1172                                       }
1173                                  },
1174                                 ],
1175               'File::Temp' => [
1176                                # XXX we should probably delete from
1177                                # %INC too so we can load after we
1178                                # installed a new enough version --
1179                                # I'm not sure.
1180                                sub {require File::Temp;
1181                                     unless (CPAN::Version->vge(File::Temp::->VERSION,0.16)) {
1182                                         for ("Will not use File::Temp, need 0.16\n") {
1183                                                $CPAN::Frontend->mywarn($_);
1184                                                die $_;
1185                                         }
1186                                     }
1187                                },
1188                               ]
1189              };
1190    if ($usable->{$mod}) {
1191        local @INC = @INC;
1192        pop @INC if $INC[-1] eq '.';
1193        for my $c (0..$#{$usable->{$mod}}) {
1194            my $code = $usable->{$mod}[$c];
1195            my $ret = eval { &$code() };
1196            $ret = "" unless defined $ret;
1197            if ($@) {
1198                # warn "DEBUG: c[$c]\$\@[$@]ret[$ret]";
1199                return;
1200            }
1201        }
1202    }
1203    return $HAS_USABLE->{$mod} = 1;
1204}
1205
1206sub frontend {
1207    shift;
1208    $CPAN::Frontend = shift if @_;
1209    $CPAN::Frontend;
1210}
1211
1212sub use_inst {
1213    my ($self, $module) = @_;
1214
1215    unless ($self->has_inst($module)) {
1216        $self->frontend->mydie("$module not installed, cannot continue");
1217    }
1218}
1219
1220#-> sub CPAN::has_inst
1221sub has_inst {
1222    my($self,$mod,$message) = @_;
1223    Carp::croak("CPAN->has_inst() called without an argument")
1224        unless defined $mod;
1225    my %dont = map { $_ => 1 } keys %{$CPAN::META->{dontload_hash}||{}},
1226        keys %{$CPAN::Config->{dontload_hash}||{}},
1227            @{$CPAN::Config->{dontload_list}||[]};
1228    if (defined $message && $message eq "no"  # as far as I remember only used by Nox
1229        ||
1230        $dont{$mod}
1231       ) {
1232      $CPAN::META->{dontload_hash}{$mod}||=1; # unsafe meta access, ok
1233      return 0;
1234    }
1235    local @INC = @INC;
1236    pop @INC if $INC[-1] eq '.';
1237    my $file = $mod;
1238    my $obj;
1239    $file =~ s|::|/|g;
1240    $file .= ".pm";
1241    if ($INC{$file}) {
1242        # checking %INC is wrong, because $INC{LWP} may be true
1243        # although $INC{"URI/URL.pm"} may have failed. But as
1244        # I really want to say "blah loaded OK", I have to somehow
1245        # cache results.
1246        ### warn "$file in %INC"; #debug
1247        return 1;
1248    } elsif (eval { require $file }) {
1249        # eval is good: if we haven't yet read the database it's
1250        # perfect and if we have installed the module in the meantime,
1251        # it tries again. The second require is only a NOOP returning
1252        # 1 if we had success, otherwise it's retrying
1253
1254        my $mtime = (stat $INC{$file})[9];
1255        # privileged files loaded by has_inst; Note: we use $mtime
1256        # as a proxy for a checksum.
1257        $CPAN::Shell::reload->{$file} = $mtime;
1258        my $v = eval "\$$mod\::VERSION";
1259        $v = $v ? " (v$v)" : "";
1260        CPAN::Shell->optprint("load_module","CPAN: $mod loaded ok$v\n");
1261        if ($mod eq "CPAN::WAIT") {
1262            push @CPAN::Shell::ISA, 'CPAN::WAIT';
1263        }
1264        return 1;
1265    } elsif ($mod eq "Net::FTP") {
1266        $CPAN::Frontend->mywarn(qq{
1267  Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
1268  if you just type
1269      install Bundle::libnet
1270
1271}) unless $Have_warned->{"Net::FTP"}++;
1272        $CPAN::Frontend->mysleep(3);
1273    } elsif ($mod eq "Digest::SHA") {
1274        if ($Have_warned->{"Digest::SHA"}++) {
1275            $CPAN::Frontend->mywarn(qq{CPAN: checksum security checks disabled }.
1276                                     qq{because Digest::SHA not installed.\n});
1277        } else {
1278            $CPAN::Frontend->mywarn(qq{
1279  CPAN: checksum security checks disabled because Digest::SHA not installed.
1280  Please consider installing the Digest::SHA module.
1281
1282});
1283            $CPAN::Frontend->mysleep(2);
1284        }
1285    } elsif ($mod eq "Module::Signature") {
1286        # NOT prefs_lookup, we are not a distro
1287        my $check_sigs = $CPAN::Config->{check_sigs};
1288        if (not $check_sigs) {
1289            # they do not want us:-(
1290        } elsif (not $Have_warned->{"Module::Signature"}++) {
1291            # No point in complaining unless the user can
1292            # reasonably install and use it.
1293            if (eval { require Crypt::OpenPGP; 1 } ||
1294                (
1295                 defined $CPAN::Config->{'gpg'}
1296                 &&
1297                 $CPAN::Config->{'gpg'} =~ /\S/
1298                )
1299               ) {
1300                $CPAN::Frontend->mywarn(qq{
1301  CPAN: Module::Signature security checks disabled because Module::Signature
1302  not installed.  Please consider installing the Module::Signature module.
1303  You may also need to be able to connect over the Internet to the public
1304  key servers like pool.sks-keyservers.net or pgp.mit.edu.
1305
1306});
1307                $CPAN::Frontend->mysleep(2);
1308            }
1309        }
1310    } else {
1311        delete $INC{$file}; # if it inc'd LWP but failed during, say, URI
1312    }
1313    return 0;
1314}
1315
1316#-> sub CPAN::instance ;
1317sub instance {
1318    my($mgr,$class,$id) = @_;
1319    CPAN::Index->reload;
1320    $id ||= "";
1321    # unsafe meta access, ok?
1322    return $META->{readwrite}{$class}{$id} if exists $META->{readwrite}{$class}{$id};
1323    $META->{readwrite}{$class}{$id} ||= $class->new(ID => $id);
1324}
1325
1326#-> sub CPAN::new ;
1327sub new {
1328    bless {}, shift;
1329}
1330
1331#-> sub CPAN::_exit_messages ;
1332sub _exit_messages {
1333    my ($self) = @_;
1334    $self->{exit_messages} ||= [];
1335}
1336
1337#-> sub CPAN::cleanup ;
1338sub cleanup {
1339  # warn "cleanup called with arg[@_] End[$CPAN::End] Signal[$Signal]";
1340  local $SIG{__DIE__} = '';
1341  my($message) = @_;
1342  my $i = 0;
1343  my $ineval = 0;
1344  my($subroutine);
1345  while ((undef,undef,undef,$subroutine) = caller(++$i)) {
1346      $ineval = 1, last if
1347        $subroutine eq '(eval)';
1348  }
1349  return if $ineval && !$CPAN::End;
1350  return unless defined $META->{LOCK};
1351  return unless -f $META->{LOCK};
1352  $META->savehist;
1353  $META->{cachemgr} ||= CPAN::CacheMgr->new('atexit');
1354  close $META->{LOCKFH};
1355  unlink $META->{LOCK};
1356  # require Carp;
1357  # Carp::cluck("DEBUGGING");
1358  if ( $CPAN::CONFIG_DIRTY ) {
1359      $CPAN::Frontend->mywarn("Warning: Configuration not saved.\n");
1360  }
1361  $CPAN::Frontend->myprint("Lockfile removed.\n");
1362  for my $msg ( @{ $META->_exit_messages } ) {
1363      $CPAN::Frontend->myprint($msg);
1364  }
1365}
1366
1367#-> sub CPAN::readhist
1368sub readhist {
1369    my($self,$term,$histfile) = @_;
1370    my $histsize = $CPAN::Config->{'histsize'} || 100;
1371    $term->Attribs->{'MaxHistorySize'} = $histsize if (defined($term->Attribs->{'MaxHistorySize'}));
1372    my($fh) = FileHandle->new;
1373    open $fh, "<$histfile" or return;
1374    local $/ = "\n";
1375    while (<$fh>) {
1376        chomp;
1377        $term->AddHistory($_);
1378    }
1379    close $fh;
1380}
1381
1382#-> sub CPAN::savehist
1383sub savehist {
1384    my($self) = @_;
1385    my($histfile,$histsize);
1386    unless ($histfile = $CPAN::Config->{'histfile'}) {
1387        $CPAN::Frontend->mywarn("No history written (no histfile specified).\n");
1388        return;
1389    }
1390    $histsize = $CPAN::Config->{'histsize'} || 100;
1391    if ($CPAN::term) {
1392        unless ($CPAN::term->can("GetHistory")) {
1393            $CPAN::Frontend->mywarn("Terminal does not support GetHistory.\n");
1394            return;
1395        }
1396    } else {
1397        return;
1398    }
1399    my @h = $CPAN::term->GetHistory;
1400    splice @h, 0, @h-$histsize if @h>$histsize;
1401    my($fh) = FileHandle->new;
1402    open $fh, ">$histfile" or $CPAN::Frontend->mydie("Couldn't open >$histfile: $!");
1403    local $\ = local $, = "\n";
1404    print $fh @h;
1405    close $fh;
1406}
1407
1408#-> sub CPAN::is_tested
1409sub is_tested {
1410    my($self,$what,$when) = @_;
1411    unless ($what) {
1412        Carp::cluck("DEBUG: empty what");
1413        return;
1414    }
1415    $self->{is_tested}{$what} = $when;
1416}
1417
1418#-> sub CPAN::reset_tested
1419# forget all distributions tested -- resets what gets included in PERL5LIB
1420sub reset_tested {
1421    my ($self) = @_;
1422    $self->{is_tested} = {};
1423}
1424
1425#-> sub CPAN::is_installed
1426# unsets the is_tested flag: as soon as the thing is installed, it is
1427# not needed in set_perl5lib anymore
1428sub is_installed {
1429    my($self,$what) = @_;
1430    delete $self->{is_tested}{$what};
1431}
1432
1433sub _list_sorted_descending_is_tested {
1434    my($self) = @_;
1435    my $foul = 0;
1436    my @sorted = sort
1437        { ($self->{is_tested}{$b}||0) <=> ($self->{is_tested}{$a}||0) }
1438            grep
1439                { if ($foul){ 0 } elsif (-e) { 1 } else { $foul = $_; 0 } }
1440                    keys %{$self->{is_tested}};
1441    if ($foul) {
1442        $CPAN::Frontend->mywarn("Lost build_dir detected ($foul), giving up all cached test results of currently running session.\n");
1443        for my $dbd (sort keys %{$self->{is_tested}}) { # distro-build-dir
1444        SEARCH: for my $d (sort { $a->id cmp $b->id } $CPAN::META->all_objects("CPAN::Distribution")) {
1445                if ($d->{build_dir} && $d->{build_dir} eq $dbd) {
1446                    $CPAN::Frontend->mywarn(sprintf "Flushing cache for %s\n", $d->pretty_id);
1447                    $d->fforce("");
1448                    last SEARCH;
1449                }
1450            }
1451            delete $self->{is_tested}{$dbd};
1452        }
1453        return ();
1454    } else {
1455        return @sorted;
1456    }
1457}
1458
1459#-> sub CPAN::set_perl5lib
1460# Notes on max environment variable length:
1461#   - Win32 : XP or later, 8191; Win2000 or NT4, 2047
1462{
1463my $fh;
1464sub set_perl5lib {
1465    my($self,$for) = @_;
1466    unless ($for) {
1467        (undef,undef,undef,$for) = caller(1);
1468        $for =~ s/.*://;
1469    }
1470    $self->{is_tested} ||= {};
1471    return unless %{$self->{is_tested}};
1472    my $env = $ENV{PERL5LIB};
1473    $env = $ENV{PERLLIB} unless defined $env;
1474    my @env;
1475    push @env, split /\Q$Config::Config{path_sep}\E/, $env if defined $env and length $env;
1476    #my @dirs = map {("$_/blib/arch", "$_/blib/lib")} keys %{$self->{is_tested}};
1477    #$CPAN::Frontend->myprint("Prepending @dirs to PERL5LIB.\n");
1478
1479    my @dirs = map {("$_/blib/arch", "$_/blib/lib")} $self->_list_sorted_descending_is_tested;
1480    return if !@dirs;
1481
1482    if (@dirs < 12) {
1483        $CPAN::Frontend->optprint('perl5lib', "Prepending @dirs to PERL5LIB for '$for'\n");
1484        $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1485    } elsif (@dirs < 24 ) {
1486        my @d = map {my $cp = $_;
1487                     $cp =~ s/^\Q$CPAN::Config->{build_dir}\E/%BUILDDIR%/;
1488                     $cp
1489                 } @dirs;
1490        $CPAN::Frontend->optprint('perl5lib', "Prepending @d to PERL5LIB; ".
1491                                 "%BUILDDIR%=$CPAN::Config->{build_dir} ".
1492                                 "for '$for'\n"
1493                                );
1494        $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
1495    } else {
1496        my $cnt = keys %{$self->{is_tested}};
1497        my $newenv = join $Config::Config{path_sep}, @dirs, @env;
1498        $CPAN::Frontend->optprint('perl5lib', sprintf ("Prepending blib/arch and blib/lib of ".
1499                                 "%d build dirs to PERL5LIB, reaching size %d; ".
1500                                 "for '%s'\n", $cnt, length($newenv), $for)
1501                                );
1502        $ENV{PERL5LIB} = $newenv;
1503    }
1504}}
1505
1506
15071;
1508
1509
1510__END__
1511
1512=head1 NAME
1513
1514CPAN - query, download and build perl modules from CPAN sites
1515
1516=head1 SYNOPSIS
1517
1518Interactive mode:
1519
1520  perl -MCPAN -e shell
1521
1522--or--
1523
1524  cpan
1525
1526Basic commands:
1527
1528  # Modules:
1529
1530  cpan> install Acme::Meta                       # in the shell
1531
1532  CPAN::Shell->install("Acme::Meta");            # in perl
1533
1534  # Distributions:
1535
1536  cpan> install NWCLARK/Acme-Meta-0.02.tar.gz    # in the shell
1537
1538  CPAN::Shell->
1539    install("NWCLARK/Acme-Meta-0.02.tar.gz");    # in perl
1540
1541  # module objects:
1542
1543  $mo = CPAN::Shell->expandany($mod);
1544  $mo = CPAN::Shell->expand("Module",$mod);      # same thing
1545
1546  # distribution objects:
1547
1548  $do = CPAN::Shell->expand("Module",$mod)->distribution;
1549  $do = CPAN::Shell->expandany($distro);         # same thing
1550  $do = CPAN::Shell->expand("Distribution",
1551                            $distro);            # same thing
1552
1553=head1 DESCRIPTION
1554
1555The CPAN module automates or at least simplifies the make and install
1556of perl modules and extensions. It includes some primitive searching
1557capabilities and knows how to use LWP, HTTP::Tiny, Net::FTP and certain
1558external download clients to fetch distributions from the net.
1559
1560These are fetched from one or more mirrored CPAN (Comprehensive
1561Perl Archive Network) sites and unpacked in a dedicated directory.
1562
1563The CPAN module also supports named and versioned
1564I<bundles> of modules. Bundles simplify handling of sets of
1565related modules. See Bundles below.
1566
1567The package contains a session manager and a cache manager. The
1568session manager keeps track of what has been fetched, built, and
1569installed in the current session. The cache manager keeps track of the
1570disk space occupied by the make processes and deletes excess space
1571using a simple FIFO mechanism.
1572
1573All methods provided are accessible in a programmer style and in an
1574interactive shell style.
1575
1576=head2 CPAN::shell([$prompt, $command]) Starting Interactive Mode
1577
1578Enter interactive mode by running
1579
1580    perl -MCPAN -e shell
1581
1582or
1583
1584    cpan
1585
1586which puts you into a readline interface. If C<Term::ReadKey> and
1587either of C<Term::ReadLine::Perl> or C<Term::ReadLine::Gnu> are installed,
1588history and command completion are supported.
1589
1590Once at the command line, type C<h> for one-page help
1591screen; the rest should be self-explanatory.
1592
1593The function call C<shell> takes two optional arguments: one the
1594prompt, the second the default initial command line (the latter
1595only works if a real ReadLine interface module is installed).
1596
1597The most common uses of the interactive modes are
1598
1599=over 2
1600
1601=item Searching for authors, bundles, distribution files and modules
1602
1603There are corresponding one-letter commands C<a>, C<b>, C<d>, and C<m>
1604for each of the four categories and another, C<i> for any of the
1605mentioned four. Each of the four entities is implemented as a class
1606with slightly differing methods for displaying an object.
1607
1608Arguments to these commands are either strings exactly matching
1609the identification string of an object, or regular expressions
1610matched case-insensitively against various attributes of the
1611objects. The parser only recognizes a regular expression when you
1612enclose it with slashes.
1613
1614The principle is that the number of objects found influences how an
1615item is displayed. If the search finds one item, the result is
1616displayed with the rather verbose method C<as_string>, but if
1617more than one is found, each object is displayed with the terse method
1618C<as_glimpse>.
1619
1620Examples:
1621
1622  cpan> m Acme::MetaSyntactic
1623  Module id = Acme::MetaSyntactic
1624      CPAN_USERID  BOOK (Philippe Bruhat (BooK) <[...]>)
1625      CPAN_VERSION 0.99
1626      CPAN_FILE    B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
1627      UPLOAD_DATE  2006-11-06
1628      MANPAGE      Acme::MetaSyntactic - Themed metasyntactic variables names
1629      INST_FILE    /usr/local/lib/perl/5.10.0/Acme/MetaSyntactic.pm
1630      INST_VERSION 0.99
1631  cpan> a BOOK
1632  Author id = BOOK
1633      EMAIL        [...]
1634      FULLNAME     Philippe Bruhat (BooK)
1635  cpan> d BOOK/Acme-MetaSyntactic-0.99.tar.gz
1636  Distribution id = B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
1637      CPAN_USERID  BOOK (Philippe Bruhat (BooK) <[...]>)
1638      CONTAINSMODS Acme::MetaSyntactic Acme::MetaSyntactic::Alias [...]
1639      UPLOAD_DATE  2006-11-06
1640  cpan> m /lorem/
1641  Module  = Acme::MetaSyntactic::loremipsum (BOOK/Acme-MetaSyntactic-0.99.tar.gz)
1642  Module    Text::Lorem            (ADEOLA/Text-Lorem-0.3.tar.gz)
1643  Module    Text::Lorem::More      (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
1644  Module    Text::Lorem::More::Source (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
1645  cpan> i /berlin/
1646  Distribution    BEATNIK/Filter-NumberLines-0.02.tar.gz
1647  Module  = DateTime::TimeZone::Europe::Berlin (DROLSKY/DateTime-TimeZone-0.7904.tar.gz)
1648  Module    Filter::NumberLines    (BEATNIK/Filter-NumberLines-0.02.tar.gz)
1649  Author          [...]
1650
1651The examples illustrate several aspects: the first three queries
1652target modules, authors, or distros directly and yield exactly one
1653result. The last two use regular expressions and yield several
1654results. The last one targets all of bundles, modules, authors, and
1655distros simultaneously. When more than one result is available, they
1656are printed in one-line format.
1657
1658=item C<get>, C<make>, C<test>, C<install>, C<clean> modules or distributions
1659
1660These commands take any number of arguments and investigate what is
1661necessary to perform the action. Argument processing is as follows:
1662
1663  known module name in format Foo/Bar.pm   module
1664  other embedded slash                     distribution
1665    - with trailing slash dot              directory
1666  enclosing slashes                        regexp
1667  known module name in format Foo::Bar     module
1668
1669If the argument is a distribution file name (recognized by embedded
1670slashes), it is processed. If it is a module, CPAN determines the
1671distribution file in which this module is included and processes that,
1672following any dependencies named in the module's META.yml or
1673Makefile.PL (this behavior is controlled by the configuration
1674parameter C<prerequisites_policy>). If an argument is enclosed in
1675slashes it is treated as a regular expression: it is expanded and if
1676the result is a single object (distribution, bundle or module), this
1677object is processed.
1678
1679Example:
1680
1681    install Dummy::Perl                   # installs the module
1682    install AUXXX/Dummy-Perl-3.14.tar.gz  # installs that distribution
1683    install /Dummy-Perl-3.14/             # same if the regexp is unambiguous
1684
1685C<get> downloads a distribution file and untars or unzips it, C<make>
1686builds it, C<test> runs the test suite, and C<install> installs it.
1687
1688Any C<make> or C<test> is run unconditionally. An
1689
1690  install <distribution_file>
1691
1692is also run unconditionally. But for
1693
1694  install <module>
1695
1696CPAN checks whether an install is needed and prints
1697I<module up to date> if the distribution file containing
1698the module doesn't need updating.
1699
1700CPAN also keeps track of what it has done within the current session
1701and doesn't try to build a package a second time regardless of whether it
1702succeeded or not. It does not repeat a test run if the test
1703has been run successfully before. Same for install runs.
1704
1705The C<force> pragma may precede another command (currently: C<get>,
1706C<make>, C<test>, or C<install>) to execute the command from scratch
1707and attempt to continue past certain errors. See the section below on
1708the C<force> and the C<fforce> pragma.
1709
1710The C<notest> pragma skips the test part in the build
1711process.
1712
1713Example:
1714
1715    cpan> notest install Tk
1716
1717A C<clean> command results in a
1718
1719  make clean
1720
1721being executed within the distribution file's working directory.
1722
1723=item C<readme>, C<perldoc>, C<look> module or distribution
1724
1725C<readme> displays the README file of the associated distribution.
1726C<Look> gets and untars (if not yet done) the distribution file,
1727changes to the appropriate directory and opens a subshell process in
1728that directory. C<perldoc> displays the module's pod documentation
1729in html or plain text format.
1730
1731=item C<ls> author
1732
1733=item C<ls> globbing_expression
1734
1735The first form lists all distribution files in and below an author's
1736CPAN directory as stored in the CHECKSUMS files distributed on
1737CPAN. The listing recurses into subdirectories.
1738
1739The second form limits or expands the output with shell
1740globbing as in the following examples:
1741
1742      ls JV/make*
1743      ls GSAR/*make*
1744      ls */*make*
1745
1746The last example is very slow and outputs extra progress indicators
1747that break the alignment of the result.
1748
1749Note that globbing only lists directories explicitly asked for, for
1750example FOO/* will not list FOO/bar/Acme-Sthg-n.nn.tar.gz. This may be
1751regarded as a bug that may be changed in some future version.
1752
1753=item C<failed>
1754
1755The C<failed> command reports all distributions that failed on one of
1756C<make>, C<test> or C<install> for some reason in the currently
1757running shell session.
1758
1759=item Persistence between sessions
1760
1761If the C<YAML> or the C<YAML::Syck> module is installed a record of
1762the internal state of all modules is written to disk after each step.
1763The files contain a signature of the currently running perl version
1764for later perusal.
1765
1766If the configurations variable C<build_dir_reuse> is set to a true
1767value, then CPAN.pm reads the collected YAML files. If the stored
1768signature matches the currently running perl, the stored state is
1769loaded into memory such that persistence between sessions
1770is effectively established.
1771
1772=item The C<force> and the C<fforce> pragma
1773
1774To speed things up in complex installation scenarios, CPAN.pm keeps
1775track of what it has already done and refuses to do some things a
1776second time. A C<get>, a C<make>, and an C<install> are not repeated.
1777A C<test> is repeated only if the previous test was unsuccessful. The
1778diagnostic message when CPAN.pm refuses to do something a second time
1779is one of I<Has already been >C<unwrapped|made|tested successfully> or
1780something similar. Another situation where CPAN refuses to act is an
1781C<install> if the corresponding C<test> was not successful.
1782
1783In all these cases, the user can override this stubborn behaviour by
1784prepending the command with the word force, for example:
1785
1786  cpan> force get Foo
1787  cpan> force make AUTHOR/Bar-3.14.tar.gz
1788  cpan> force test Baz
1789  cpan> force install Acme::Meta
1790
1791Each I<forced> command is executed with the corresponding part of its
1792memory erased.
1793
1794The C<fforce> pragma is a variant that emulates a C<force get> which
1795erases the entire memory followed by the action specified, effectively
1796restarting the whole get/make/test/install procedure from scratch.
1797
1798=item Lockfile
1799
1800Interactive sessions maintain a lockfile, by default C<~/.cpan/.lock>.
1801Batch jobs can run without a lockfile and not disturb each other.
1802
1803The shell offers to run in I<downgraded mode> when another process is
1804holding the lockfile. This is an experimental feature that is not yet
1805tested very well. This second shell then does not write the history
1806file, does not use the metadata file, and has a different prompt.
1807
1808=item Signals
1809
1810CPAN.pm installs signal handlers for SIGINT and SIGTERM. While you are
1811in the cpan-shell, it is intended that you can press C<^C> anytime and
1812return to the cpan-shell prompt. A SIGTERM will cause the cpan-shell
1813to clean up and leave the shell loop. You can emulate the effect of a
1814SIGTERM by sending two consecutive SIGINTs, which usually means by
1815pressing C<^C> twice.
1816
1817CPAN.pm ignores SIGPIPE. If the user sets C<inactivity_timeout>, a
1818SIGALRM is used during the run of the C<perl Makefile.PL> or C<perl
1819Build.PL> subprocess. A SIGALRM is also used during module version
1820parsing, and is controlled by C<version_timeout>.
1821
1822=back
1823
1824=head2 CPAN::Shell
1825
1826The commands available in the shell interface are methods in
1827the package CPAN::Shell. If you enter the shell command, your
1828input is split by the Text::ParseWords::shellwords() routine, which
1829acts like most shells do. The first word is interpreted as the
1830method to be invoked, and the rest of the words are treated as the method's arguments.
1831Continuation lines are supported by ending a line with a
1832literal backslash.
1833
1834=head2 autobundle
1835
1836C<autobundle> writes a bundle file into the
1837C<$CPAN::Config-E<gt>{cpan_home}/Bundle> directory. The file contains
1838a list of all modules that are both available from CPAN and currently
1839installed within @INC. Duplicates of each distribution are suppressed.
1840The name of the bundle file is based on the current date and a
1841counter, e.g. F<Bundle/Snapshot_2012_05_21_00.pm>. This is installed
1842again by running C<cpan Bundle::Snapshot_2012_05_21_00>, or installing
1843C<Bundle::Snapshot_2012_05_21_00> from the CPAN shell.
1844
1845Return value: path to the written file.
1846
1847=head2 hosts
1848
1849Note: this feature is still in alpha state and may change in future
1850versions of CPAN.pm
1851
1852This commands provides a statistical overview over recent download
1853activities. The data for this is collected in the YAML file
1854C<FTPstats.yml> in your C<cpan_home> directory. If no YAML module is
1855configured or YAML not installed, no stats are provided.
1856
1857=over
1858
1859=item install_tested
1860
1861Install all distributions that have been tested successfully but have
1862not yet been installed. See also C<is_tested>.
1863
1864=item is_tested
1865
1866List all build directories of distributions that have been tested
1867successfully but have not yet been installed. See also
1868C<install_tested>.
1869
1870=back
1871
1872=head2 mkmyconfig
1873
1874mkmyconfig() writes your own CPAN::MyConfig file into your C<~/.cpan/>
1875directory so that you can save your own preferences instead of the
1876system-wide ones.
1877
1878=head2 r [Module|/Regexp/]...
1879
1880scans current perl installation for modules that have a newer version
1881available on CPAN and provides a list of them. If called without
1882argument, all potential upgrades are listed; if called with arguments
1883the list is filtered to the modules and regexps given as arguments.
1884
1885The listing looks something like this:
1886
1887  Package namespace         installed    latest  in CPAN file
1888  CPAN                        1.94_64    1.9600  ANDK/CPAN-1.9600.tar.gz
1889  CPAN::Reporter               1.1801    1.1902  DAGOLDEN/CPAN-Reporter-1.1902.tar.gz
1890  YAML                           0.70      0.73  INGY/YAML-0.73.tar.gz
1891  YAML::Syck                     1.14      1.17  AVAR/YAML-Syck-1.17.tar.gz
1892  YAML::Tiny                     1.44      1.50  ADAMK/YAML-Tiny-1.50.tar.gz
1893  CGI                            3.43      3.55  MARKSTOS/CGI.pm-3.55.tar.gz
1894  Module::Build::YAML            1.40      1.41  DAGOLDEN/Module-Build-0.3800.tar.gz
1895  TAP::Parser::Result::YAML      3.22      3.23  ANDYA/Test-Harness-3.23.tar.gz
1896  YAML::XS                       0.34      0.35  INGY/YAML-LibYAML-0.35.tar.gz
1897
1898It suppresses duplicates in the column C<in CPAN file> such that
1899distributions with many upgradeable modules are listed only once.
1900
1901Note that the list is not sorted.
1902
1903=head2 recent ***EXPERIMENTAL COMMAND***
1904
1905The C<recent> command downloads a list of recent uploads to CPAN and
1906displays them I<slowly>. While the command is running, a $SIG{INT}
1907exits the loop after displaying the current item.
1908
1909B<Note>: This command requires XML::LibXML installed.
1910
1911B<Note>: This whole command currently is just a hack and will
1912probably change in future versions of CPAN.pm, but the general
1913approach will likely remain.
1914
1915B<Note>: See also L<smoke>
1916
1917=head2 recompile
1918
1919recompile() is a special command that takes no argument and
1920runs the make/test/install cycle with brute force over all installed
1921dynamically loadable extensions (a.k.a. XS modules) with 'force' in
1922effect. The primary purpose of this command is to finish a network
1923installation. Imagine you have a common source tree for two different
1924architectures. You decide to do a completely independent fresh
1925installation. You start on one architecture with the help of a Bundle
1926file produced earlier. CPAN installs the whole Bundle for you, but
1927when you try to repeat the job on the second architecture, CPAN
1928responds with a C<"Foo up to date"> message for all modules. So you
1929invoke CPAN's recompile on the second architecture and you're done.
1930
1931Another popular use for C<recompile> is to act as a rescue in case your
1932perl breaks binary compatibility. If one of the modules that CPAN uses
1933is in turn depending on binary compatibility (so you cannot run CPAN
1934commands), then you should try the CPAN::Nox module for recovery.
1935
1936=head2 report Bundle|Distribution|Module
1937
1938The C<report> command temporarily turns on the C<test_report> config
1939variable, then runs the C<force test> command with the given
1940arguments. The C<force> pragma reruns the tests and repeats
1941every step that might have failed before.
1942
1943=head2 smoke ***EXPERIMENTAL COMMAND***
1944
1945B<*** WARNING: this command downloads and executes software from CPAN to
1946your computer of completely unknown status. You should never do
1947this with your normal account and better have a dedicated well
1948separated and secured machine to do this. ***>
1949
1950The C<smoke> command takes the list of recent uploads to CPAN as
1951provided by the C<recent> command and tests them all. While the
1952command is running $SIG{INT} is defined to mean that the current item
1953shall be skipped.
1954
1955B<Note>: This whole command currently is just a hack and will
1956probably change in future versions of CPAN.pm, but the general
1957approach will likely remain.
1958
1959B<Note>: See also L<recent>
1960
1961=head2 upgrade [Module|/Regexp/]...
1962
1963The C<upgrade> command first runs an C<r> command with the given
1964arguments and then installs the newest versions of all modules that
1965were listed by that.
1966
1967=head2 The four C<CPAN::*> Classes: Author, Bundle, Module, Distribution
1968
1969Although it may be considered internal, the class hierarchy does matter
1970for both users and programmer. CPAN.pm deals with the four
1971classes mentioned above, and those classes all share a set of methods. Classical
1972single polymorphism is in effect. A metaclass object registers all
1973objects of all kinds and indexes them with a string. The strings
1974referencing objects have a separated namespace (well, not completely
1975separated):
1976
1977         Namespace                         Class
1978
1979   words containing a "/" (slash)      Distribution
1980    words starting with Bundle::          Bundle
1981          everything else            Module or Author
1982
1983Modules know their associated Distribution objects. They always refer
1984to the most recent official release. Developers may mark their releases
1985as unstable development versions (by inserting an underscore into the
1986module version number which will also be reflected in the distribution
1987name when you run 'make dist'), so the really hottest and newest
1988distribution is not always the default.  If a module Foo circulates
1989on CPAN in both version 1.23 and 1.23_90, CPAN.pm offers a convenient
1990way to install version 1.23 by saying
1991
1992    install Foo
1993
1994This would install the complete distribution file (say
1995BAR/Foo-1.23.tar.gz) with all accompanying material. But if you would
1996like to install version 1.23_90, you need to know where the
1997distribution file resides on CPAN relative to the authors/id/
1998directory. If the author is BAR, this might be BAR/Foo-1.23_90.tar.gz;
1999so you would have to say
2000
2001    install BAR/Foo-1.23_90.tar.gz
2002
2003The first example will be driven by an object of the class
2004CPAN::Module, the second by an object of class CPAN::Distribution.
2005
2006=head2 Integrating local directories
2007
2008Note: this feature is still in alpha state and may change in future
2009versions of CPAN.pm
2010
2011Distribution objects are normally distributions from the CPAN, but
2012there is a slightly degenerate case for Distribution objects, too, of
2013projects held on the local disk. These distribution objects have the
2014same name as the local directory and end with a dot. A dot by itself
2015is also allowed for the current directory at the time CPAN.pm was
2016used. All actions such as C<make>, C<test>, and C<install> are applied
2017directly to that directory. This gives the command C<cpan .> an
2018interesting touch: while the normal mantra of installing a CPAN module
2019without CPAN.pm is one of
2020
2021    perl Makefile.PL                 perl Build.PL
2022           ( go and get prerequisites )
2023    make                             ./Build
2024    make test                        ./Build test
2025    make install                     ./Build install
2026
2027the command C<cpan .> does all of this at once. It figures out which
2028of the two mantras is appropriate, fetches and installs all
2029prerequisites, takes care of them recursively, and finally finishes the
2030installation of the module in the current directory, be it a CPAN
2031module or not.
2032
2033The typical usage case is for private modules or working copies of
2034projects from remote repositories on the local disk.
2035
2036=head2 Redirection
2037
2038The usual shell redirection symbols C< | > and C<< > >> are recognized
2039by the cpan shell B<only when surrounded by whitespace>. So piping to
2040pager or redirecting output into a file works somewhat as in a normal
2041shell, with the stipulation that you must type extra spaces.
2042
2043=head2 Plugin support ***EXPERIMENTAL***
2044
2045Plugins are objects that implement any of currently eight methods:
2046
2047  pre_get
2048  post_get
2049  pre_make
2050  post_make
2051  pre_test
2052  post_test
2053  pre_install
2054  post_install
2055
2056The C<plugin_list> configuration parameter holds a list of strings of
2057the form
2058
2059  Modulename=arg0,arg1,arg2,arg3,...
2060
2061eg:
2062
2063  CPAN::Plugin::Flurb=dir,/opt/pkgs/flurb/raw,verbose,1
2064
2065At run time, each listed plugin is instantiated as a singleton object
2066by running the equivalent of this pseudo code:
2067
2068  my $plugin = <string representation from config>;
2069  <generate Modulename and arguments from $plugin>;
2070  my $p = $instance{$plugin} ||= Modulename->new($arg0,$arg1,...);
2071
2072The generated singletons are kept around from instantiation until the
2073end of the shell session. <plugin_list> can be reconfigured at any
2074time at run time. While the cpan shell is running, it checks all
2075activated plugins at each of the 8 reference points listed above and
2076runs the respective method if it is implemented for that object. The
2077method is called with the active CPAN::Distribution object passed in
2078as an argument.
2079
2080=head1 CONFIGURATION
2081
2082When the CPAN module is used for the first time, a configuration
2083dialogue tries to determine a couple of site specific options. The
2084result of the dialog is stored in a hash reference C< $CPAN::Config >
2085in a file CPAN/Config.pm.
2086
2087Default values defined in the CPAN/Config.pm file can be
2088overridden in a user specific file: CPAN/MyConfig.pm. Such a file is
2089best placed in C<$HOME/.cpan/CPAN/MyConfig.pm>, because C<$HOME/.cpan> is
2090added to the search path of the CPAN module before the use() or
2091require() statements. The mkmyconfig command writes this file for you.
2092
2093The C<o conf> command has various bells and whistles:
2094
2095=over
2096
2097=item completion support
2098
2099If you have a ReadLine module installed, you can hit TAB at any point
2100of the commandline and C<o conf> will offer you completion for the
2101built-in subcommands and/or config variable names.
2102
2103=item displaying some help: o conf help
2104
2105Displays a short help
2106
2107=item displaying current values: o conf [KEY]
2108
2109Displays the current value(s) for this config variable. Without KEY,
2110displays all subcommands and config variables.
2111
2112Example:
2113
2114  o conf shell
2115
2116If KEY starts and ends with a slash, the string in between is
2117treated as a regular expression and only keys matching this regexp
2118are displayed
2119
2120Example:
2121
2122  o conf /color/
2123
2124=item changing of scalar values: o conf KEY VALUE
2125
2126Sets the config variable KEY to VALUE. The empty string can be
2127specified as usual in shells, with C<''> or C<"">
2128
2129Example:
2130
2131  o conf wget /usr/bin/wget
2132
2133=item changing of list values: o conf KEY SHIFT|UNSHIFT|PUSH|POP|SPLICE|LIST
2134
2135If a config variable name ends with C<list>, it is a list. C<o conf
2136KEY shift> removes the first element of the list, C<o conf KEY pop>
2137removes the last element of the list. C<o conf KEYS unshift LIST>
2138prepends a list of values to the list, C<o conf KEYS push LIST>
2139appends a list of valued to the list.
2140
2141Likewise, C<o conf KEY splice LIST> passes the LIST to the corresponding
2142splice command.
2143
2144Finally, any other list of arguments is taken as a new list value for
2145the KEY variable discarding the previous value.
2146
2147Examples:
2148
2149  o conf urllist unshift http://cpan.dev.local/CPAN
2150  o conf urllist splice 3 1
2151  o conf urllist http://cpan1.local http://cpan2.local ftp://ftp.perl.org
2152
2153=item reverting to saved: o conf defaults
2154
2155Reverts all config variables to the state in the saved config file.
2156
2157=item saving the config: o conf commit
2158
2159Saves all config variables to the current config file (CPAN/Config.pm
2160or CPAN/MyConfig.pm that was loaded at start).
2161
2162=back
2163
2164The configuration dialog can be started any time later again by
2165issuing the command C< o conf init > in the CPAN shell. A subset of
2166the configuration dialog can be run by issuing C<o conf init WORD>
2167where WORD is any valid config variable or a regular expression.
2168
2169=head2 Config Variables
2170
2171The following keys in the hash reference $CPAN::Config are
2172currently defined:
2173
2174  allow_installing_module_downgrades
2175                     allow or disallow installing module downgrades
2176  allow_installing_outdated_dists
2177                     allow or disallow installing modules that are
2178                     indexed in the cpan index pointing to a distro
2179                     with a higher distro-version number
2180  applypatch         path to external prg
2181  auto_commit        commit all changes to config variables to disk
2182  build_cache        size of cache for directories to build modules
2183  build_dir          locally accessible directory to build modules
2184  build_dir_reuse    boolean if distros in build_dir are persistent
2185  build_requires_install_policy
2186                     to install or not to install when a module is
2187                     only needed for building. yes|no|ask/yes|ask/no
2188  bzip2              path to external prg
2189  cache_metadata     use serializer to cache metadata
2190  check_sigs         if signatures should be verified
2191  cleanup_after_install
2192                     remove build directory immediately after a
2193                     successful install and remember that for the
2194                     duration of the session
2195  colorize_debug     Term::ANSIColor attributes for debugging output
2196  colorize_output    boolean if Term::ANSIColor should colorize output
2197  colorize_print     Term::ANSIColor attributes for normal output
2198  colorize_warn      Term::ANSIColor attributes for warnings
2199  commandnumber_in_prompt
2200                     boolean if you want to see current command number
2201  commands_quote     preferred character to use for quoting external
2202                     commands when running them. Defaults to double
2203                     quote on Windows, single tick everywhere else;
2204                     can be set to space to disable quoting
2205  connect_to_internet_ok
2206                     whether to ask if opening a connection is ok before
2207                     urllist is specified
2208  cpan_home          local directory reserved for this package
2209  curl               path to external prg
2210  dontload_hash      DEPRECATED
2211  dontload_list      arrayref: modules in the list will not be
2212                     loaded by the CPAN::has_inst() routine
2213  ftp                path to external prg
2214  ftp_passive        if set, the environment variable FTP_PASSIVE is set
2215                     for downloads
2216  ftp_proxy          proxy host for ftp requests
2217  ftpstats_period    max number of days to keep download statistics
2218  ftpstats_size      max number of items to keep in the download statistics
2219  getcwd             see below
2220  gpg                path to external prg
2221  gzip               location of external program gzip
2222  halt_on_failure    stop processing after the first failure of queued
2223                     items or dependencies
2224  histfile           file to maintain history between sessions
2225  histsize           maximum number of lines to keep in histfile
2226  http_proxy         proxy host for http requests
2227  inactivity_timeout breaks interactive Makefile.PLs or Build.PLs
2228                     after this many seconds inactivity. Set to 0 to
2229                     disable timeouts.
2230  index_expire       refetch index files after this many days
2231  inhibit_startup_message
2232                     if true, suppress the startup message
2233  keep_source_where  directory in which to keep the source (if we do)
2234  load_module_verbosity
2235                     report loading of optional modules used by CPAN.pm
2236  lynx               path to external prg
2237  make               location of external make program
2238  make_arg           arguments that should always be passed to 'make'
2239  make_install_make_command
2240                     the make command for running 'make install', for
2241                     example 'sudo make'
2242  make_install_arg   same as make_arg for 'make install'
2243  makepl_arg         arguments passed to 'perl Makefile.PL'
2244  mbuild_arg         arguments passed to './Build'
2245  mbuild_install_arg arguments passed to './Build install'
2246  mbuild_install_build_command
2247                     command to use instead of './Build' when we are
2248                     in the install stage, for example 'sudo ./Build'
2249  mbuildpl_arg       arguments passed to 'perl Build.PL'
2250  ncftp              path to external prg
2251  ncftpget           path to external prg
2252  no_proxy           don't proxy to these hosts/domains (comma separated list)
2253  pager              location of external program more (or any pager)
2254  password           your password if you CPAN server wants one
2255  patch              path to external prg
2256  patches_dir        local directory containing patch files
2257  perl5lib_verbosity verbosity level for PERL5LIB additions
2258  plugin_list        list of active hooks (see Plugin support above
2259                     and the CPAN::Plugin module)
2260  prefer_external_tar
2261                     per default all untar operations are done with
2262                     Archive::Tar; by setting this variable to true
2263                     the external tar command is used if available
2264  prefer_installer   legal values are MB and EUMM: if a module comes
2265                     with both a Makefile.PL and a Build.PL, use the
2266                     former (EUMM) or the latter (MB); if the module
2267                     comes with only one of the two, that one will be
2268                     used no matter the setting
2269  prerequisites_policy
2270                     what to do if you are missing module prerequisites
2271                     ('follow' automatically, 'ask' me, or 'ignore')
2272                     For 'follow', also sets PERL_AUTOINSTALL and
2273                     PERL_EXTUTILS_AUTOINSTALL for "--defaultdeps" if
2274                     not already set
2275  prefs_dir          local directory to store per-distro build options
2276  proxy_user         username for accessing an authenticating proxy
2277  proxy_pass         password for accessing an authenticating proxy
2278  pushy_https        use https to cpan.org when possible, otherwise use http
2279                     to cpan.org and issue a warning
2280  randomize_urllist  add some randomness to the sequence of the urllist
2281  recommends_policy  whether recommended prerequisites should be included
2282  scan_cache         controls scanning of cache ('atstart', 'atexit' or 'never')
2283  shell              your favorite shell
2284  show_unparsable_versions
2285                     boolean if r command tells which modules are versionless
2286  show_upload_date   boolean if commands should try to determine upload date
2287  show_zero_versions boolean if r command tells for which modules $version==0
2288  suggests_policy    whether suggested prerequisites should be included
2289  tar                location of external program tar
2290  tar_verbosity      verbosity level for the tar command
2291  term_is_latin      deprecated: if true Unicode is translated to ISO-8859-1
2292                     (and nonsense for characters outside latin range)
2293  term_ornaments     boolean to turn ReadLine ornamenting on/off
2294  test_report        email test reports (if CPAN::Reporter is installed)
2295  trust_test_report_history
2296                     skip testing when previously tested ok (according to
2297                     CPAN::Reporter history)
2298  unzip              location of external program unzip
2299  urllist            arrayref to nearby CPAN sites (or equivalent locations)
2300  urllist_ping_external
2301                     use external ping command when autoselecting mirrors
2302  urllist_ping_verbose
2303                     increase verbosity when autoselecting mirrors
2304  use_prompt_default set PERL_MM_USE_DEFAULT for configure/make/test/install
2305  use_sqlite         use CPAN::SQLite for metadata storage (fast and lean)
2306  username           your username if you CPAN server wants one
2307  version_timeout    stops version parsing after this many seconds.
2308                     Default is 15 secs. Set to 0 to disable.
2309  wait_list          arrayref to a wait server to try (See CPAN::WAIT)
2310  wget               path to external prg
2311  yaml_load_code     enable YAML code deserialisation via CPAN::DeferredCode
2312  yaml_module        which module to use to read/write YAML files
2313
2314You can set and query each of these options interactively in the cpan
2315shell with the C<o conf> or the C<o conf init> command as specified below.
2316
2317=over 2
2318
2319=item C<o conf E<lt>scalar optionE<gt>>
2320
2321prints the current value of the I<scalar option>
2322
2323=item C<o conf E<lt>scalar optionE<gt> E<lt>valueE<gt>>
2324
2325Sets the value of the I<scalar option> to I<value>
2326
2327=item C<o conf E<lt>list optionE<gt>>
2328
2329prints the current value of the I<list option> in MakeMaker's
2330neatvalue format.
2331
2332=item C<o conf E<lt>list optionE<gt> [shift|pop]>
2333
2334shifts or pops the array in the I<list option> variable
2335
2336=item C<o conf E<lt>list optionE<gt> [unshift|push|splice] E<lt>listE<gt>>
2337
2338works like the corresponding perl commands.
2339
2340=item interactive editing: o conf init [MATCH|LIST]
2341
2342Runs an interactive configuration dialog for matching variables.
2343Without argument runs the dialog over all supported config variables.
2344To specify a MATCH the argument must be enclosed by slashes.
2345
2346Examples:
2347
2348  o conf init ftp_passive ftp_proxy
2349  o conf init /color/
2350
2351Note: this method of setting config variables often provides more
2352explanation about the functioning of a variable than the manpage.
2353
2354=back
2355
2356=head2 CPAN::anycwd($path): Note on config variable getcwd
2357
2358CPAN.pm changes the current working directory often and needs to
2359determine its own current working directory. By default it uses
2360Cwd::cwd, but if for some reason this doesn't work on your system,
2361configure alternatives according to the following table:
2362
2363=over 4
2364
2365=item cwd
2366
2367Calls Cwd::cwd
2368
2369=item getcwd
2370
2371Calls Cwd::getcwd
2372
2373=item fastcwd
2374
2375Calls Cwd::fastcwd
2376
2377=item getdcwd
2378
2379Calls Cwd::getdcwd
2380
2381=item backtickcwd
2382
2383Calls the external command cwd.
2384
2385=back
2386
2387=head2 Note on the format of the urllist parameter
2388
2389urllist parameters are URLs according to RFC 1738. We do a little
2390guessing if your URL is not compliant, but if you have problems with
2391C<file> URLs, please try the correct format. Either:
2392
2393    file://localhost/whatever/ftp/pub/CPAN/
2394
2395or
2396
2397    file:///home/ftp/pub/CPAN/
2398
2399=head2 The urllist parameter has CD-ROM support
2400
2401The C<urllist> parameter of the configuration table contains a list of
2402URLs used for downloading. If the list contains any
2403C<file> URLs, CPAN always tries there first. This
2404feature is disabled for index files. So the recommendation for the
2405owner of a CD-ROM with CPAN contents is: include your local, possibly
2406outdated CD-ROM as a C<file> URL at the end of urllist, e.g.
2407
2408  o conf urllist push file://localhost/CDROM/CPAN
2409
2410CPAN.pm will then fetch the index files from one of the CPAN sites
2411that come at the beginning of urllist. It will later check for each
2412module to see whether there is a local copy of the most recent version.
2413
2414Another peculiarity of urllist is that the site that we could
2415successfully fetch the last file from automatically gets a preference
2416token and is tried as the first site for the next request. So if you
2417add a new site at runtime it may happen that the previously preferred
2418site will be tried another time. This means that if you want to disallow
2419a site for the next transfer, it must be explicitly removed from
2420urllist.
2421
2422=head2 Maintaining the urllist parameter
2423
2424If you have YAML.pm (or some other YAML module configured in
2425C<yaml_module>) installed, CPAN.pm collects a few statistical data
2426about recent downloads. You can view the statistics with the C<hosts>
2427command or inspect them directly by looking into the C<FTPstats.yml>
2428file in your C<cpan_home> directory.
2429
2430To get some interesting statistics, it is recommended that
2431C<randomize_urllist> be set; this introduces some amount of
2432randomness into the URL selection.
2433
2434=head2 The C<requires> and C<build_requires> dependency declarations
2435
2436Since CPAN.pm version 1.88_51 modules declared as C<build_requires> by
2437a distribution are treated differently depending on the config
2438variable C<build_requires_install_policy>. By setting
2439C<build_requires_install_policy> to C<no>, such a module is not
2440installed. It is only built and tested, and then kept in the list of
2441tested but uninstalled modules. As such, it is available during the
2442build of the dependent module by integrating the path to the
2443C<blib/arch> and C<blib/lib> directories in the environment variable
2444PERL5LIB. If C<build_requires_install_policy> is set to C<yes>, then
2445both modules declared as C<requires> and those declared as
2446C<build_requires> are treated alike. By setting to C<ask/yes> or
2447C<ask/no>, CPAN.pm asks the user and sets the default accordingly.
2448
2449=head2 Configuration of the allow_installing_* parameters
2450
2451The C<allow_installing_*> parameters are evaluated during
2452the C<make> phase. If set to C<yes>, they allow the testing and the installation of
2453the current distro and otherwise have no effect. If set to C<no>, they
2454may abort the build (preventing testing and installing), depending on the contents of the
2455C<blib/> directory. The C<blib/> directory is the directory that holds
2456all the files that would usually be installed in the C<install> phase.
2457
2458C<allow_installing_outdated_dists> compares the C<blib/> directory with the CPAN index.
2459If it finds something there that belongs, according to the index, to a different
2460dist, it aborts the current build.
2461
2462C<allow_installing_module_downgrades> compares the C<blib/> directory
2463with already installed modules, actually their version numbers, as
2464determined by ExtUtils::MakeMaker or equivalent. If a to-be-installed
2465module would downgrade an already installed module, the current build
2466is aborted.
2467
2468An interesting twist occurs when a distroprefs document demands the
2469installation of an outdated dist via goto while
2470C<allow_installing_outdated_dists> forbids it. Without additional
2471provisions, this would let the C<allow_installing_outdated_dists>
2472win and the distroprefs lose. So the proper arrangement in such a case
2473is to write a second distroprefs document for the distro that C<goto>
2474points to and overrule the C<cpanconfig> there. E.g.:
2475
2476  ---
2477  match:
2478    distribution: "^MAUKE/Keyword-Simple-0.04.tar.gz"
2479  goto: "MAUKE/Keyword-Simple-0.03.tar.gz"
2480  ---
2481  match:
2482    distribution: "^MAUKE/Keyword-Simple-0.03.tar.gz"
2483  cpanconfig:
2484    allow_installing_outdated_dists: yes
2485
2486=head2 Configuration for individual distributions (I<Distroprefs>)
2487
2488(B<Note:> This feature has been introduced in CPAN.pm 1.8854)
2489
2490Distributions on CPAN usually behave according to what we call the
2491CPAN mantra. Or since the advent of Module::Build we should talk about
2492two mantras:
2493
2494    perl Makefile.PL     perl Build.PL
2495    make                 ./Build
2496    make test            ./Build test
2497    make install         ./Build install
2498
2499But some modules cannot be built with this mantra. They try to get
2500some extra data from the user via the environment, extra arguments, or
2501interactively--thus disturbing the installation of large bundles like
2502Phalanx100 or modules with many dependencies like Plagger.
2503
2504The distroprefs system of C<CPAN.pm> addresses this problem by
2505allowing the user to specify extra informations and recipes in YAML
2506files to either
2507
2508=over
2509
2510=item
2511
2512pass additional arguments to one of the four commands,
2513
2514=item
2515
2516set environment variables
2517
2518=item
2519
2520instantiate an Expect object that reads from the console, waits for
2521some regular expressions and enters some answers
2522
2523=item
2524
2525temporarily override assorted C<CPAN.pm> configuration variables
2526
2527=item
2528
2529specify dependencies the original maintainer forgot
2530
2531=item
2532
2533disable the installation of an object altogether
2534
2535=back
2536
2537See the YAML and Data::Dumper files that come with the C<CPAN.pm>
2538distribution in the C<distroprefs/> directory for examples.
2539
2540=head2 Filenames
2541
2542The YAML files themselves must have the C<.yml> extension; all other
2543files are ignored (for two exceptions see I<Fallback Data::Dumper and
2544Storable> below). The containing directory can be specified in
2545C<CPAN.pm> in the C<prefs_dir> config variable. Try C<o conf init
2546prefs_dir> in the CPAN shell to set and activate the distroprefs
2547system.
2548
2549Every YAML file may contain arbitrary documents according to the YAML
2550specification, and every document is treated as an entity that
2551can specify the treatment of a single distribution.
2552
2553Filenames can be picked arbitrarily; C<CPAN.pm> always reads
2554all files (in alphabetical order) and takes the key C<match> (see
2555below in I<Language Specs>) as a hashref containing match criteria
2556that determine if the current distribution matches the YAML document
2557or not.
2558
2559=head2 Fallback Data::Dumper and Storable
2560
2561If neither your configured C<yaml_module> nor YAML.pm is installed,
2562CPAN.pm falls back to using Data::Dumper and Storable and looks for
2563files with the extensions C<.dd> or C<.st> in the C<prefs_dir>
2564directory. These files are expected to contain one or more hashrefs.
2565For Data::Dumper generated files, this is expected to be done with by
2566defining C<$VAR1>, C<$VAR2>, etc. The YAML shell would produce these
2567with the command
2568
2569    ysh < somefile.yml > somefile.dd
2570
2571For Storable files the rule is that they must be constructed such that
2572C<Storable::retrieve(file)> returns an array reference and the array
2573elements represent one distropref object each. The conversion from
2574YAML would look like so:
2575
2576    perl -MYAML=LoadFile -MStorable=nstore -e '
2577        @y=LoadFile(shift);
2578        nstore(\@y, shift)' somefile.yml somefile.st
2579
2580In bootstrapping situations it is usually sufficient to translate only
2581a few YAML files to Data::Dumper for crucial modules like
2582C<YAML::Syck>, C<YAML.pm> and C<Expect.pm>. If you prefer Storable
2583over Data::Dumper, remember to pull out a Storable version that writes
2584an older format than all the other Storable versions that will need to
2585read them.
2586
2587=head2 Blueprint
2588
2589The following example contains all supported keywords and structures
2590with the exception of C<eexpect> which can be used instead of
2591C<expect>.
2592
2593  ---
2594  comment: "Demo"
2595  match:
2596    module: "Dancing::Queen"
2597    distribution: "^CHACHACHA/Dancing-"
2598    not_distribution: "\.zip$"
2599    perl: "/usr/local/cariba-perl/bin/perl"
2600    perlconfig:
2601      archname: "freebsd"
2602      not_cc: "gcc"
2603    env:
2604      DANCING_FLOOR: "Shubiduh"
2605  disabled: 1
2606  cpanconfig:
2607    make: gmake
2608  pl:
2609    args:
2610      - "--somearg=specialcase"
2611
2612    env: {}
2613
2614    expect:
2615      - "Which is your favorite fruit"
2616      - "apple\n"
2617
2618  make:
2619    args:
2620      - all
2621      - extra-all
2622
2623    env: {}
2624
2625    expect: []
2626
2627    commandline: "echo SKIPPING make"
2628
2629  test:
2630    args: []
2631
2632    env: {}
2633
2634    expect: []
2635
2636  install:
2637    args: []
2638
2639    env:
2640      WANT_TO_INSTALL: YES
2641
2642    expect:
2643      - "Do you really want to install"
2644      - "y\n"
2645
2646  patches:
2647    - "ABCDE/Fedcba-3.14-ABCDE-01.patch"
2648
2649  depends:
2650    configure_requires:
2651      LWP: 5.8
2652    build_requires:
2653      Test::Exception: 0.25
2654    requires:
2655      Spiffy: 0.30
2656
2657
2658=head2 Language Specs
2659
2660Every YAML document represents a single hash reference. The valid keys
2661in this hash are as follows:
2662
2663=over
2664
2665=item comment [scalar]
2666
2667A comment
2668
2669=item cpanconfig [hash]
2670
2671Temporarily override assorted C<CPAN.pm> configuration variables.
2672
2673Supported are: C<build_requires_install_policy>, C<check_sigs>,
2674C<make>, C<make_install_make_command>, C<prefer_installer>,
2675C<test_report>. Please report as a bug when you need another one
2676supported.
2677
2678=item depends [hash] *** EXPERIMENTAL FEATURE ***
2679
2680All three types, namely C<configure_requires>, C<build_requires>, and
2681C<requires> are supported in the way specified in the META.yml
2682specification. The current implementation I<merges> the specified
2683dependencies with those declared by the package maintainer. In a
2684future implementation this may be changed to override the original
2685declaration.
2686
2687=item disabled [boolean]
2688
2689Specifies that this distribution shall not be processed at all.
2690
2691=item features [array] *** EXPERIMENTAL FEATURE ***
2692
2693Experimental implementation to deal with optional_features from
2694META.yml. Still needs coordination with installer software and
2695currently works only for META.yml declaring C<dynamic_config=0>. Use
2696with caution.
2697
2698=item goto [string]
2699
2700The canonical name of a delegate distribution to install
2701instead. Useful when a new version, although it tests OK itself,
2702breaks something else or a developer release or a fork is already
2703uploaded that is better than the last released version.
2704
2705=item install [hash]
2706
2707Processing instructions for the C<make install> or C<./Build install>
2708phase of the CPAN mantra. See below under I<Processing Instructions>.
2709
2710=item make [hash]
2711
2712Processing instructions for the C<make> or C<./Build> phase of the
2713CPAN mantra. See below under I<Processing Instructions>.
2714
2715=item match [hash]
2716
2717A hashref with one or more of the keys C<distribution>, C<module>,
2718C<perl>, C<perlconfig>, and C<env> that specify whether a document is
2719targeted at a specific CPAN distribution or installation.
2720Keys prefixed with C<not_> negates the corresponding match.
2721
2722The corresponding values are interpreted as regular expressions. The
2723C<distribution> related one will be matched against the canonical
2724distribution name, e.g. "AUTHOR/Foo-Bar-3.14.tar.gz".
2725
2726The C<module> related one will be matched against I<all> modules
2727contained in the distribution until one module matches.
2728
2729The C<perl> related one will be matched against C<$^X> (but with the
2730absolute path).
2731
2732The value associated with C<perlconfig> is itself a hashref that is
2733matched against corresponding values in the C<%Config::Config> hash
2734living in the C<Config.pm> module.
2735Keys prefixed with C<not_> negates the corresponding match.
2736
2737The value associated with C<env> is itself a hashref that is
2738matched against corresponding values in the C<%ENV> hash.
2739Keys prefixed with C<not_> negates the corresponding match.
2740
2741If more than one restriction of C<module>, C<distribution>, etc. is
2742specified, the results of the separately computed match values must
2743all match. If so, the hashref represented by the
2744YAML document is returned as the preference structure for the current
2745distribution.
2746
2747=item patches [array]
2748
2749An array of patches on CPAN or on the local disk to be applied in
2750order via an external patch program. If the value for the C<-p>
2751parameter is C<0> or C<1> is determined by reading the patch
2752beforehand. The path to each patch is either an absolute path on the
2753local filesystem or relative to a patch directory specified in the
2754C<patches_dir> configuration variable or in the format of a canonical
2755distro name. For examples please consult the distroprefs/ directory in
2756the CPAN.pm distribution (these examples are not installed by
2757default).
2758
2759Note: if the C<applypatch> program is installed and C<CPAN::Config>
2760knows about it B<and> a patch is written by the C<makepatch> program,
2761then C<CPAN.pm> lets C<applypatch> apply the patch. Both C<makepatch>
2762and C<applypatch> are available from CPAN in the C<JV/makepatch-*>
2763distribution.
2764
2765=item pl [hash]
2766
2767Processing instructions for the C<perl Makefile.PL> or C<perl
2768Build.PL> phase of the CPAN mantra. See below under I<Processing
2769Instructions>.
2770
2771=item test [hash]
2772
2773Processing instructions for the C<make test> or C<./Build test> phase
2774of the CPAN mantra. See below under I<Processing Instructions>.
2775
2776=back
2777
2778=head2 Processing Instructions
2779
2780=over
2781
2782=item args [array]
2783
2784Arguments to be added to the command line
2785
2786=item commandline
2787
2788A full commandline to run via C<system()>.
2789During execution, the environment variable PERL is set
2790to $^X (but with an absolute path). If C<commandline> is specified,
2791C<args> is not used.
2792
2793=item eexpect [hash]
2794
2795Extended C<expect>. This is a hash reference with four allowed keys,
2796C<mode>, C<timeout>, C<reuse>, and C<talk>.
2797
2798You must install the C<Expect> module to use C<eexpect>. CPAN.pm
2799does not install it for you.
2800
2801C<mode> may have the values C<deterministic> for the case where all
2802questions come in the order written down and C<anyorder> for the case
2803where the questions may come in any order. The default mode is
2804C<deterministic>.
2805
2806C<timeout> denotes a timeout in seconds. Floating-point timeouts are
2807OK. With C<mode=deterministic>, the timeout denotes the
2808timeout per question; with C<mode=anyorder> it denotes the
2809timeout per byte received from the stream or questions.
2810
2811C<talk> is a reference to an array that contains alternating questions
2812and answers. Questions are regular expressions and answers are literal
2813strings. The Expect module watches the stream from the
2814execution of the external program (C<perl Makefile.PL>, C<perl
2815Build.PL>, C<make>, etc.).
2816
2817For C<mode=deterministic>, the CPAN.pm injects the
2818corresponding answer as soon as the stream matches the regular expression.
2819
2820For C<mode=anyorder> CPAN.pm answers a question as soon
2821as the timeout is reached for the next byte in the input stream. In
2822this mode you can use the C<reuse> parameter to decide what will
2823happen with a question-answer pair after it has been used. In the
2824default case (reuse=0) it is removed from the array, avoiding being
2825used again accidentally. If you want to answer the
2826question C<Do you really want to do that> several times, then it must
2827be included in the array at least as often as you want this answer to
2828be given. Setting the parameter C<reuse> to 1 makes this repetition
2829unnecessary.
2830
2831=item env [hash]
2832
2833Environment variables to be set during the command
2834
2835=item expect [array]
2836
2837You must install the C<Expect> module to use C<expect>. CPAN.pm
2838does not install it for you.
2839
2840C<< expect: <array> >> is a short notation for this C<eexpect>:
2841
2842	eexpect:
2843		mode: deterministic
2844		timeout: 15
2845		talk: <array>
2846
2847=back
2848
2849=head2 Schema verification with C<Kwalify>
2850
2851If you have the C<Kwalify> module installed (which is part of the
2852Bundle::CPANxxl), then all your distroprefs files are checked for
2853syntactic correctness.
2854
2855=head2 Example Distroprefs Files
2856
2857C<CPAN.pm> comes with a collection of example YAML files. Note that these
2858are really just examples and should not be used without care because
2859they cannot fit everybody's purpose. After all, the authors of the
2860packages that ask questions had a need to ask, so you should watch
2861their questions and adjust the examples to your environment and your
2862needs. You have been warned:-)
2863
2864=head1 PROGRAMMER'S INTERFACE
2865
2866If you do not enter the shell, shell commands are
2867available both as methods (C<CPAN::Shell-E<gt>install(...)>) and as
2868functions in the calling package (C<install(...)>).  Before calling low-level
2869commands, it makes sense to initialize components of CPAN you need, e.g.:
2870
2871  CPAN::HandleConfig->load;
2872  CPAN::Shell::setup_output;
2873  CPAN::Index->reload;
2874
2875High-level commands do such initializations automatically.
2876
2877There's currently only one class that has a stable interface -
2878CPAN::Shell. All commands that are available in the CPAN shell are
2879methods of the class CPAN::Shell. The arguments on the commandline are
2880passed as arguments to the method.
2881
2882So if you take for example the shell command
2883
2884  notest install A B C
2885
2886the actually executed command is
2887
2888  CPAN::Shell->notest("install","A","B","C");
2889
2890Each of the commands that produce listings of modules (C<r>,
2891C<autobundle>, C<u>) also return a list of the IDs of all modules
2892within the list.
2893
2894=over 2
2895
2896=item expand($type,@things)
2897
2898The IDs of all objects available within a program are strings that can
2899be expanded to the corresponding real objects with the
2900C<CPAN::Shell-E<gt>expand("Module",@things)> method. Expand returns a
2901list of CPAN::Module objects according to the C<@things> arguments
2902given. In scalar context, it returns only the first element of the
2903list.
2904
2905=item expandany(@things)
2906
2907Like expand, but returns objects of the appropriate type, i.e.
2908CPAN::Bundle objects for bundles, CPAN::Module objects for modules, and
2909CPAN::Distribution objects for distributions. Note: it does not expand
2910to CPAN::Author objects.
2911
2912=item Programming Examples
2913
2914This enables the programmer to do operations that combine
2915functionalities that are available in the shell.
2916
2917    # install everything that is outdated on my disk:
2918    perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
2919
2920    # install my favorite programs if necessary:
2921    for $mod (qw(Net::FTP Digest::SHA Data::Dumper)) {
2922        CPAN::Shell->install($mod);
2923    }
2924
2925    # list all modules on my disk that have no VERSION number
2926    for $mod (CPAN::Shell->expand("Module","/./")) {
2927        next unless $mod->inst_file;
2928        # MakeMaker convention for undefined $VERSION:
2929        next unless $mod->inst_version eq "undef";
2930        print "No VERSION in ", $mod->id, "\n";
2931    }
2932
2933    # find out which distribution on CPAN contains a module:
2934    print CPAN::Shell->expand("Module","Apache::Constants")->cpan_file
2935
2936Or if you want to schedule a I<cron> job to watch CPAN, you could list
2937all modules that need updating. First a quick and dirty way:
2938
2939    perl -e 'use CPAN; CPAN::Shell->r;'
2940
2941If you don't want any output should all modules be
2942up to date, parse the output of above command for the regular
2943expression C</modules are up to date/> and decide to mail the output
2944only if it doesn't match.
2945
2946If you prefer to do it more in a programmerish style in one single
2947process, something like this may better suit you:
2948
2949  # list all modules on my disk that have newer versions on CPAN
2950  for $mod (CPAN::Shell->expand("Module","/./")) {
2951    next unless $mod->inst_file;
2952    next if $mod->uptodate;
2953    printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
2954        $mod->id, $mod->inst_version, $mod->cpan_version;
2955  }
2956
2957If that gives too much output every day, you may want to
2958watch only for three modules. You can write
2959
2960  for $mod (CPAN::Shell->expand("Module","/Apache|LWP|CGI/")) {
2961
2962as the first line instead. Or you can combine some of the above
2963tricks:
2964
2965  # watch only for a new mod_perl module
2966  $mod = CPAN::Shell->expand("Module","mod_perl");
2967  exit if $mod->uptodate;
2968  # new mod_perl arrived, let me know all update recommendations
2969  CPAN::Shell->r;
2970
2971=back
2972
2973=head2 Methods in the other Classes
2974
2975=over 4
2976
2977=item CPAN::Author::as_glimpse()
2978
2979Returns a one-line description of the author
2980
2981=item CPAN::Author::as_string()
2982
2983Returns a multi-line description of the author
2984
2985=item CPAN::Author::email()
2986
2987Returns the author's email address
2988
2989=item CPAN::Author::fullname()
2990
2991Returns the author's name
2992
2993=item CPAN::Author::name()
2994
2995An alias for fullname
2996
2997=item CPAN::Bundle::as_glimpse()
2998
2999Returns a one-line description of the bundle
3000
3001=item CPAN::Bundle::as_string()
3002
3003Returns a multi-line description of the bundle
3004
3005=item CPAN::Bundle::clean()
3006
3007Recursively runs the C<clean> method on all items contained in the bundle.
3008
3009=item CPAN::Bundle::contains()
3010
3011Returns a list of objects' IDs contained in a bundle. The associated
3012objects may be bundles, modules or distributions.
3013
3014=item CPAN::Bundle::force($method,@args)
3015
3016Forces CPAN to perform a task that it normally would have refused to
3017do. Force takes as arguments a method name to be called and any number
3018of additional arguments that should be passed to the called method.
3019The internals of the object get the needed changes so that CPAN.pm
3020does not refuse to take the action. The C<force> is passed recursively
3021to all contained objects. See also the section above on the C<force>
3022and the C<fforce> pragma.
3023
3024=item CPAN::Bundle::get()
3025
3026Recursively runs the C<get> method on all items contained in the bundle
3027
3028=item CPAN::Bundle::inst_file()
3029
3030Returns the highest installed version of the bundle in either @INC or
3031C<< $CPAN::Config->{cpan_home} >>. Note that this is different from
3032CPAN::Module::inst_file.
3033
3034=item CPAN::Bundle::inst_version()
3035
3036Like CPAN::Bundle::inst_file, but returns the $VERSION
3037
3038=item CPAN::Bundle::uptodate()
3039
3040Returns 1 if the bundle itself and all its members are up-to-date.
3041
3042=item CPAN::Bundle::install()
3043
3044Recursively runs the C<install> method on all items contained in the bundle
3045
3046=item CPAN::Bundle::make()
3047
3048Recursively runs the C<make> method on all items contained in the bundle
3049
3050=item CPAN::Bundle::readme()
3051
3052Recursively runs the C<readme> method on all items contained in the bundle
3053
3054=item CPAN::Bundle::test()
3055
3056Recursively runs the C<test> method on all items contained in the bundle
3057
3058=item CPAN::Distribution::as_glimpse()
3059
3060Returns a one-line description of the distribution
3061
3062=item CPAN::Distribution::as_string()
3063
3064Returns a multi-line description of the distribution
3065
3066=item CPAN::Distribution::author
3067
3068Returns the CPAN::Author object of the maintainer who uploaded this
3069distribution
3070
3071=item CPAN::Distribution::pretty_id()
3072
3073Returns a string of the form "AUTHORID/TARBALL", where AUTHORID is the
3074author's PAUSE ID and TARBALL is the distribution filename.
3075
3076=item CPAN::Distribution::base_id()
3077
3078Returns the distribution filename without any archive suffix.  E.g
3079"Foo-Bar-0.01"
3080
3081=item CPAN::Distribution::clean()
3082
3083Changes to the directory where the distribution has been unpacked and
3084runs C<make clean> there.
3085
3086=item CPAN::Distribution::containsmods()
3087
3088Returns a list of IDs of modules contained in a distribution file.
3089Works only for distributions listed in the 02packages.details.txt.gz
3090file. This typically means that just most recent version of a
3091distribution is covered.
3092
3093=item CPAN::Distribution::cvs_import()
3094
3095Changes to the directory where the distribution has been unpacked and
3096runs something like
3097
3098    cvs -d $cvs_root import -m $cvs_log $cvs_dir $userid v$version
3099
3100there.
3101
3102=item CPAN::Distribution::dir()
3103
3104Returns the directory into which this distribution has been unpacked.
3105
3106=item CPAN::Distribution::force($method,@args)
3107
3108Forces CPAN to perform a task that it normally would have refused to
3109do. Force takes as arguments a method name to be called and any number
3110of additional arguments that should be passed to the called method.
3111The internals of the object get the needed changes so that CPAN.pm
3112does not refuse to take the action. See also the section above on the
3113C<force> and the C<fforce> pragma.
3114
3115=item CPAN::Distribution::get()
3116
3117Downloads the distribution from CPAN and unpacks it. Does nothing if
3118the distribution has already been downloaded and unpacked within the
3119current session.
3120
3121=item CPAN::Distribution::install()
3122
3123Changes to the directory where the distribution has been unpacked and
3124runs the external command C<make install> there. If C<make> has not
3125yet been run, it will be run first. A C<make test> is issued in
3126any case and if this fails, the install is cancelled. The
3127cancellation can be avoided by letting C<force> run the C<install> for
3128you.
3129
3130This install method only has the power to install the distribution if
3131there are no dependencies in the way. To install an object along with all
3132its dependencies, use CPAN::Shell->install.
3133
3134Note that install() gives no meaningful return value. See uptodate().
3135
3136=item CPAN::Distribution::isa_perl()
3137
3138Returns 1 if this distribution file seems to be a perl distribution.
3139Normally this is derived from the file name only, but the index from
3140CPAN can contain a hint to achieve a return value of true for other
3141filenames too.
3142
3143=item CPAN::Distribution::look()
3144
3145Changes to the directory where the distribution has been unpacked and
3146opens a subshell there. Exiting the subshell returns.
3147
3148=item CPAN::Distribution::make()
3149
3150First runs the C<get> method to make sure the distribution is
3151downloaded and unpacked. Changes to the directory where the
3152distribution has been unpacked and runs the external commands C<perl
3153Makefile.PL> or C<perl Build.PL> and C<make> there.
3154
3155=item CPAN::Distribution::perldoc()
3156
3157Downloads the pod documentation of the file associated with a
3158distribution (in HTML format) and runs it through the external
3159command I<lynx> specified in C<< $CPAN::Config->{lynx} >>. If I<lynx>
3160isn't available, it converts it to plain text with the external
3161command I<html2text> and runs it through the pager specified
3162in C<< $CPAN::Config->{pager} >>.
3163
3164=item CPAN::Distribution::prefs()
3165
3166Returns the hash reference from the first matching YAML file that the
3167user has deposited in the C<prefs_dir/> directory. The first
3168succeeding match wins. The files in the C<prefs_dir/> are processed
3169alphabetically, and the canonical distro name (e.g.
3170AUTHOR/Foo-Bar-3.14.tar.gz) is matched against the regular expressions
3171stored in the $root->{match}{distribution} attribute value.
3172Additionally all module names contained in a distribution are matched
3173against the regular expressions in the $root->{match}{module} attribute
3174value. The two match values are ANDed together. Each of the two
3175attributes are optional.
3176
3177=item CPAN::Distribution::prereq_pm()
3178
3179Returns the hash reference that has been announced by a distribution
3180as the C<requires> and C<build_requires> elements. These can be
3181declared either by the C<META.yml> (if authoritative) or can be
3182deposited after the run of C<Build.PL> in the file C<./_build/prereqs>
3183or after the run of C<Makfile.PL> written as the C<PREREQ_PM> hash in
3184a comment in the produced C<Makefile>. I<Note>: this method only works
3185after an attempt has been made to C<make> the distribution. Returns
3186undef otherwise.
3187
3188=item CPAN::Distribution::readme()
3189
3190Downloads the README file associated with a distribution and runs it
3191through the pager specified in C<< $CPAN::Config->{pager} >>.
3192
3193=item CPAN::Distribution::reports()
3194
3195Downloads report data for this distribution from www.cpantesters.org
3196and displays a subset of them.
3197
3198=item CPAN::Distribution::read_yaml()
3199
3200Returns the content of the META.yml of this distro as a hashref. Note:
3201works only after an attempt has been made to C<make> the distribution.
3202Returns undef otherwise. Also returns undef if the content of META.yml
3203is not authoritative. (The rules about what exactly makes the content
3204authoritative are still in flux.)
3205
3206=item CPAN::Distribution::test()
3207
3208Changes to the directory where the distribution has been unpacked and
3209runs C<make test> there.
3210
3211=item CPAN::Distribution::uptodate()
3212
3213Returns 1 if all the modules contained in the distribution are
3214up-to-date. Relies on containsmods.
3215
3216=item CPAN::Index::force_reload()
3217
3218Forces a reload of all indices.
3219
3220=item CPAN::Index::reload()
3221
3222Reloads all indices if they have not been read for more than
3223C<< $CPAN::Config->{index_expire} >> days.
3224
3225=item CPAN::InfoObj::dump()
3226
3227CPAN::Author, CPAN::Bundle, CPAN::Module, and CPAN::Distribution
3228inherit this method. It prints the data structure associated with an
3229object. Useful for debugging. Note: the data structure is considered
3230internal and thus subject to change without notice.
3231
3232=item CPAN::Module::as_glimpse()
3233
3234Returns a one-line description of the module in four columns: The
3235first column contains the word C<Module>, the second column consists
3236of one character: an equals sign if this module is already installed
3237and up-to-date, a less-than sign if this module is installed but can be
3238upgraded, and a space if the module is not installed. The third column
3239is the name of the module and the fourth column gives maintainer or
3240distribution information.
3241
3242=item CPAN::Module::as_string()
3243
3244Returns a multi-line description of the module
3245
3246=item CPAN::Module::clean()
3247
3248Runs a clean on the distribution associated with this module.
3249
3250=item CPAN::Module::cpan_file()
3251
3252Returns the filename on CPAN that is associated with the module.
3253
3254=item CPAN::Module::cpan_version()
3255
3256Returns the latest version of this module available on CPAN.
3257
3258=item CPAN::Module::cvs_import()
3259
3260Runs a cvs_import on the distribution associated with this module.
3261
3262=item CPAN::Module::description()
3263
3264Returns a 44 character description of this module. Only available for
3265modules listed in The Module List (CPAN/modules/00modlist.long.html
3266or 00modlist.long.txt.gz)
3267
3268=item CPAN::Module::distribution()
3269
3270Returns the CPAN::Distribution object that contains the current
3271version of this module.
3272
3273=item CPAN::Module::dslip_status()
3274
3275Returns a hash reference. The keys of the hash are the letters C<D>,
3276C<S>, C<L>, C<I>, and <P>, for development status, support level,
3277language, interface and public licence respectively. The data for the
3278DSLIP status are collected by pause.perl.org when authors register
3279their namespaces. The values of the 5 hash elements are one-character
3280words whose meaning is described in the table below. There are also 5
3281hash elements C<DV>, C<SV>, C<LV>, C<IV>, and <PV> that carry a more
3282verbose value of the 5 status variables.
3283
3284Where the 'DSLIP' characters have the following meanings:
3285
3286  D - Development Stage  (Note: *NO IMPLIED TIMESCALES*):
3287    i   - Idea, listed to gain consensus or as a placeholder
3288    c   - under construction but pre-alpha (not yet released)
3289    a/b - Alpha/Beta testing
3290    R   - Released
3291    M   - Mature (no rigorous definition)
3292    S   - Standard, supplied with Perl 5
3293
3294  S - Support Level:
3295    m   - Mailing-list
3296    d   - Developer
3297    u   - Usenet newsgroup comp.lang.perl.modules
3298    n   - None known, try comp.lang.perl.modules
3299    a   - abandoned; volunteers welcome to take over maintenance
3300
3301  L - Language Used:
3302    p   - Perl-only, no compiler needed, should be platform independent
3303    c   - C and perl, a C compiler will be needed
3304    h   - Hybrid, written in perl with optional C code, no compiler needed
3305    +   - C++ and perl, a C++ compiler will be needed
3306    o   - perl and another language other than C or C++
3307
3308  I - Interface Style
3309    f   - plain Functions, no references used
3310    h   - hybrid, object and function interfaces available
3311    n   - no interface at all (huh?)
3312    r   - some use of unblessed References or ties
3313    O   - Object oriented using blessed references and/or inheritance
3314
3315  P - Public License
3316    p   - Standard-Perl: user may choose between GPL and Artistic
3317    g   - GPL: GNU General Public License
3318    l   - LGPL: "GNU Lesser General Public License" (previously known as
3319          "GNU Library General Public License")
3320    b   - BSD: The BSD License
3321    a   - Artistic license alone
3322    2   - Artistic license 2.0 or later
3323    o   - open source: approved by www.opensource.org
3324    d   - allows distribution without restrictions
3325    r   - restricted distribution
3326    n   - no license at all
3327
3328=item CPAN::Module::force($method,@args)
3329
3330Forces CPAN to perform a task it would normally refuse to
3331do. Force takes as arguments a method name to be invoked and any number
3332of additional arguments to pass that method.
3333The internals of the object get the needed changes so that CPAN.pm
3334does not refuse to take the action. See also the section above on the
3335C<force> and the C<fforce> pragma.
3336
3337=item CPAN::Module::get()
3338
3339Runs a get on the distribution associated with this module.
3340
3341=item CPAN::Module::inst_file()
3342
3343Returns the filename of the module found in @INC. The first file found
3344is reported, just as perl itself stops searching @INC once it finds a
3345module.
3346
3347=item CPAN::Module::available_file()
3348
3349Returns the filename of the module found in PERL5LIB or @INC. The
3350first file found is reported. The advantage of this method over
3351C<inst_file> is that modules that have been tested but not yet
3352installed are included because PERL5LIB keeps track of tested modules.
3353
3354=item CPAN::Module::inst_version()
3355
3356Returns the version number of the installed module in readable format.
3357
3358=item CPAN::Module::available_version()
3359
3360Returns the version number of the available module in readable format.
3361
3362=item CPAN::Module::install()
3363
3364Runs an C<install> on the distribution associated with this module.
3365
3366=item CPAN::Module::look()
3367
3368Changes to the directory where the distribution associated with this
3369module has been unpacked and opens a subshell there. Exiting the
3370subshell returns.
3371
3372=item CPAN::Module::make()
3373
3374Runs a C<make> on the distribution associated with this module.
3375
3376=item CPAN::Module::manpage_headline()
3377
3378If module is installed, peeks into the module's manpage, reads the
3379headline, and returns it. Moreover, if the module has been downloaded
3380within this session, does the equivalent on the downloaded module even
3381if it hasn't been installed yet.
3382
3383=item CPAN::Module::perldoc()
3384
3385Runs a C<perldoc> on this module.
3386
3387=item CPAN::Module::readme()
3388
3389Runs a C<readme> on the distribution associated with this module.
3390
3391=item CPAN::Module::reports()
3392
3393Calls the reports() method on the associated distribution object.
3394
3395=item CPAN::Module::test()
3396
3397Runs a C<test> on the distribution associated with this module.
3398
3399=item CPAN::Module::uptodate()
3400
3401Returns 1 if the module is installed and up-to-date.
3402
3403=item CPAN::Module::userid()
3404
3405Returns the author's ID of the module.
3406
3407=back
3408
3409=head2 Cache Manager
3410
3411Currently the cache manager only keeps track of the build directory
3412($CPAN::Config->{build_dir}). It is a simple FIFO mechanism that
3413deletes complete directories below C<build_dir> as soon as the size of
3414all directories there gets bigger than $CPAN::Config->{build_cache}
3415(in MB). The contents of this cache may be used for later
3416re-installations that you intend to do manually, but will never be
3417trusted by CPAN itself. This is due to the fact that the user might
3418use these directories for building modules on different architectures.
3419
3420There is another directory ($CPAN::Config->{keep_source_where}) where
3421the original distribution files are kept. This directory is not
3422covered by the cache manager and must be controlled by the user. If
3423you choose to have the same directory as build_dir and as
3424keep_source_where directory, then your sources will be deleted with
3425the same fifo mechanism.
3426
3427=head2 Bundles
3428
3429A bundle is just a perl module in the namespace Bundle:: that does not
3430define any functions or methods. It usually only contains documentation.
3431
3432It starts like a perl module with a package declaration and a $VERSION
3433variable. After that the pod section looks like any other pod with the
3434only difference being that I<one special pod section> exists starting with
3435(verbatim):
3436
3437    =head1 CONTENTS
3438
3439In this pod section each line obeys the format
3440
3441        Module_Name [Version_String] [- optional text]
3442
3443The only required part is the first field, the name of a module
3444(e.g. Foo::Bar, i.e. I<not> the name of the distribution file). The rest
3445of the line is optional. The comment part is delimited by a dash just
3446as in the man page header.
3447
3448The distribution of a bundle should follow the same convention as
3449other distributions.
3450
3451Bundles are treated specially in the CPAN package. If you say 'install
3452Bundle::Tkkit' (assuming such a bundle exists), CPAN will install all
3453the modules in the CONTENTS section of the pod. You can install your
3454own Bundles locally by placing a conformant Bundle file somewhere into
3455your @INC path. The autobundle() command which is available in the
3456shell interface does that for you by including all currently installed
3457modules in a snapshot bundle file.
3458
3459=head1 PREREQUISITES
3460
3461The CPAN program is trying to depend on as little as possible so the
3462user can use it in hostile environment. It works better the more goodies
3463the environment provides. For example if you try in the CPAN shell
3464
3465  install Bundle::CPAN
3466
3467or
3468
3469  install Bundle::CPANxxl
3470
3471you will find the shell more convenient than the bare shell before.
3472
3473If you have a local mirror of CPAN and can access all files with
3474"file:" URLs, then you only need a perl later than perl5.003 to run
3475this module. Otherwise Net::FTP is strongly recommended. LWP may be
3476required for non-UNIX systems, or if your nearest CPAN site is
3477associated with a URL that is not C<ftp:>.
3478
3479If you have neither Net::FTP nor LWP, there is a fallback mechanism
3480implemented for an external ftp command or for an external lynx
3481command.
3482
3483=head1 UTILITIES
3484
3485=head2 Finding packages and VERSION
3486
3487This module presumes that all packages on CPAN
3488
3489=over 2
3490
3491=item *
3492
3493declare their $VERSION variable in an easy to parse manner. This
3494prerequisite can hardly be relaxed because it consumes far too much
3495memory to load all packages into the running program just to determine
3496the $VERSION variable. Currently all programs that are dealing with
3497version use something like this
3498
3499    perl -MExtUtils::MakeMaker -le \
3500        'print MM->parse_version(shift)' filename
3501
3502If you are author of a package and wonder if your $VERSION can be
3503parsed, please try the above method.
3504
3505=item *
3506
3507come as compressed or gzipped tarfiles or as zip files and contain a
3508C<Makefile.PL> or C<Build.PL> (well, we try to handle a bit more, but
3509with little enthusiasm).
3510
3511=back
3512
3513=head2 Debugging
3514
3515Debugging this module is more than a bit complex due to interference from
3516the software producing the indices on CPAN, the mirroring process on CPAN,
3517packaging, configuration, synchronicity, and even (gasp!) due to bugs
3518within the CPAN.pm module itself.
3519
3520For debugging the code of CPAN.pm itself in interactive mode, some
3521debugging aid can be turned on for most packages within
3522CPAN.pm with one of
3523
3524=over 2
3525
3526=item o debug package...
3527
3528sets debug mode for packages.
3529
3530=item o debug -package...
3531
3532unsets debug mode for packages.
3533
3534=item o debug all
3535
3536turns debugging on for all packages.
3537
3538=item o debug number
3539
3540=back
3541
3542which sets the debugging packages directly. Note that C<o debug 0>
3543turns debugging off.
3544
3545What seems a successful strategy is the combination of C<reload
3546cpan> and the debugging switches. Add a new debug statement while
3547running in the shell and then issue a C<reload cpan> and see the new
3548debugging messages immediately without losing the current context.
3549
3550C<o debug> without an argument lists the valid package names and the
3551current set of packages in debugging mode. C<o debug> has built-in
3552completion support.
3553
3554For debugging of CPAN data there is the C<dump> command which takes
3555the same arguments as make/test/install and outputs each object's
3556Data::Dumper dump. If an argument looks like a perl variable and
3557contains one of C<$>, C<@> or C<%>, it is eval()ed and fed to
3558Data::Dumper directly.
3559
3560=head2 Floppy, Zip, Offline Mode
3561
3562CPAN.pm works nicely without network access, too. If you maintain machines
3563that are not networked at all, you should consider working with C<file:>
3564URLs. You'll have to collect your modules somewhere first. So
3565you might use CPAN.pm to put together all you need on a networked
3566machine. Then copy the $CPAN::Config->{keep_source_where} (but not
3567$CPAN::Config->{build_dir}) directory on a floppy. This floppy is kind
3568of a personal CPAN. CPAN.pm on the non-networked machines works nicely
3569with this floppy. See also below the paragraph about CD-ROM support.
3570
3571=head2 Basic Utilities for Programmers
3572
3573=over 2
3574
3575=item has_inst($module)
3576
3577Returns true if the module is installed. Used to load all modules into
3578the running CPAN.pm that are considered optional. The config variable
3579C<dontload_list> intercepts the C<has_inst()> call such
3580that an optional module is not loaded despite being available. For
3581example, the following command will prevent C<YAML.pm> from being
3582loaded:
3583
3584    cpan> o conf dontload_list push YAML
3585
3586See the source for details.
3587
3588=item use_inst($module)
3589
3590Similary to L<has_inst()> tries to load optional library but also dies if
3591library is not available
3592
3593=item has_usable($module)
3594
3595Returns true if the module is installed and in a usable state. Only
3596useful for a handful of modules that are used internally. See the
3597source for details.
3598
3599=item instance($module)
3600
3601The constructor for all the singletons used to represent modules,
3602distributions, authors, and bundles. If the object already exists, this
3603method returns the object; otherwise, it calls the constructor.
3604
3605=item frontend()
3606
3607=item frontend($new_frontend)
3608
3609Getter/setter for frontend object. Method just allows to subclass CPAN.pm.
3610
3611=back
3612
3613=head1 SECURITY
3614
3615There's no strong security layer in CPAN.pm. CPAN.pm helps you to
3616install foreign, unmasked, unsigned code on your machine. We compare
3617to a checksum that comes from the net just as the distribution file
3618itself. But we try to make it easy to add security on demand:
3619
3620=head2 Cryptographically signed modules
3621
3622Since release 1.77, CPAN.pm has been able to verify cryptographically
3623signed module distributions using Module::Signature.  The CPAN modules
3624can be signed by their authors, thus giving more security.  The simple
3625unsigned MD5 checksums that were used before by CPAN protect mainly
3626against accidental file corruption.
3627
3628You will need to have Module::Signature installed, which in turn
3629requires that you have at least one of Crypt::OpenPGP module or the
3630command-line F<gpg> tool installed.
3631
3632You will also need to be able to connect over the Internet to the public
3633key servers, like pgp.mit.edu, and their port 11731 (the HKP protocol).
3634
3635The configuration parameter check_sigs is there to turn signature
3636checking on or off.
3637
3638=head1 EXPORT
3639
3640Most functions in package CPAN are exported by default. The reason
3641for this is that the primary use is intended for the cpan shell or for
3642one-liners.
3643
3644=head1 ENVIRONMENT
3645
3646When the CPAN shell enters a subshell via the look command, it sets
3647the environment CPAN_SHELL_LEVEL to 1, or increments that variable if it is
3648already set.
3649
3650When CPAN runs, it sets the environment variable PERL5_CPAN_IS_RUNNING
3651to the ID of the running process. It also sets
3652PERL5_CPANPLUS_IS_RUNNING to prevent runaway processes which could
3653happen with older versions of Module::Install.
3654
3655When running C<perl Makefile.PL>, the environment variable
3656C<PERL5_CPAN_IS_EXECUTING> is set to the full path of the
3657C<Makefile.PL> that is being executed. This prevents runaway processes
3658with newer versions of Module::Install.
3659
3660When the config variable ftp_passive is set, all downloads will be run
3661with the environment variable FTP_PASSIVE set to this value. This is
3662in general a good idea as it influences both Net::FTP and LWP based
3663connections. The same effect can be achieved by starting the cpan
3664shell with this environment variable set. For Net::FTP alone, one can
3665also always set passive mode by running libnetcfg.
3666
3667=head1 POPULATE AN INSTALLATION WITH LOTS OF MODULES
3668
3669Populating a freshly installed perl with one's favorite modules is pretty
3670easy if you maintain a private bundle definition file. To get a useful
3671blueprint of a bundle definition file, the command autobundle can be used
3672on the CPAN shell command line. This command writes a bundle definition
3673file for all modules installed for the current perl
3674interpreter. It's recommended to run this command once only, and from then
3675on maintain the file manually under a private name, say
3676Bundle/my_bundle.pm. With a clever bundle file you can then simply say
3677
3678    cpan> install Bundle::my_bundle
3679
3680then answer a few questions and go out for coffee (possibly
3681even in a different city).
3682
3683Maintaining a bundle definition file means keeping track of two
3684things: dependencies and interactivity. CPAN.pm sometimes fails on
3685calculating dependencies because not all modules define all MakeMaker
3686attributes correctly, so a bundle definition file should specify
3687prerequisites as early as possible. On the other hand, it's
3688annoying that so many distributions need some interactive configuring. So
3689what you can try to accomplish in your private bundle file is to have the
3690packages that need to be configured early in the file and the gentle
3691ones later, so you can go out for coffee after a few minutes and leave CPAN.pm
3692to churn away unattended.
3693
3694=head1 WORKING WITH CPAN.pm BEHIND FIREWALLS
3695
3696Thanks to Graham Barr for contributing the following paragraphs about
3697the interaction between perl, and various firewall configurations. For
3698further information on firewalls, it is recommended to consult the
3699documentation that comes with the I<ncftp> program. If you are unable to
3700go through the firewall with a simple Perl setup, it is likely
3701that you can configure I<ncftp> so that it works through your firewall.
3702
3703=head2 Three basic types of firewalls
3704
3705Firewalls can be categorized into three basic types.
3706
3707=over 4
3708
3709=item http firewall
3710
3711This is when the firewall machine runs a web server, and to access the
3712outside world, you must do so via that web server. If you set environment
3713variables like http_proxy or ftp_proxy to values beginning with http://,
3714or in your web browser you've proxy information set, then you know
3715you are running behind an http firewall.
3716
3717To access servers outside these types of firewalls with perl (even for
3718ftp), you need LWP or HTTP::Tiny.
3719
3720=item ftp firewall
3721
3722This where the firewall machine runs an ftp server. This kind of
3723firewall will only let you access ftp servers outside the firewall.
3724This is usually done by connecting to the firewall with ftp, then
3725entering a username like "user@outside.host.com".
3726
3727To access servers outside these type of firewalls with perl, you
3728need Net::FTP.
3729
3730=item One-way visibility
3731
3732One-way visibility means these firewalls try to make themselves
3733invisible to users inside the firewall. An FTP data connection is
3734normally created by sending your IP address to the remote server and then
3735listening for the return connection. But the remote server will not be able to
3736connect to you because of the firewall. For these types of firewall,
3737FTP connections need to be done in a passive mode.
3738
3739There are two that I can think off.
3740
3741=over 4
3742
3743=item SOCKS
3744
3745If you are using a SOCKS firewall, you will need to compile perl and link
3746it with the SOCKS library.  This is what is normally called a 'socksified'
3747perl. With this executable you will be able to connect to servers outside
3748the firewall as if it were not there.
3749
3750=item IP Masquerade
3751
3752This is when the firewall implemented in the kernel (via NAT, or networking
3753address translation), it allows you to hide a complete network behind one
3754IP address. With this firewall no special compiling is needed as you can
3755access hosts directly.
3756
3757For accessing ftp servers behind such firewalls you usually need to
3758set the environment variable C<FTP_PASSIVE> or the config variable
3759ftp_passive to a true value.
3760
3761=back
3762
3763=back
3764
3765=head2 Configuring lynx or ncftp for going through a firewall
3766
3767If you can go through your firewall with e.g. lynx, presumably with a
3768command such as
3769
3770    /usr/local/bin/lynx -pscott:tiger
3771
3772then you would configure CPAN.pm with the command
3773
3774    o conf lynx "/usr/local/bin/lynx -pscott:tiger"
3775
3776That's all. Similarly for ncftp or ftp, you would configure something
3777like
3778
3779    o conf ncftp "/usr/bin/ncftp -f /home/scott/ncftplogin.cfg"
3780
3781Your mileage may vary...
3782
3783=head1 FAQ
3784
3785=over 4
3786
3787=item 1)
3788
3789I installed a new version of module X but CPAN keeps saying,
3790I have the old version installed
3791
3792Probably you B<do> have the old version installed. This can
3793happen if a module installs itself into a different directory in the
3794@INC path than it was previously installed. This is not really a
3795CPAN.pm problem, you would have the same problem when installing the
3796module manually. The easiest way to prevent this behaviour is to add
3797the argument C<UNINST=1> to the C<make install> call, and that is why
3798many people add this argument permanently by configuring
3799
3800  o conf make_install_arg UNINST=1
3801
3802=item 2)
3803
3804So why is UNINST=1 not the default?
3805
3806Because there are people who have their precise expectations about who
3807may install where in the @INC path and who uses which @INC array. In
3808fine tuned environments C<UNINST=1> can cause damage.
3809
3810=item 3)
3811
3812I want to clean up my mess, and install a new perl along with
3813all modules I have. How do I go about it?
3814
3815Run the autobundle command for your old perl and optionally rename the
3816resulting bundle file (e.g. Bundle/mybundle.pm), install the new perl
3817with the Configure option prefix, e.g.
3818
3819    ./Configure -Dprefix=/usr/local/perl-5.6.78.9
3820
3821Install the bundle file you produced in the first step with something like
3822
3823    cpan> install Bundle::mybundle
3824
3825and you're done.
3826
3827=item 4)
3828
3829When I install bundles or multiple modules with one command
3830there is too much output to keep track of.
3831
3832You may want to configure something like
3833
3834  o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
3835  o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"
3836
3837so that STDOUT is captured in a file for later inspection.
3838
3839
3840=item 5)
3841
3842I am not root, how can I install a module in a personal directory?
3843
3844As of CPAN 1.9463, if you do not have permission to write the default perl
3845library directories, CPAN's configuration process will ask you whether
3846you want to bootstrap <local::lib>, which makes keeping a personal
3847perl library directory easy.
3848
3849Another thing you should bear in mind is that the UNINST parameter can
3850be dangerous when you are installing into a private area because you
3851might accidentally remove modules that other people depend on that are
3852not using the private area.
3853
3854=item 6)
3855
3856How to get a package, unwrap it, and make a change before building it?
3857
3858Have a look at the C<look> (!) command.
3859
3860=item 7)
3861
3862I installed a Bundle and had a couple of fails. When I
3863retried, everything resolved nicely. Can this be fixed to work
3864on first try?
3865
3866The reason for this is that CPAN does not know the dependencies of all
3867modules when it starts out. To decide about the additional items to
3868install, it just uses data found in the META.yml file or the generated
3869Makefile. An undetected missing piece breaks the process. But it may
3870well be that your Bundle installs some prerequisite later than some
3871depending item and thus your second try is able to resolve everything.
3872Please note, CPAN.pm does not know the dependency tree in advance and
3873cannot sort the queue of things to install in a topologically correct
3874order. It resolves perfectly well B<if> all modules declare the
3875prerequisites correctly with the PREREQ_PM attribute to MakeMaker or
3876the C<requires> stanza of Module::Build. For bundles which fail and
3877you need to install often, it is recommended to sort the Bundle
3878definition file manually.
3879
3880=item 8)
3881
3882In our intranet, we have many modules for internal use. How
3883can I integrate these modules with CPAN.pm but without uploading
3884the modules to CPAN?
3885
3886Have a look at the CPAN::Site module.
3887
3888=item 9)
3889
3890When I run CPAN's shell, I get an error message about things in my
3891C</etc/inputrc> (or C<~/.inputrc>) file.
3892
3893These are readline issues and can only be fixed by studying readline
3894configuration on your architecture and adjusting the referenced file
3895accordingly. Please make a backup of the C</etc/inputrc> or C<~/.inputrc>
3896and edit them. Quite often harmless changes like uppercasing or
3897lowercasing some arguments solves the problem.
3898
3899=item 10)
3900
3901Some authors have strange characters in their names.
3902
3903Internally CPAN.pm uses the UTF-8 charset. If your terminal is
3904expecting ISO-8859-1 charset, a converter can be activated by setting
3905term_is_latin to a true value in your config file. One way of doing so
3906would be
3907
3908    cpan> o conf term_is_latin 1
3909
3910If other charset support is needed, please file a bug report against
3911CPAN.pm at rt.cpan.org and describe your needs. Maybe we can extend
3912the support or maybe UTF-8 terminals become widely available.
3913
3914Note: this config variable is deprecated and will be removed in a
3915future version of CPAN.pm. It will be replaced with the conventions
3916around the family of $LANG and $LC_* environment variables.
3917
3918=item 11)
3919
3920When an install fails for some reason and then I correct the error
3921condition and retry, CPAN.pm refuses to install the module, saying
3922C<Already tried without success>.
3923
3924Use the force pragma like so
3925
3926  force install Foo::Bar
3927
3928Or you can use
3929
3930  look Foo::Bar
3931
3932and then C<make install> directly in the subshell.
3933
3934=item 12)
3935
3936How do I install a "DEVELOPER RELEASE" of a module?
3937
3938By default, CPAN will install the latest non-developer release of a
3939module. If you want to install a dev release, you have to specify the
3940partial path starting with the author id to the tarball you wish to
3941install, like so:
3942
3943    cpan> install KWILLIAMS/Module-Build-0.27_07.tar.gz
3944
3945Note that you can use the C<ls> command to get this path listed.
3946
3947=item 13)
3948
3949How do I install a module and all its dependencies from the commandline,
3950without being prompted for anything, despite my CPAN configuration
3951(or lack thereof)?
3952
3953CPAN uses ExtUtils::MakeMaker's prompt() function to ask its questions, so
3954if you set the PERL_MM_USE_DEFAULT environment variable, you shouldn't be
3955asked any questions at all (assuming the modules you are installing are
3956nice about obeying that variable as well):
3957
3958    % PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'
3959
3960=item 14)
3961
3962How do I create a Module::Build based Build.PL derived from an
3963ExtUtils::MakeMaker focused Makefile.PL?
3964
3965http://search.cpan.org/dist/Module-Build-Convert/
3966
3967=item 15)
3968
3969I'm frequently irritated with the CPAN shell's inability to help me
3970select a good mirror.
3971
3972CPAN can now help you select a "good" mirror, based on which ones have the
3973lowest 'ping' round-trip times.  From the shell, use the command 'o conf init
3974urllist' and allow CPAN to automatically select mirrors for you.
3975
3976Beyond that help, the urllist config parameter is yours. You can add and remove
3977sites at will. You should find out which sites have the best up-to-dateness,
3978bandwidth, reliability, etc. and are topologically close to you. Some people
3979prefer fast downloads, others up-to-dateness, others reliability.  You decide
3980which to try in which order.
3981
3982Henk P. Penning maintains a site that collects data about CPAN sites:
3983
3984  http://mirrors.cpan.org/
3985
3986Also, feel free to play with experimental features. Run
3987
3988  o conf init randomize_urllist ftpstats_period ftpstats_size
3989
3990and choose your favorite parameters. After a few downloads running the
3991C<hosts> command will probably assist you in choosing the best mirror
3992sites.
3993
3994=item 16)
3995
3996Why do I get asked the same questions every time I start the shell?
3997
3998You can make your configuration changes permanent by calling the
3999command C<o conf commit>. Alternatively set the C<auto_commit>
4000variable to true by running C<o conf init auto_commit> and answering
4001the following question with yes.
4002
4003=item 17)
4004
4005Older versions of CPAN.pm had the original root directory of all
4006tarballs in the build directory. Now there are always random
4007characters appended to these directory names. Why was this done?
4008
4009The random characters are provided by File::Temp and ensure that each
4010module's individual build directory is unique. This makes running
4011CPAN.pm in concurrent processes simultaneously safe.
4012
4013=item 18)
4014
4015Speaking of the build directory. Do I have to clean it up myself?
4016
4017You have the choice to set the config variable C<scan_cache> to
4018C<never>. Then you must clean it up yourself. The other possible
4019values, C<atstart> and C<atexit> clean up the build directory when you
4020start (or more precisely, after the first extraction into the build
4021directory) or exit the CPAN shell, respectively. If you never start up
4022the CPAN shell, you probably also have to clean up the build directory
4023yourself.
4024
4025=item 19)
4026
4027How can I switch to sudo instead of local::lib?
4028
4029The following 5 environment veriables need to be reset to the previous
4030values: PATH, PERL5LIB, PERL_LOCAL_LIB_ROOT, PERL_MB_OPT, PERL_MM_OPT;
4031and these two CPAN.pm config variables must be reconfigured:
4032make_install_make_command and mbuild_install_build_command. The five
4033env variables have probably been overwritten in your $HOME/.bashrc or
4034some equivalent. You either find them there and delete their traces
4035and logout/login or you override them temporarily, depending on your
4036exact desire. The two cpanpm config variables can be set with:
4037
4038  o conf init /install_.*_command/
4039
4040probably followed by
4041
4042  o conf commit
4043
4044=back
4045
4046=head1 COMPATIBILITY
4047
4048=head2 OLD PERL VERSIONS
4049
4050CPAN.pm is regularly tested to run under 5.005 and assorted
4051newer versions. It is getting more and more difficult to get the
4052minimal prerequisites working on older perls. It is close to
4053impossible to get the whole Bundle::CPAN working there. If you're in
4054the position to have only these old versions, be advised that CPAN is
4055designed to work fine without the Bundle::CPAN installed.
4056
4057To get things going, note that GBARR/Scalar-List-Utils-1.18.tar.gz is
4058compatible with ancient perls and that File::Temp is listed as a
4059prerequisite but CPAN has reasonable workarounds if it is missing.
4060
4061=head2 CPANPLUS
4062
4063This module and its competitor, the CPANPLUS module, are both much
4064cooler than the other. CPAN.pm is older. CPANPLUS was designed to be
4065more modular, but it was never intended to be compatible with CPAN.pm.
4066
4067=head2 CPANMINUS
4068
4069In the year 2010 App::cpanminus was launched as a new approach to a
4070cpan shell with a considerably smaller footprint. Very cool stuff.
4071
4072=head1 SECURITY ADVICE
4073
4074This software enables you to upgrade software on your computer and so
4075is inherently dangerous because the newly installed software may
4076contain bugs and may alter the way your computer works or even make it
4077unusable. Please consider backing up your data before every upgrade.
4078
4079=head1 BUGS
4080
4081Please report bugs via L<http://rt.cpan.org/>
4082
4083Before submitting a bug, please make sure that the traditional method
4084of building a Perl module package from a shell by following the
4085installation instructions of that package still works in your
4086environment.
4087
4088=head1 AUTHOR
4089
4090Andreas Koenig C<< <andk@cpan.org> >>
4091
4092=head1 LICENSE
4093
4094This program is free software; you can redistribute it and/or
4095modify it under the same terms as Perl itself.
4096
4097See L<http://www.perl.com/perl/misc/Artistic.html>
4098
4099=head1 TRANSLATIONS
4100
4101Kawai,Takanori provides a Japanese translation of a very old version
4102of this manpage at
4103L<http://homepage3.nifty.com/hippo2000/perltips/CPAN.htm>
4104
4105=head1 SEE ALSO
4106
4107Many people enter the CPAN shell by running the L<cpan> utility
4108program which is installed in the same directory as perl itself. So if
4109you have this directory in your PATH variable (or some equivalent in
4110your operating system) then typing C<cpan> in a console window will
4111work for you as well. Above that the utility provides several
4112commandline shortcuts.
4113
4114melezhik (Alexey) sent me a link where he published a chef recipe to
4115work with CPAN.pm: http://community.opscode.com/cookbooks/cpan.
4116
4117
4118=cut
4119