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