PageRenderTime 52ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/linkedfs/usr/lib/perl5/5.8.6/CPAN.pm

https://bitbucket.org/harakiri/trk
Perl | 7169 lines | 6676 code | 175 blank | 318 comment | 385 complexity | 5e757b07ad3ef5e5ad6a09dae26f9563 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
  2. package CPAN;
  3. $VERSION = '1.76_01';
  4. $VERSION = eval $VERSION;
  5. # $Id: CPAN.pm,v 1.412 2003/07/31 14:53:04 k Exp $
  6. # only used during development:
  7. $Revision = "";
  8. # $Revision = "[".substr(q$Revision: 1.412 $, 10)."]";
  9. use Carp ();
  10. use Config ();
  11. use Cwd ();
  12. use DirHandle;
  13. use Exporter ();
  14. use ExtUtils::MakeMaker (); # $SelfLoader::DEBUG=1;
  15. use File::Basename ();
  16. use File::Copy ();
  17. use File::Find;
  18. use File::Path ();
  19. use FileHandle ();
  20. use Safe ();
  21. use Text::ParseWords ();
  22. use Text::Wrap;
  23. use File::Spec;
  24. use Sys::Hostname;
  25. no lib "."; # we need to run chdir all over and we would get at wrong
  26. # libraries there
  27. require Mac::BuildTools if $^O eq 'MacOS';
  28. END { $End++; &cleanup; }
  29. %CPAN::DEBUG = qw[
  30. CPAN 1
  31. Index 2
  32. InfoObj 4
  33. Author 8
  34. Distribution 16
  35. Bundle 32
  36. Module 64
  37. CacheMgr 128
  38. Complete 256
  39. FTP 512
  40. Shell 1024
  41. Eval 2048
  42. Config 4096
  43. Tarzip 8192
  44. Version 16384
  45. Queue 32768
  46. ];
  47. $CPAN::DEBUG ||= 0;
  48. $CPAN::Signal ||= 0;
  49. $CPAN::Frontend ||= "CPAN::Shell";
  50. $CPAN::Defaultsite ||= "ftp://ftp.perl.org/pub/CPAN";
  51. package CPAN;
  52. use strict qw(vars);
  53. use vars qw($VERSION @EXPORT $AUTOLOAD $DEBUG $META $HAS_USABLE $term
  54. $Revision $Signal $End $Suppress_readline $Frontend
  55. $Defaultsite $Have_warned);
  56. @CPAN::ISA = qw(CPAN::Debug Exporter);
  57. @EXPORT = qw(
  58. autobundle bundle expand force get cvs_import
  59. install make readme recompile shell test clean
  60. );
  61. #-> sub CPAN::AUTOLOAD ;
  62. sub AUTOLOAD {
  63. my($l) = $AUTOLOAD;
  64. $l =~ s/.*:://;
  65. my(%EXPORT);
  66. @EXPORT{@EXPORT} = '';
  67. CPAN::Config->load unless $CPAN::Config_loaded++;
  68. if (exists $EXPORT{$l}){
  69. CPAN::Shell->$l(@_);
  70. } else {
  71. $CPAN::Frontend->mywarn(qq{Unknown command "$AUTOLOAD". }.
  72. qq{Type ? for help.
  73. });
  74. }
  75. }
  76. #-> sub CPAN::shell ;
  77. sub shell {
  78. my($self) = @_;
  79. $Suppress_readline = ! -t STDIN unless defined $Suppress_readline;
  80. CPAN::Config->load unless $CPAN::Config_loaded++;
  81. my $oprompt = shift || "cpan> ";
  82. my $prompt = $oprompt;
  83. my $commandline = shift || "";
  84. local($^W) = 1;
  85. unless ($Suppress_readline) {
  86. require Term::ReadLine;
  87. if (! $term
  88. or
  89. $term->ReadLine eq "Term::ReadLine::Stub"
  90. ) {
  91. $term = Term::ReadLine->new('CPAN Monitor');
  92. }
  93. if ($term->ReadLine eq "Term::ReadLine::Gnu") {
  94. my $attribs = $term->Attribs;
  95. $attribs->{attempted_completion_function} = sub {
  96. &CPAN::Complete::gnu_cpl;
  97. }
  98. } else {
  99. $readline::rl_completion_function =
  100. $readline::rl_completion_function = 'CPAN::Complete::cpl';
  101. }
  102. if (my $histfile = $CPAN::Config->{'histfile'}) {{
  103. unless ($term->can("AddHistory")) {
  104. $CPAN::Frontend->mywarn("Terminal does not support AddHistory.\n");
  105. last;
  106. }
  107. my($fh) = FileHandle->new;
  108. open $fh, "<$histfile" or last;
  109. local $/ = "\n";
  110. while (<$fh>) {
  111. chomp;
  112. $term->AddHistory($_);
  113. }
  114. close $fh;
  115. }}
  116. # $term->OUT is autoflushed anyway
  117. my $odef = select STDERR;
  118. $| = 1;
  119. select STDOUT;
  120. $| = 1;
  121. select $odef;
  122. }
  123. # no strict; # I do not recall why no strict was here (2000-09-03)
  124. $META->checklock();
  125. my $cwd = CPAN::anycwd();
  126. my $try_detect_readline;
  127. $try_detect_readline = $term->ReadLine eq "Term::ReadLine::Stub" if $term;
  128. my $rl_avail = $Suppress_readline ? "suppressed" :
  129. ($term->ReadLine ne "Term::ReadLine::Stub") ? "enabled" :
  130. "available (try 'install Bundle::CPAN')";
  131. $CPAN::Frontend->myprint(
  132. sprintf qq{
  133. cpan shell -- CPAN exploration and modules installation (v%s%s)
  134. ReadLine support %s
  135. },
  136. $CPAN::VERSION,
  137. $CPAN::Revision,
  138. $rl_avail
  139. )
  140. unless $CPAN::Config->{'inhibit_startup_message'} ;
  141. my($continuation) = "";
  142. SHELLCOMMAND: while () {
  143. if ($Suppress_readline) {
  144. print $prompt;
  145. last SHELLCOMMAND unless defined ($_ = <> );
  146. chomp;
  147. } else {
  148. last SHELLCOMMAND unless
  149. defined ($_ = $term->readline($prompt, $commandline));
  150. }
  151. $_ = "$continuation$_" if $continuation;
  152. s/^\s+//;
  153. next SHELLCOMMAND if /^$/;
  154. $_ = 'h' if /^\s*\?/;
  155. if (/^(?:q(?:uit)?|bye|exit)$/i) {
  156. last SHELLCOMMAND;
  157. } elsif (s/\\$//s) {
  158. chomp;
  159. $continuation = $_;
  160. $prompt = " > ";
  161. } elsif (/^\!/) {
  162. s/^\!//;
  163. my($eval) = $_;
  164. package CPAN::Eval;
  165. use vars qw($import_done);
  166. CPAN->import(':DEFAULT') unless $import_done++;
  167. CPAN->debug("eval[$eval]") if $CPAN::DEBUG;
  168. eval($eval);
  169. warn $@ if $@;
  170. $continuation = "";
  171. $prompt = $oprompt;
  172. } elsif (/./) {
  173. my(@line);
  174. if ($] < 5.00322) { # parsewords had a bug until recently
  175. @line = split;
  176. } else {
  177. eval { @line = Text::ParseWords::shellwords($_) };
  178. warn($@), next SHELLCOMMAND if $@;
  179. warn("Text::Parsewords could not parse the line [$_]"),
  180. next SHELLCOMMAND unless @line;
  181. }
  182. $CPAN::META->debug("line[".join("|",@line)."]") if $CPAN::DEBUG;
  183. my $command = shift @line;
  184. eval { CPAN::Shell->$command(@line) };
  185. warn $@ if $@;
  186. chdir $cwd or $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd": $!});
  187. $CPAN::Frontend->myprint("\n");
  188. $continuation = "";
  189. $prompt = $oprompt;
  190. }
  191. } continue {
  192. $commandline = ""; # I do want to be able to pass a default to
  193. # shell, but on the second command I see no
  194. # use in that
  195. $Signal=0;
  196. CPAN::Queue->nullify_queue;
  197. if ($try_detect_readline) {
  198. if ($CPAN::META->has_inst("Term::ReadLine::Gnu")
  199. ||
  200. $CPAN::META->has_inst("Term::ReadLine::Perl")
  201. ) {
  202. delete $INC{"Term/ReadLine.pm"};
  203. my $redef = 0;
  204. local($SIG{__WARN__}) = CPAN::Shell::paintdots_onreload(\$redef);
  205. require Term::ReadLine;
  206. $CPAN::Frontend->myprint("\n$redef subroutines in ".
  207. "Term::ReadLine redefined\n");
  208. @_ = ($oprompt,"");
  209. goto &shell;
  210. }
  211. }
  212. }
  213. chdir $cwd or $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd": $!});
  214. }
  215. package CPAN::CacheMgr;
  216. @CPAN::CacheMgr::ISA = qw(CPAN::InfoObj CPAN);
  217. use File::Find;
  218. package CPAN::Config;
  219. use vars qw(%can $dot_cpan);
  220. %can = (
  221. 'commit' => "Commit changes to disk",
  222. 'defaults' => "Reload defaults from disk",
  223. 'init' => "Interactive setting of all options",
  224. );
  225. package CPAN::FTP;
  226. use vars qw($Ua $Thesite $Themethod);
  227. @CPAN::FTP::ISA = qw(CPAN::Debug);
  228. package CPAN::LWP::UserAgent;
  229. use vars qw(@ISA $USER $PASSWD $SETUPDONE);
  230. # we delay requiring LWP::UserAgent and setting up inheritence until we need it
  231. package CPAN::Complete;
  232. @CPAN::Complete::ISA = qw(CPAN::Debug);
  233. @CPAN::Complete::COMMANDS = sort qw(
  234. ! a b d h i m o q r u autobundle clean dump
  235. make test install force readme reload look
  236. cvs_import ls
  237. ) unless @CPAN::Complete::COMMANDS;
  238. package CPAN::Index;
  239. use vars qw($LAST_TIME $DATE_OF_02 $DATE_OF_03);
  240. @CPAN::Index::ISA = qw(CPAN::Debug);
  241. $LAST_TIME ||= 0;
  242. $DATE_OF_03 ||= 0;
  243. # use constant PROTOCOL => "2.0"; # outcommented to avoid warning on upgrade from 1.57
  244. sub PROTOCOL { 2.0 }
  245. package CPAN::InfoObj;
  246. @CPAN::InfoObj::ISA = qw(CPAN::Debug);
  247. package CPAN::Author;
  248. @CPAN::Author::ISA = qw(CPAN::InfoObj);
  249. package CPAN::Distribution;
  250. @CPAN::Distribution::ISA = qw(CPAN::InfoObj);
  251. package CPAN::Bundle;
  252. @CPAN::Bundle::ISA = qw(CPAN::Module);
  253. package CPAN::Module;
  254. @CPAN::Module::ISA = qw(CPAN::InfoObj);
  255. package CPAN::Exception::RecursiveDependency;
  256. use overload '""' => "as_string";
  257. sub new {
  258. my($class) = shift;
  259. my($deps) = shift;
  260. my @deps;
  261. my %seen;
  262. for my $dep (@$deps) {
  263. push @deps, $dep;
  264. last if $seen{$dep}++;
  265. }
  266. bless { deps => \@deps }, $class;
  267. }
  268. sub as_string {
  269. my($self) = shift;
  270. "\nRecursive dependency detected:\n " .
  271. join("\n => ", @{$self->{deps}}) .
  272. ".\nCannot continue.\n";
  273. }
  274. package CPAN::Shell;
  275. use vars qw($AUTOLOAD @ISA $COLOR_REGISTERED $ADVANCED_QUERY $PRINT_ORNAMENTING);
  276. @CPAN::Shell::ISA = qw(CPAN::Debug);
  277. $COLOR_REGISTERED ||= 0;
  278. $PRINT_ORNAMENTING ||= 0;
  279. #-> sub CPAN::Shell::AUTOLOAD ;
  280. sub AUTOLOAD {
  281. my($autoload) = $AUTOLOAD;
  282. my $class = shift(@_);
  283. # warn "autoload[$autoload] class[$class]";
  284. $autoload =~ s/.*:://;
  285. if ($autoload =~ /^w/) {
  286. if ($CPAN::META->has_inst('CPAN::WAIT')) {
  287. CPAN::WAIT->$autoload(@_);
  288. } else {
  289. $CPAN::Frontend->mywarn(qq{
  290. Commands starting with "w" require CPAN::WAIT to be installed.
  291. Please consider installing CPAN::WAIT to use the fulltext index.
  292. For this you just need to type
  293. install CPAN::WAIT
  294. });
  295. }
  296. } else {
  297. $CPAN::Frontend->mywarn(qq{Unknown command '$autoload'. }.
  298. qq{Type ? for help.
  299. });
  300. }
  301. }
  302. package CPAN::Tarzip;
  303. use vars qw($AUTOLOAD @ISA $BUGHUNTING);
  304. @CPAN::Tarzip::ISA = qw(CPAN::Debug);
  305. $BUGHUNTING = 0; # released code must have turned off
  306. package CPAN::Queue;
  307. # One use of the queue is to determine if we should or shouldn't
  308. # announce the availability of a new CPAN module
  309. # Now we try to use it for dependency tracking. For that to happen
  310. # we need to draw a dependency tree and do the leaves first. This can
  311. # easily be reached by running CPAN.pm recursively, but we don't want
  312. # to waste memory and run into deep recursion. So what we can do is
  313. # this:
  314. # CPAN::Queue is the package where the queue is maintained. Dependencies
  315. # often have high priority and must be brought to the head of the queue,
  316. # possibly by jumping the queue if they are already there. My first code
  317. # attempt tried to be extremely correct. Whenever a module needed
  318. # immediate treatment, I either unshifted it to the front of the queue,
  319. # or, if it was already in the queue, I spliced and let it bypass the
  320. # others. This became a too correct model that made it impossible to put
  321. # an item more than once into the queue. Why would you need that? Well,
  322. # you need temporary duplicates as the manager of the queue is a loop
  323. # that
  324. #
  325. # (1) looks at the first item in the queue without shifting it off
  326. #
  327. # (2) cares for the item
  328. #
  329. # (3) removes the item from the queue, *even if its agenda failed and
  330. # even if the item isn't the first in the queue anymore* (that way
  331. # protecting against never ending queues)
  332. #
  333. # So if an item has prerequisites, the installation fails now, but we
  334. # want to retry later. That's easy if we have it twice in the queue.
  335. #
  336. # I also expect insane dependency situations where an item gets more
  337. # than two lives in the queue. Simplest example is triggered by 'install
  338. # Foo Foo Foo'. People make this kind of mistakes and I don't want to
  339. # get in the way. I wanted the queue manager to be a dumb servant, not
  340. # one that knows everything.
  341. #
  342. # Who would I tell in this model that the user wants to be asked before
  343. # processing? I can't attach that information to the module object,
  344. # because not modules are installed but distributions. So I'd have to
  345. # tell the distribution object that it should ask the user before
  346. # processing. Where would the question be triggered then? Most probably
  347. # in CPAN::Distribution::rematein.
  348. # Hope that makes sense, my head is a bit off:-) -- AK
  349. use vars qw{ @All };
  350. # CPAN::Queue::new ;
  351. sub new {
  352. my($class,$s) = @_;
  353. my $self = bless { qmod => $s }, $class;
  354. push @All, $self;
  355. return $self;
  356. }
  357. # CPAN::Queue::first ;
  358. sub first {
  359. my $obj = $All[0];
  360. $obj->{qmod};
  361. }
  362. # CPAN::Queue::delete_first ;
  363. sub delete_first {
  364. my($class,$what) = @_;
  365. my $i;
  366. for my $i (0..$#All) {
  367. if ( $All[$i]->{qmod} eq $what ) {
  368. splice @All, $i, 1;
  369. return;
  370. }
  371. }
  372. }
  373. # CPAN::Queue::jumpqueue ;
  374. sub jumpqueue {
  375. my $class = shift;
  376. my @what = @_;
  377. CPAN->debug(sprintf("before jumpqueue All[%s] what[%s]",
  378. join(",",map {$_->{qmod}} @All),
  379. join(",",@what)
  380. )) if $CPAN::DEBUG;
  381. WHAT: for my $what (reverse @what) {
  382. my $jumped = 0;
  383. for (my $i=0; $i<$#All;$i++) { #prevent deep recursion
  384. CPAN->debug("i[$All[$i]]what[$what]") if $CPAN::DEBUG;
  385. if ($All[$i]->{qmod} eq $what){
  386. $jumped++;
  387. if ($jumped > 100) { # one's OK if e.g. just
  388. # processing now; more are OK if
  389. # user typed it several times
  390. $CPAN::Frontend->mywarn(
  391. qq{Object [$what] queued more than 100 times, ignoring}
  392. );
  393. next WHAT;
  394. }
  395. }
  396. }
  397. my $obj = bless { qmod => $what }, $class;
  398. unshift @All, $obj;
  399. }
  400. CPAN->debug(sprintf("after jumpqueue All[%s] what[%s]",
  401. join(",",map {$_->{qmod}} @All),
  402. join(",",@what)
  403. )) if $CPAN::DEBUG;
  404. }
  405. # CPAN::Queue::exists ;
  406. sub exists {
  407. my($self,$what) = @_;
  408. my @all = map { $_->{qmod} } @All;
  409. my $exists = grep { $_->{qmod} eq $what } @All;
  410. # warn "in exists what[$what] all[@all] exists[$exists]";
  411. $exists;
  412. }
  413. # CPAN::Queue::delete ;
  414. sub delete {
  415. my($self,$mod) = @_;
  416. @All = grep { $_->{qmod} ne $mod } @All;
  417. }
  418. # CPAN::Queue::nullify_queue ;
  419. sub nullify_queue {
  420. @All = ();
  421. }
  422. package CPAN;
  423. $META ||= CPAN->new; # In case we re-eval ourselves we need the ||
  424. # from here on only subs.
  425. ################################################################################
  426. #-> sub CPAN::all_objects ;
  427. sub all_objects {
  428. my($mgr,$class) = @_;
  429. CPAN::Config->load unless $CPAN::Config_loaded++;
  430. CPAN->debug("mgr[$mgr] class[$class]") if $CPAN::DEBUG;
  431. CPAN::Index->reload;
  432. values %{ $META->{readwrite}{$class} }; # unsafe meta access, ok
  433. }
  434. *all = \&all_objects;
  435. # Called by shell, not in batch mode. In batch mode I see no risk in
  436. # having many processes updating something as installations are
  437. # continually checked at runtime. In shell mode I suspect it is
  438. # unintentional to open more than one shell at a time
  439. #-> sub CPAN::checklock ;
  440. sub checklock {
  441. my($self) = @_;
  442. my $lockfile = File::Spec->catfile($CPAN::Config->{cpan_home},".lock");
  443. if (-f $lockfile && -M _ > 0) {
  444. my $fh = FileHandle->new($lockfile) or
  445. $CPAN::Frontend->mydie("Could not open $lockfile: $!");
  446. my $otherpid = <$fh>;
  447. my $otherhost = <$fh>;
  448. $fh->close;
  449. if (defined $otherpid && $otherpid) {
  450. chomp $otherpid;
  451. }
  452. if (defined $otherhost && $otherhost) {
  453. chomp $otherhost;
  454. }
  455. my $thishost = hostname();
  456. if (defined $otherhost && defined $thishost &&
  457. $otherhost ne '' && $thishost ne '' &&
  458. $otherhost ne $thishost) {
  459. $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile $lockfile\n".
  460. "reports other host $otherhost and other process $otherpid.\n".
  461. "Cannot proceed.\n"));
  462. }
  463. elsif (defined $otherpid && $otherpid) {
  464. return if $$ == $otherpid; # should never happen
  465. $CPAN::Frontend->mywarn(
  466. qq{
  467. There seems to be running another CPAN process (pid $otherpid). Contacting...
  468. });
  469. if (kill 0, $otherpid) {
  470. $CPAN::Frontend->mydie(qq{Other job is running.
  471. You may want to kill it and delete the lockfile, maybe. On UNIX try:
  472. kill $otherpid
  473. rm $lockfile
  474. });
  475. } elsif (-w $lockfile) {
  476. my($ans) =
  477. ExtUtils::MakeMaker::prompt
  478. (qq{Other job not responding. Shall I overwrite }.
  479. qq{the lockfile? (Y/N)},"y");
  480. $CPAN::Frontend->myexit("Ok, bye\n")
  481. unless $ans =~ /^y/i;
  482. } else {
  483. Carp::croak(
  484. qq{Lockfile $lockfile not writeable by you. }.
  485. qq{Cannot proceed.\n}.
  486. qq{ On UNIX try:\n}.
  487. qq{ rm $lockfile\n}.
  488. qq{ and then rerun us.\n}
  489. );
  490. }
  491. } else {
  492. $CPAN::Frontend->mydie(sprintf("CPAN.pm panic: Lockfile $lockfile\n".
  493. "reports other process with ID ".
  494. "$otherpid. Cannot proceed.\n"));
  495. }
  496. }
  497. my $dotcpan = $CPAN::Config->{cpan_home};
  498. eval { File::Path::mkpath($dotcpan);};
  499. if ($@) {
  500. # A special case at least for Jarkko.
  501. my $firsterror = $@;
  502. my $seconderror;
  503. my $symlinkcpan;
  504. if (-l $dotcpan) {
  505. $symlinkcpan = readlink $dotcpan;
  506. die "readlink $dotcpan failed: $!" unless defined $symlinkcpan;
  507. eval { File::Path::mkpath($symlinkcpan); };
  508. if ($@) {
  509. $seconderror = $@;
  510. } else {
  511. $CPAN::Frontend->mywarn(qq{
  512. Working directory $symlinkcpan created.
  513. });
  514. }
  515. }
  516. unless (-d $dotcpan) {
  517. my $diemess = qq{
  518. Your configuration suggests "$dotcpan" as your
  519. CPAN.pm working directory. I could not create this directory due
  520. to this error: $firsterror\n};
  521. $diemess .= qq{
  522. As "$dotcpan" is a symlink to "$symlinkcpan",
  523. I tried to create that, but I failed with this error: $seconderror
  524. } if $seconderror;
  525. $diemess .= qq{
  526. Please make sure the directory exists and is writable.
  527. };
  528. $CPAN::Frontend->mydie($diemess);
  529. }
  530. }
  531. my $fh;
  532. unless ($fh = FileHandle->new(">$lockfile")) {
  533. if ($! =~ /Permission/) {
  534. my $incc = $INC{'CPAN/Config.pm'};
  535. my $myincc = File::Spec->catfile($ENV{HOME},'.cpan','CPAN','MyConfig.pm');
  536. $CPAN::Frontend->myprint(qq{
  537. Your configuration suggests that CPAN.pm should use a working
  538. directory of
  539. $CPAN::Config->{cpan_home}
  540. Unfortunately we could not create the lock file
  541. $lockfile
  542. due to permission problems.
  543. Please make sure that the configuration variable
  544. \$CPAN::Config->{cpan_home}
  545. points to a directory where you can write a .lock file. You can set
  546. this variable in either
  547. $incc
  548. or
  549. $myincc
  550. });
  551. }
  552. $CPAN::Frontend->mydie("Could not open >$lockfile: $!");
  553. }
  554. $fh->print($$, "\n");
  555. $fh->print(hostname(), "\n");
  556. $self->{LOCK} = $lockfile;
  557. $fh->close;
  558. $SIG{TERM} = sub {
  559. &cleanup;
  560. $CPAN::Frontend->mydie("Got SIGTERM, leaving");
  561. };
  562. $SIG{INT} = sub {
  563. # no blocks!!!
  564. &cleanup if $Signal;
  565. $CPAN::Frontend->mydie("Got another SIGINT") if $Signal;
  566. print "Caught SIGINT\n";
  567. $Signal++;
  568. };
  569. # From: Larry Wall <larry@wall.org>
  570. # Subject: Re: deprecating SIGDIE
  571. # To: perl5-porters@perl.org
  572. # Date: Thu, 30 Sep 1999 14:58:40 -0700 (PDT)
  573. #
  574. # The original intent of __DIE__ was only to allow you to substitute one
  575. # kind of death for another on an application-wide basis without respect
  576. # to whether you were in an eval or not. As a global backstop, it should
  577. # not be used any more lightly (or any more heavily :-) than class
  578. # UNIVERSAL. Any attempt to build a general exception model on it should
  579. # be politely squashed. Any bug that causes every eval {} to have to be
  580. # modified should be not so politely squashed.
  581. #
  582. # Those are my current opinions. It is also my optinion that polite
  583. # arguments degenerate to personal arguments far too frequently, and that
  584. # when they do, it's because both people wanted it to, or at least didn't
  585. # sufficiently want it not to.
  586. #
  587. # Larry
  588. # global backstop to cleanup if we should really die
  589. $SIG{__DIE__} = \&cleanup;
  590. $self->debug("Signal handler set.") if $CPAN::DEBUG;
  591. }
  592. #-> sub CPAN::DESTROY ;
  593. sub DESTROY {
  594. &cleanup; # need an eval?
  595. }
  596. #-> sub CPAN::anycwd ;
  597. sub anycwd () {
  598. my $getcwd;
  599. $getcwd = $CPAN::Config->{'getcwd'} || 'cwd';
  600. CPAN->$getcwd();
  601. }
  602. #-> sub CPAN::cwd ;
  603. sub cwd {Cwd::cwd();}
  604. #-> sub CPAN::getcwd ;
  605. sub getcwd {Cwd::getcwd();}
  606. #-> sub CPAN::exists ;
  607. sub exists {
  608. my($mgr,$class,$id) = @_;
  609. CPAN::Config->load unless $CPAN::Config_loaded++;
  610. CPAN::Index->reload;
  611. ### Carp::croak "exists called without class argument" unless $class;
  612. $id ||= "";
  613. exists $META->{readonly}{$class}{$id} or
  614. exists $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
  615. }
  616. #-> sub CPAN::delete ;
  617. sub delete {
  618. my($mgr,$class,$id) = @_;
  619. delete $META->{readonly}{$class}{$id}; # unsafe meta access, ok
  620. delete $META->{readwrite}{$class}{$id}; # unsafe meta access, ok
  621. }
  622. #-> sub CPAN::has_usable
  623. # has_inst is sometimes too optimistic, we should replace it with this
  624. # has_usable whenever a case is given
  625. sub has_usable {
  626. my($self,$mod,$message) = @_;
  627. return 1 if $HAS_USABLE->{$mod};
  628. my $has_inst = $self->has_inst($mod,$message);
  629. return unless $has_inst;
  630. my $usable;
  631. $usable = {
  632. LWP => [ # we frequently had "Can't locate object
  633. # method "new" via package "LWP::UserAgent" at
  634. # (eval 69) line 2006
  635. sub {require LWP},
  636. sub {require LWP::UserAgent},
  637. sub {require HTTP::Request},
  638. sub {require URI::URL},
  639. ],
  640. Net::FTP => [
  641. sub {require Net::FTP},
  642. sub {require Net::Config},
  643. ]
  644. };
  645. if ($usable->{$mod}) {
  646. for my $c (0..$#{$usable->{$mod}}) {
  647. my $code = $usable->{$mod}[$c];
  648. my $ret = eval { &$code() };
  649. if ($@) {
  650. warn "DEBUG: c[$c]\$\@[$@]ret[$ret]";
  651. return;
  652. }
  653. }
  654. }
  655. return $HAS_USABLE->{$mod} = 1;
  656. }
  657. #-> sub CPAN::has_inst
  658. sub has_inst {
  659. my($self,$mod,$message) = @_;
  660. Carp::croak("CPAN->has_inst() called without an argument")
  661. unless defined $mod;
  662. if (defined $message && $message eq "no"
  663. ||
  664. exists $CPAN::META->{dontload_hash}{$mod} # unsafe meta access, ok
  665. ||
  666. exists $CPAN::Config->{dontload_hash}{$mod}
  667. ) {
  668. $CPAN::META->{dontload_hash}{$mod}||=1; # unsafe meta access, ok
  669. return 0;
  670. }
  671. my $file = $mod;
  672. my $obj;
  673. $file =~ s|::|/|g;
  674. $file =~ s|/|\\|g if $^O eq 'MSWin32';
  675. $file .= ".pm";
  676. if ($INC{$file}) {
  677. # checking %INC is wrong, because $INC{LWP} may be true
  678. # although $INC{"URI/URL.pm"} may have failed. But as
  679. # I really want to say "bla loaded OK", I have to somehow
  680. # cache results.
  681. ### warn "$file in %INC"; #debug
  682. return 1;
  683. } elsif (eval { require $file }) {
  684. # eval is good: if we haven't yet read the database it's
  685. # perfect and if we have installed the module in the meantime,
  686. # it tries again. The second require is only a NOOP returning
  687. # 1 if we had success, otherwise it's retrying
  688. $CPAN::Frontend->myprint("CPAN: $mod loaded ok\n");
  689. if ($mod eq "CPAN::WAIT") {
  690. push @CPAN::Shell::ISA, CPAN::WAIT;
  691. }
  692. return 1;
  693. } elsif ($mod eq "Net::FTP") {
  694. $CPAN::Frontend->mywarn(qq{
  695. Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
  696. if you just type
  697. install Bundle::libnet
  698. }) unless $Have_warned->{"Net::FTP"}++;
  699. sleep 3;
  700. } elsif ($mod eq "Digest::MD5"){
  701. $CPAN::Frontend->myprint(qq{
  702. CPAN: MD5 security checks disabled because Digest::MD5 not installed.
  703. Please consider installing the Digest::MD5 module.
  704. });
  705. sleep 2;
  706. } else {
  707. delete $INC{$file}; # if it inc'd LWP but failed during, say, URI
  708. }
  709. return 0;
  710. }
  711. #-> sub CPAN::instance ;
  712. sub instance {
  713. my($mgr,$class,$id) = @_;
  714. CPAN::Index->reload;
  715. $id ||= "";
  716. # unsafe meta access, ok?
  717. return $META->{readwrite}{$class}{$id} if exists $META->{readwrite}{$class}{$id};
  718. $META->{readwrite}{$class}{$id} ||= $class->new(ID => $id);
  719. }
  720. #-> sub CPAN::new ;
  721. sub new {
  722. bless {}, shift;
  723. }
  724. #-> sub CPAN::cleanup ;
  725. sub cleanup {
  726. # warn "cleanup called with arg[@_] End[$End] Signal[$Signal]";
  727. local $SIG{__DIE__} = '';
  728. my($message) = @_;
  729. my $i = 0;
  730. my $ineval = 0;
  731. my($subroutine);
  732. while ((undef,undef,undef,$subroutine) = caller(++$i)) {
  733. $ineval = 1, last if
  734. $subroutine eq '(eval)';
  735. }
  736. return if $ineval && !$End;
  737. return unless defined $META->{LOCK};
  738. return unless -f $META->{LOCK};
  739. $META->savehist;
  740. unlink $META->{LOCK};
  741. # require Carp;
  742. # Carp::cluck("DEBUGGING");
  743. $CPAN::Frontend->mywarn("Lockfile removed.\n");
  744. }
  745. #-> sub CPAN::savehist
  746. sub savehist {
  747. my($self) = @_;
  748. my($histfile,$histsize);
  749. unless ($histfile = $CPAN::Config->{'histfile'}){
  750. $CPAN::Frontend->mywarn("No history written (no histfile specified).\n");
  751. return;
  752. }
  753. $histsize = $CPAN::Config->{'histsize'} || 100;
  754. if ($CPAN::term){
  755. unless ($CPAN::term->can("GetHistory")) {
  756. $CPAN::Frontend->mywarn("Terminal does not support GetHistory.\n");
  757. return;
  758. }
  759. } else {
  760. return;
  761. }
  762. my @h = $CPAN::term->GetHistory;
  763. splice @h, 0, @h-$histsize if @h>$histsize;
  764. my($fh) = FileHandle->new;
  765. open $fh, ">$histfile" or $CPAN::Frontend->mydie("Couldn't open >$histfile: $!");
  766. local $\ = local $, = "\n";
  767. print $fh @h;
  768. close $fh;
  769. }
  770. sub is_tested {
  771. my($self,$what) = @_;
  772. $self->{is_tested}{$what} = 1;
  773. }
  774. sub is_installed {
  775. my($self,$what) = @_;
  776. delete $self->{is_tested}{$what};
  777. }
  778. sub set_perl5lib {
  779. my($self) = @_;
  780. $self->{is_tested} ||= {};
  781. return unless %{$self->{is_tested}};
  782. my $env = $ENV{PERL5LIB};
  783. $env = $ENV{PERLLIB} unless defined $env;
  784. my @env;
  785. push @env, $env if defined $env and length $env;
  786. my @dirs = map {("$_/blib/arch", "$_/blib/lib")} keys %{$self->{is_tested}};
  787. $CPAN::Frontend->myprint("Prepending @dirs to PERL5LIB.\n");
  788. $ENV{PERL5LIB} = join $Config::Config{path_sep}, @dirs, @env;
  789. }
  790. package CPAN::CacheMgr;
  791. #-> sub CPAN::CacheMgr::as_string ;
  792. sub as_string {
  793. eval { require Data::Dumper };
  794. if ($@) {
  795. return shift->SUPER::as_string;
  796. } else {
  797. return Data::Dumper::Dumper(shift);
  798. }
  799. }
  800. #-> sub CPAN::CacheMgr::cachesize ;
  801. sub cachesize {
  802. shift->{DU};
  803. }
  804. #-> sub CPAN::CacheMgr::tidyup ;
  805. sub tidyup {
  806. my($self) = @_;
  807. return unless -d $self->{ID};
  808. while ($self->{DU} > $self->{'MAX'} ) {
  809. my($toremove) = shift @{$self->{FIFO}};
  810. $CPAN::Frontend->myprint(sprintf(
  811. "Deleting from cache".
  812. ": $toremove (%.1f>%.1f MB)\n",
  813. $self->{DU}, $self->{'MAX'})
  814. );
  815. return if $CPAN::Signal;
  816. $self->force_clean_cache($toremove);
  817. return if $CPAN::Signal;
  818. }
  819. }
  820. #-> sub CPAN::CacheMgr::dir ;
  821. sub dir {
  822. shift->{ID};
  823. }
  824. #-> sub CPAN::CacheMgr::entries ;
  825. sub entries {
  826. my($self,$dir) = @_;
  827. return unless defined $dir;
  828. $self->debug("reading dir[$dir]") if $CPAN::DEBUG;
  829. $dir ||= $self->{ID};
  830. my($cwd) = CPAN::anycwd();
  831. chdir $dir or Carp::croak("Can't chdir to $dir: $!");
  832. my $dh = DirHandle->new(File::Spec->curdir)
  833. or Carp::croak("Couldn't opendir $dir: $!");
  834. my(@entries);
  835. for ($dh->read) {
  836. next if $_ eq "." || $_ eq "..";
  837. if (-f $_) {
  838. push @entries, File::Spec->catfile($dir,$_);
  839. } elsif (-d _) {
  840. push @entries, File::Spec->catdir($dir,$_);
  841. } else {
  842. $CPAN::Frontend->mywarn("Warning: weird direntry in $dir: $_\n");
  843. }
  844. }
  845. chdir $cwd or Carp::croak("Can't chdir to $cwd: $!");
  846. sort { -M $b <=> -M $a} @entries;
  847. }
  848. #-> sub CPAN::CacheMgr::disk_usage ;
  849. sub disk_usage {
  850. my($self,$dir) = @_;
  851. return if exists $self->{SIZE}{$dir};
  852. return if $CPAN::Signal;
  853. my($Du) = 0;
  854. find(
  855. sub {
  856. $File::Find::prune++ if $CPAN::Signal;
  857. return if -l $_;
  858. if ($^O eq 'MacOS') {
  859. require Mac::Files;
  860. my $cat = Mac::Files::FSpGetCatInfo($_);
  861. $Du += $cat->ioFlLgLen() + $cat->ioFlRLgLen() if $cat;
  862. } else {
  863. $Du += (-s _);
  864. }
  865. },
  866. $dir
  867. );
  868. return if $CPAN::Signal;
  869. $self->{SIZE}{$dir} = $Du/1024/1024;
  870. push @{$self->{FIFO}}, $dir;
  871. $self->debug("measured $dir is $Du") if $CPAN::DEBUG;
  872. $self->{DU} += $Du/1024/1024;
  873. $self->{DU};
  874. }
  875. #-> sub CPAN::CacheMgr::force_clean_cache ;
  876. sub force_clean_cache {
  877. my($self,$dir) = @_;
  878. return unless -e $dir;
  879. $self->debug("have to rmtree $dir, will free $self->{SIZE}{$dir}")
  880. if $CPAN::DEBUG;
  881. File::Path::rmtree($dir);
  882. $self->{DU} -= $self->{SIZE}{$dir};
  883. delete $self->{SIZE}{$dir};
  884. }
  885. #-> sub CPAN::CacheMgr::new ;
  886. sub new {
  887. my $class = shift;
  888. my $time = time;
  889. my($debug,$t2);
  890. $debug = "";
  891. my $self = {
  892. ID => $CPAN::Config->{'build_dir'},
  893. MAX => $CPAN::Config->{'build_cache'},
  894. SCAN => $CPAN::Config->{'scan_cache'} || 'atstart',
  895. DU => 0
  896. };
  897. File::Path::mkpath($self->{ID});
  898. my $dh = DirHandle->new($self->{ID});
  899. bless $self, $class;
  900. $self->scan_cache;
  901. $t2 = time;
  902. $debug .= "timing of CacheMgr->new: ".($t2 - $time);
  903. $time = $t2;
  904. CPAN->debug($debug) if $CPAN::DEBUG;
  905. $self;
  906. }
  907. #-> sub CPAN::CacheMgr::scan_cache ;
  908. sub scan_cache {
  909. my $self = shift;
  910. return if $self->{SCAN} eq 'never';
  911. $CPAN::Frontend->mydie("Unknown scan_cache argument: $self->{SCAN}")
  912. unless $self->{SCAN} eq 'atstart';
  913. $CPAN::Frontend->myprint(
  914. sprintf("Scanning cache %s for sizes\n",
  915. $self->{ID}));
  916. my $e;
  917. for $e ($self->entries($self->{ID})) {
  918. next if $e eq ".." || $e eq ".";
  919. $self->disk_usage($e);
  920. return if $CPAN::Signal;
  921. }
  922. $self->tidyup;
  923. }
  924. package CPAN::Debug;
  925. #-> sub CPAN::Debug::debug ;
  926. sub debug {
  927. my($self,$arg) = @_;
  928. my($caller,$func,$line,@rest) = caller(1); # caller(0) eg
  929. # Complete, caller(1)
  930. # eg readline
  931. ($caller) = caller(0);
  932. $caller =~ s/.*:://;
  933. $arg = "" unless defined $arg;
  934. my $rest = join "|", map { defined $_ ? $_ : "UNDEF" } @rest;
  935. if ($CPAN::DEBUG{$caller} & $CPAN::DEBUG){
  936. if ($arg and ref $arg) {
  937. eval { require Data::Dumper };
  938. if ($@) {
  939. $CPAN::Frontend->myprint($arg->as_string);
  940. } else {
  941. $CPAN::Frontend->myprint(Data::Dumper::Dumper($arg));
  942. }
  943. } else {
  944. $CPAN::Frontend->myprint("Debug($caller:$func,$line,[$rest]): $arg\n");
  945. }
  946. }
  947. }
  948. package CPAN::Config;
  949. #-> sub CPAN::Config::edit ;
  950. # returns true on successful action
  951. sub edit {
  952. my($self,@args) = @_;
  953. return unless @args;
  954. CPAN->debug("self[$self]args[".join(" | ",@args)."]");
  955. my($o,$str,$func,$args,$key_exists);
  956. $o = shift @args;
  957. if($can{$o}) {
  958. $self->$o(@args);
  959. return 1;
  960. } else {
  961. CPAN->debug("o[$o]") if $CPAN::DEBUG;
  962. if ($o =~ /list$/) {
  963. $func = shift @args;
  964. $func ||= "";
  965. CPAN->debug("func[$func]") if $CPAN::DEBUG;
  966. my $changed;
  967. # Let's avoid eval, it's easier to comprehend without.
  968. if ($func eq "push") {
  969. push @{$CPAN::Config->{$o}}, @args;
  970. $changed = 1;
  971. } elsif ($func eq "pop") {
  972. pop @{$CPAN::Config->{$o}};
  973. $changed = 1;
  974. } elsif ($func eq "shift") {
  975. shift @{$CPAN::Config->{$o}};
  976. $changed = 1;
  977. } elsif ($func eq "unshift") {
  978. unshift @{$CPAN::Config->{$o}}, @args;
  979. $changed = 1;
  980. } elsif ($func eq "splice") {
  981. splice @{$CPAN::Config->{$o}}, @args;
  982. $changed = 1;
  983. } elsif (@args) {
  984. $CPAN::Config->{$o} = [@args];
  985. $changed = 1;
  986. } else {
  987. $self->prettyprint($o);
  988. }
  989. if ($o eq "urllist" && $changed) {
  990. # reset the cached values
  991. undef $CPAN::FTP::Thesite;
  992. undef $CPAN::FTP::Themethod;
  993. }
  994. return $changed;
  995. } else {
  996. $CPAN::Config->{$o} = $args[0] if defined $args[0];
  997. $self->prettyprint($o);
  998. }
  999. }
  1000. }
  1001. sub prettyprint {
  1002. my($self,$k) = @_;
  1003. my $v = $CPAN::Config->{$k};
  1004. if (ref $v) {
  1005. my(@report) = ref $v eq "ARRAY" ?
  1006. @$v :
  1007. map { sprintf(" %-18s => %s\n",
  1008. $_,
  1009. defined $v->{$_} ? $v->{$_} : "UNDEFINED"
  1010. )} keys %$v;
  1011. $CPAN::Frontend->myprint(
  1012. join(
  1013. "",
  1014. sprintf(
  1015. " %-18s\n",
  1016. $k
  1017. ),
  1018. map {"\t$_\n"} @report
  1019. )
  1020. );
  1021. } elsif (defined $v) {
  1022. $CPAN::Frontend->myprint(sprintf " %-18s %s\n", $k, $v);
  1023. } else {
  1024. $CPAN::Frontend->myprint(sprintf " %-18s %s\n", $k, "UNDEFINED");
  1025. }
  1026. }
  1027. #-> sub CPAN::Config::commit ;
  1028. sub commit {
  1029. my($self,$configpm) = @_;
  1030. unless (defined $configpm){
  1031. $configpm ||= $INC{"CPAN/MyConfig.pm"};
  1032. $configpm ||= $INC{"CPAN/Config.pm"};
  1033. $configpm || Carp::confess(q{
  1034. CPAN::Config::commit called without an argument.
  1035. Please specify a filename where to save the configuration or try
  1036. "o conf init" to have an interactive course through configing.
  1037. });
  1038. }
  1039. my($mode);
  1040. if (-f $configpm) {
  1041. $mode = (stat $configpm)[2];
  1042. if ($mode && ! -w _) {
  1043. Carp::confess("$configpm is not writable");
  1044. }
  1045. }
  1046. my $msg;
  1047. $msg = <<EOF unless $configpm =~ /MyConfig/;
  1048. # This is CPAN.pm's systemwide configuration file. This file provides
  1049. # defaults for users, and the values can be changed in a per-user
  1050. # configuration file. The user-config file is being looked for as
  1051. # ~/.cpan/CPAN/MyConfig.pm.
  1052. EOF
  1053. $msg ||= "\n";
  1054. my($fh) = FileHandle->new;
  1055. rename $configpm, "$configpm~" if -f $configpm;
  1056. open $fh, ">$configpm" or
  1057. $CPAN::Frontend->mydie("Couldn't open >$configpm: $!");
  1058. $fh->print(qq[$msg\$CPAN::Config = \{\n]);
  1059. foreach (sort keys %$CPAN::Config) {
  1060. $fh->print(
  1061. " '$_' => ",
  1062. ExtUtils::MakeMaker::neatvalue($CPAN::Config->{$_}),
  1063. ",\n"
  1064. );
  1065. }
  1066. $fh->print("};\n1;\n__END__\n");
  1067. close $fh;
  1068. #$mode = 0444 | ( $mode & 0111 ? 0111 : 0 );
  1069. #chmod $mode, $configpm;
  1070. ###why was that so? $self->defaults;
  1071. $CPAN::Frontend->myprint("commit: wrote $configpm\n");
  1072. 1;
  1073. }
  1074. *default = \&defaults;
  1075. #-> sub CPAN::Config::defaults ;
  1076. sub defaults {
  1077. my($self) = @_;
  1078. $self->unload;
  1079. $self->load;
  1080. 1;
  1081. }
  1082. sub init {
  1083. my($self) = @_;
  1084. undef $CPAN::Config->{'inhibit_startup_message'}; # lazy trick to
  1085. # have the least
  1086. # important
  1087. # variable
  1088. # undefined
  1089. $self->load;
  1090. 1;
  1091. }
  1092. # This is a piece of repeated code that is abstracted here for
  1093. # maintainability. RMB
  1094. #
  1095. sub _configpmtest {
  1096. my($configpmdir, $configpmtest) = @_;
  1097. if (-w $configpmtest) {
  1098. return $configpmtest;
  1099. } elsif (-w $configpmdir) {
  1100. #_#_# following code dumped core on me with 5.003_11, a.k.
  1101. my $configpm_bak = "$configpmtest.bak";
  1102. unlink $configpm_bak if -f $configpm_bak;
  1103. if( -f $configpmtest ) {
  1104. if( rename $configpmtest, $configpm_bak ) {
  1105. $CPAN::Frontend->mywarn(<<END)
  1106. Old configuration file $configpmtest
  1107. moved to $configpm_bak
  1108. END
  1109. }
  1110. }
  1111. my $fh = FileHandle->new;
  1112. if ($fh->open(">$configpmtest")) {
  1113. $fh->print("1;\n");
  1114. return $configpmtest;
  1115. } else {
  1116. # Should never happen
  1117. Carp::confess("Cannot open >$configpmtest");
  1118. }
  1119. } else { return }
  1120. }
  1121. #-> sub CPAN::Config::load ;
  1122. sub load {
  1123. my($self) = shift;
  1124. my(@miss);
  1125. use Carp;
  1126. eval {require CPAN::Config;}; # We eval because of some
  1127. # MakeMaker problems
  1128. unless ($dot_cpan++){
  1129. unshift @INC, File::Spec->catdir($ENV{HOME},".cpan");
  1130. eval {require CPAN::MyConfig;}; # where you can override
  1131. # system wide settings
  1132. shift @INC;
  1133. }
  1134. return unless @miss = $self->missing_config_data;
  1135. require CPAN::FirstTime;
  1136. my($configpm,$fh,$redo,$theycalled);
  1137. $redo ||= "";
  1138. $theycalled++ if @miss==1 && $miss[0] eq 'inhibit_startup_message';
  1139. if (defined $INC{"CPAN/Config.pm"} && -w $INC{"CPAN/Config.pm"}) {
  1140. $configpm = $INC{"CPAN/Config.pm"};
  1141. $redo++;
  1142. } elsif (defined $INC{"CPAN/MyConfig.pm"} && -w $INC{"CPAN/MyConfig.pm"}) {
  1143. $configpm = $INC{"CPAN/MyConfig.pm"};
  1144. $redo++;
  1145. } else {
  1146. my($path_to_cpan) = File::Basename::dirname($INC{"CPAN.pm"});
  1147. my($configpmdir) = File::Spec->catdir($path_to_cpan,"CPAN");
  1148. my($configpmtest) = File::Spec->catfile($configpmdir,"Config.pm");
  1149. if (-d $configpmdir or File::Path::mkpath($configpmdir)) {
  1150. $configpm = _configpmtest($configpmdir,$configpmtest);
  1151. }
  1152. unless ($configpm) {
  1153. $configpmdir = File::Spec->catdir($ENV{HOME},".cpan","CPAN");
  1154. File::Path::mkpath($configpmdir);
  1155. $configpmtest = File::Spec->catfile($configpmdir,"MyConfig.pm");
  1156. $configpm = _configpmtest($configpmdir,$configpmtest);
  1157. unless ($configpm) {
  1158. Carp::confess(qq{WARNING: CPAN.pm is unable to }.
  1159. qq{create a configuration file.});
  1160. }
  1161. }
  1162. }
  1163. local($") = ", ";
  1164. $CPAN::Frontend->myprint(<<END) if $redo && ! $theycalled;
  1165. We have to reconfigure CPAN.pm due to following uninitialized parameters:
  1166. @miss
  1167. END
  1168. $CPAN::Frontend->myprint(qq{
  1169. $configpm initialized.
  1170. });
  1171. sleep 2;
  1172. CPAN::FirstTime::init($configpm);
  1173. }
  1174. #-> sub CPAN::Config::missing_config_data ;
  1175. sub missing_config_data {
  1176. my(@miss);
  1177. for (
  1178. "cpan_home", "keep_source_where", "build_dir", "build_cache",
  1179. "scan_cache", "index_expire", "gzip", "tar", "unzip", "make",
  1180. "pager",
  1181. "makepl_arg", "make_arg", "make_install_arg", "urllist",
  1182. "inhibit_startup_message", "ftp_proxy", "http_proxy", "no_proxy",
  1183. "prerequisites_policy",
  1184. "cache_metadata",
  1185. ) {
  1186. push @miss, $_ unless defined $CPAN::Config->{$_};
  1187. }
  1188. return @miss;
  1189. }
  1190. #-> sub CPAN::Config::unload ;
  1191. sub unload {
  1192. delete $INC{'CPAN/MyConfig.pm'};
  1193. delete $INC{'CPAN/Config.pm'};
  1194. }
  1195. #-> sub CPAN::Config::help ;
  1196. sub help {
  1197. $CPAN::Frontend->myprint(q[
  1198. Known options:
  1199. defaults reload default config values from disk
  1200. commit commit session changes to disk
  1201. init go through a dialog to set all parameters
  1202. You may edit key values in the follow fashion (the "o" is a literal
  1203. letter o):
  1204. o conf build_cache 15
  1205. o conf build_dir "/foo/bar"
  1206. o conf urllist shift
  1207. o conf urllist unshift ftp://ftp.foo.bar/
  1208. ]);
  1209. undef; #don't reprint CPAN::Config
  1210. }
  1211. #-> sub CPAN::Config::cpl ;
  1212. sub cpl {
  1213. my($word,$line,$pos) = @_;
  1214. $word ||= "";
  1215. CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
  1216. my(@words) = split " ", substr($line,0,$pos+1);
  1217. if (
  1218. defined($words[2])
  1219. and
  1220. (
  1221. $words[2] =~ /list$/ && @words == 3
  1222. ||
  1223. $words[2] =~ /list$/ && @words == 4 && length($word)
  1224. )
  1225. ) {
  1226. return grep /^\Q$word\E/, qw(splice shift unshift pop push);
  1227. } elsif (@words >= 4) {
  1228. return ();
  1229. }
  1230. my(@o_conf) = (keys %CPAN::Config::can, keys %$CPAN::Config);
  1231. return grep /^\Q$word\E/, @o_conf;
  1232. }
  1233. package CPAN::Shell;
  1234. #-> sub CPAN::Shell::h ;
  1235. sub h {
  1236. my($class,$about) = @_;
  1237. if (defined $about) {
  1238. $CPAN::Frontend->myprint("Detailed help not yet implemented\n");
  1239. } else {
  1240. $CPAN::Frontend->myprint(q{
  1241. Display Information
  1242. command argument description
  1243. a,b,d,m WORD or /REGEXP/ about authors, bundles, distributions, modules
  1244. i WORD or /REGEXP/ about anything of above
  1245. r NONE reinstall recommendations
  1246. ls AUTHOR about files in the author's directory
  1247. Download, Test, Make, Install...
  1248. get download
  1249. make make (implies get)
  1250. test MODULES, make test (implies make)
  1251. install DISTS, BUNDLES make install (implies test)
  1252. clean make clean
  1253. look open subshell in these dists' directories
  1254. readme display these dists' README files
  1255. Other
  1256. h,? display this menu ! perl-code eval a perl command
  1257. o conf [opt] set and query options q quit the cpan shell
  1258. reload cpan load CPAN.pm again reload index load newer indices
  1259. autobundle Snapshot force cmd unconditionally do cmd});
  1260. }
  1261. }
  1262. *help = \&h;
  1263. #-> sub CPAN::Shell::a ;
  1264. sub a {
  1265. my($self,@arg) = @_;
  1266. # authors are always UPPERCASE
  1267. for (@arg) {
  1268. $_ = uc $_ unless /=/;
  1269. }
  1270. $CPAN::Frontend->myprint($self->format_result('Author',@arg));
  1271. }
  1272. #-> sub CPAN::Shell::ls ;
  1273. sub ls {
  1274. my($self,@arg) = @_;
  1275. my @accept;
  1276. for (@arg) {
  1277. unless (/^[A-Z\-]+$/i) {
  1278. $CPAN::Frontend->mywarn("ls command rejects argument $_: not an author\n");
  1279. next;
  1280. }
  1281. push @accept, uc $_;
  1282. }
  1283. for my $a (@accept){
  1284. my $author = $self->expand('Author',$a) or die "No author found for $a";
  1285. $author->ls;
  1286. }
  1287. }
  1288. #-> sub CPAN::Shell::local_bundles ;
  1289. sub local_bundles {
  1290. my($self,@which) = @_;
  1291. my($incdir,$bdir,$dh);
  1292. foreach $incdir ($CPAN::Config->{'cpan_home'},@INC) {
  1293. my @bbase = "Bundle";
  1294. while (my $bbase = shift @bbase) {
  1295. $bdir = File::Spec->catdir($incdir,split /::/, $bbase);
  1296. CPAN->debug("bdir[$bdir]\@bbase[@bbase]") if $CPAN::DEBUG;
  1297. if ($dh = DirHandle->new($bdir)) { # may fail
  1298. my($entry);
  1299. for $entry ($dh->read) {
  1300. next if $entry =~ /^\./;
  1301. if (-d File::Spec->catdir($bdir,$entry)){
  1302. push @bbase, "$bbase\::$entry";
  1303. } else {
  1304. next unless $entry =~ s/\.pm(?!\n)\Z//;
  1305. $CPAN::META->instance('CPAN::Bundle',"$bbase\::$entry");
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. #-> sub CPAN::Shell::b ;
  1313. sub b {
  1314. my($self,@which) = @_;
  1315. CPAN->debug("which[@which]") if $CPAN::DEBUG;
  1316. $self->local_bundles;
  1317. $CPAN::Frontend->myprint($self->format_result('Bundle',@which));
  1318. }
  1319. #-> sub CPAN::Shell::d ;
  1320. sub d { $CPAN::Frontend->myprint(shift->format_result('Distribution',@_));}
  1321. #-> sub CPAN::Shell::m ;
  1322. sub m { # emacs confused here }; sub mimimimimi { # emacs in sync here
  1323. my $self = shift;
  1324. $CPAN::Frontend->myprint($self->format_result('Module',@_));
  1325. }
  1326. #-> sub CPAN::Shell::i ;
  1327. sub i {
  1328. my($self) = shift;
  1329. my(@args) = @_;
  1330. my(@type,$type,@m);
  1331. @type = qw/Author Bundle Distribution Module/;
  1332. @args = '/./' unless @args;
  1333. my(@result);
  1334. for $type (@type) {
  1335. push @result, $self->expand($type,@args);
  1336. }
  1337. my $result = @result == 1 ?
  1338. $result[0]->as_string :
  1339. @result == 0 ?
  1340. "No objects found of any type for argument @args\n" :
  1341. join("",
  1342. (map {$_->as_glimpse} @result),
  1343. scalar @result, " items found\n",
  1344. );
  1345. $CPAN::Frontend->myprint($result);
  1346. }
  1347. #-> sub CPAN::Shell::o ;
  1348. # CPAN::Shell::o and CPAN::Config::edit are closely related. 'o conf'
  1349. # should have been called set and 'o debug' maybe 'set debug'
  1350. sub o {
  1351. my($self,$o_type,@o_what) = @_;
  1352. $o_type ||= "";
  1353. CPAN->debug("o_type[$o_type] o_what[".join(" | ",@o_what)."]\n");
  1354. if ($o_type eq 'conf') {
  1355. shift @o_what if @o_what && $o_what[0] eq 'help';
  1356. if (!@o_what) { # print all things, "o conf"
  1357. my($k,$v);
  1358. $CPAN::Frontend->myprint("CPAN::Config options");
  1359. if (exists $INC{'CPAN/Config.pm'}) {
  1360. $CPAN::Frontend->myprint(" from $INC{'CPAN/Config.pm'}");
  1361. }
  1362. if (exists $INC{'CPAN/MyConfig.pm'}) {
  1363. $CPAN::Frontend->myprint(" and $INC{'CPAN/MyConfig.pm'}");
  1364. }
  1365. $CPAN::Frontend->myprint(":\n");
  1366. for $k (sort keys %CPAN::Config::can) {
  1367. $v = $CPAN::Config::can{$k};
  1368. $CPAN::Frontend->myprint(sprintf " %-18s %s\n", $k, $v);
  1369. }
  1370. $CPAN::Frontend->myprint("\n");
  1371. for $k (sort keys %$CPAN::Config) {
  1372. CPAN::Config->prettyprint($k);
  1373. }
  1374. $CPAN::Frontend->myprint("\n");
  1375. } elsif (!CPAN::Config->edit(@o_what)) {
  1376. $CPAN::Frontend->myprint(qq{Type 'o conf' to view configuration }.
  1377. qq{edit options\n\n});
  1378. }
  1379. } elsif ($o_type eq 'debug') {
  1380. my(%valid);
  1381. @o_what = () if defined $o_what[0] && $o_what[0] =~ /help/i;
  1382. if (@o_what) {
  1383. while (@o_what) {
  1384. my($what) = shift @o_what;
  1385. if ($what =~ s/^-// && exists $CPAN::DEBUG{$what}) {
  1386. $CPAN::DEBUG &= $CPAN::DEBUG ^ $CPAN::DEBUG{$what};
  1387. next;
  1388. }
  1389. if ( exists $CPAN::DEBUG{$what} ) {
  1390. $CPAN::DEBUG |= $CPAN::DEBUG{$what};
  1391. } elsif ($what =~ /^\d/) {
  1392. $CPAN::DEBUG = $what;
  1393. } elsif (lc $what eq 'all') {
  1394. my($max) = 0;
  1395. for (values %CPAN::DEBUG) {
  1396. $max += $_;
  1397. }
  1398. $CPAN::DEBUG = $max;
  1399. } else {
  1400. my($known) = 0;
  1401. for (keys %CPAN::DEBUG) {
  1402. next unless lc($_) eq lc($what);
  1403. $CPAN::DEBUG |= $CPAN::DEBUG{$_};
  1404. $known = 1;
  1405. }
  1406. $CPAN::Frontend->myprint("unknown argument [$what]\n")
  1407. unless $known;
  1408. }
  1409. }
  1410. } else {
  1411. my $raw = "Valid options for debug are ".
  1412. join(", ",sort(keys %CPAN::DEBUG), 'all').
  1413. qq{ or a number. Completion works on the options. }.
  1414. qq{Case is ignored.};
  1415. require Text::Wrap;
  1416. $CPAN::Frontend->myprint(Text::Wrap::fill("","",$raw));
  1417. $CPAN::Frontend->myprint("\n\n");
  1418. }
  1419. if ($CPAN::DEBUG) {
  1420. $CPAN::Frontend->myprint("Options set for debugging:\n");
  1421. my($k,$v);
  1422. for $k (sort {$CPAN::DEBUG{$a} <=> $CPAN::DEBUG{$b}} keys %CPAN::DEBUG) {
  1423. $v = $CPAN::DEBUG{$k};
  1424. $CPAN::Frontend->myprint(sprintf " %-14s(%s)\n", $k, $v)
  1425. if $v & $CPAN::DEBUG;
  1426. }
  1427. } else {
  1428. $CPAN::Frontend->myprint("Debugging turned off completely.\n");
  1429. }
  1430. } else {
  1431. $CPAN::Frontend->myprint(qq{
  1432. Known options:
  1433. conf set or get configuration variables
  1434. debug set or get debugging options
  1435. });
  1436. }
  1437. }
  1438. sub paintdots_onreload {
  1439. my($ref) = shift;
  1440. sub {
  1441. if ( $_[0] =~ /[Ss]ubroutine ([\w:]+) redefined/ ) {
  1442. my($subr) = $1;
  1443. ++$$ref;
  1444. local($|) = 1;
  1445. # $CPAN::Frontend->myprint(".($subr)");
  1446. $CPAN::Frontend->myprint(".");
  1447. return;
  1448. }
  1449. warn @_;
  1450. };
  1451. }
  1452. #-> sub CPAN::Shell::reload ;
  1453. sub reload {
  1454. my($self,$command,@arg) = @_;
  1455. $command ||= "";
  1456. $self->debug("self[$self]command[$command]arg[@arg]") if $CPAN::DEBUG;
  1457. if ($command =~ /cpan/i) {
  1458. for my $f (qw(CPAN.pm CPAN/FirstTime.pm)) {
  1459. next unless $INC{$f};
  1460. CPAN->debug("reloading the whole $f") if $CPAN::DEBUG;
  1461. my $fh = FileHandle->new($INC{$f});
  1462. local($/);
  1463. my $redef = 0;
  1464. local($SIG{__WARN__}) = paintdots_onreload(\$redef);
  1465. eval <$fh>;
  1466. warn $@ if $@;
  1467. $CPAN::Frontend->myprint("\n$redef subroutines redefined\n");
  1468. }
  1469. } elsif ($command =~ /index/) {
  1470. CPAN::Index->force_reload;
  1471. } else {
  1472. $CPAN::Frontend->myprint(qq{cpan re-evals the CPAN.pm file
  1473. index re-reads the index files\n});
  1474. }
  1475. }
  1476. #-> sub CPAN::Shell::_binary_extensions ;
  1477. sub _binary_extensions {
  1478. my($self) = shift @_;
  1479. my(@result,$module,%seen,%need,$headerdone);
  1480. for $module ($self->expand('Module','/./')) {
  1481. my $file = $module->cpan_file;
  1482. next if $file eq "N/A";
  1483. next if $file =~ /^Contact Author/;
  1484. my $dist = $CPAN::META->instance('CPAN::Distribution',$file);
  1485. next if $dist->isa_perl;
  1486. next unless $module->xs_file;
  1487. local($|) = 1;
  1488. $CPAN::Frontend->myprint(".");
  1489. push @result, $module;
  1490. }
  1491. # print join " | ", @result;
  1492. $CPAN::Frontend->myprint("\n");
  1493. return @result;
  1494. }
  1495. #-> sub CPAN::Shell::recompile ;
  1496. sub recompile {
  1497. my($self) = shift @_;
  1498. my($module,@module,$cpan_file,%dist);
  1499. @module = $self->_binary_extensions();
  1500. for $module (@module){ # we force now and compile later, so we
  1501. # don't do it twice
  1502. $cpan_file = $module->cpan_file;
  1503. my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
  1504. $pack->force;
  1505. $dist{$cpan_file}++;
  1506. }
  1507. for $cpan_file (sort keys %dist) {
  1508. $CPAN::Frontend->myprint(" CPAN: Recompiling $cpan_file\n\n");
  1509. my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
  1510. $pack->install;
  1511. $CPAN::Signal = 0; # it's tempting to reset Signal, so we can
  1512. # stop a package from recompiling,
  1513. # e.g. IO-1.12 when we have perl5.003_10
  1514. }
  1515. }
  1516. #-> sub CPAN::Shell::_u_r_common ;
  1517. sub _u_r_common {
  1518. my($self) = shift @_;
  1519. my($what) = shift @_;
  1520. CPAN->debug("self[$self] what[$what] args[@_]") if $CPAN::DEBUG;
  1521. Carp::croak "Usage: \$obj->_u_r_common(a|r|u)" unless
  1522. $what && $what =~ /^[aru]$/;
  1523. my(@args) = @_;
  1524. @args = '/./' unless @args;
  1525. my(@result,$module,%seen,%need,$headerdone,
  1526. $version_undefs,$version_zeroes);
  1527. $version_undefs = $version_zeroes = 0;
  1528. my $sprintf = "%s%-25s%s %9s %9s %s\n";
  1529. my @expand = $self->expand('Module',@args);
  1530. my $expand = scalar @expand;
  1531. if (0) { # Looks like noise to me, was very useful for debugging
  1532. # for metadata cache
  1533. $CPAN::Frontend->myprint(sprintf "%d matches in the database\n", $expand);
  1534. }
  1535. for $module (@expand) {
  1536. my $file = $module->cpan_file;
  1537. next unless defined $file; # ??
  1538. my($latest) = $module->cpan_version;
  1539. my($inst_file) = $module->inst_file;
  1540. my($have);
  1541. return if $CPAN::Signal;
  1542. if ($inst_file){
  1543. if ($what eq "a") {
  1544. $have = $module->inst_version;
  1545. } elsif ($what eq "r") {
  1546. $have = $module->inst_version;
  1547. local($^W) = 0;
  1548. if ($have eq "undef"){
  1549. $version_undefs++;
  1550. } elsif ($have == 0){
  1551. $version_zeroes++;
  1552. }
  1553. next unless CPAN::Version->vgt($latest, $have);
  1554. # to be pedantic we should probably say:
  1555. # && !($have eq "undef" && $latest ne "undef" && $latest gt "");
  1556. # to catch the case where CPAN has a version 0 and we have a version undef
  1557. } elsif ($what eq "u") {
  1558. next;
  1559. }
  1560. } else {
  1561. if ($what eq "a") {
  1562. next;
  1563. } elsif ($what eq "r") {
  1564. next;
  1565. } elsif ($what eq "u") {
  1566. $have = "-";
  1567. }
  1568. }
  1569. return if $CPAN::Signal; # this is sometimes lengthy
  1570. $seen{$file} ||= 0;
  1571. if ($what eq "a") {
  1572. push @result, sprintf "%s %s\n", $module->id, $have;
  1573. } elsif ($what eq "r") {
  1574. push @result, $module->id;
  1575. next if $seen{$file}++;
  1576. } elsif ($what eq "u") {
  1577. push @result, $module->id;
  1578. next if $seen{$file}++;
  1579. next if $file =~ /^Contact/;
  1580. }
  1581. unless ($headerdone++){
  1582. $CPAN::Frontend->myprint("\n");
  1583. $CPAN::Frontend->myprint(sprintf(
  1584. $sprintf,
  1585. "",
  1586. "Package namespace",
  1587. "",
  1588. "installed",
  1589. "latest",
  1590. "in CPAN file"
  1591. ));
  1592. }
  1593. my $color_on = "";
  1594. my $color_off = "";
  1595. if (
  1596. $COLOR_REGISTERED
  1597. &&
  1598. $CPAN::META->has_inst("Term::ANSIColor")
  1599. &&
  1600. $module->{RO}{description}
  1601. ) {
  1602. $color_on = Term::ANSIColor::color("green");
  1603. $color_off = Term::ANSIColor::color("reset");
  1604. }
  1605. $CPAN::Frontend->myprint(sprintf $sprintf,
  1606. $color_on,
  1607. $module->id,
  1608. $color_off,
  1609. $have,
  1610. $latest,
  1611. $file);
  1612. $need{$module->id}++;
  1613. }
  1614. unless (%need) {
  1615. if ($what eq "u") {
  1616. $CPAN::Frontend->myprint("No modules found for @args\n");
  1617. } elsif ($what eq "r") {
  1618. $CPAN::Frontend->myprint("All modules are up to date for @args\n");
  1619. }
  1620. }
  1621. if ($what eq "r") {
  1622. if ($version_zeroes) {
  1623. my $s_has = $version_zeroes > 1 ? "s have" : " has";
  1624. $CPAN::Frontend->myprint(qq{$version_zeroes installed module$s_has }.
  1625. qq{a version number of 0\n});
  1626. }
  1627. if ($version_undefs) {
  1628. my $s_has = $version_undefs > 1 ? "s have" : " has";
  1629. $CPAN::Frontend->myprint(qq{$version_undefs installed module$s_has no }.
  1630. qq{parseable version number\n});
  1631. }
  1632. }
  1633. @result;
  1634. }
  1635. #-> sub CPAN::Shell::r ;
  1636. sub r {
  1637. shift->_u_r_common("r",@_);
  1638. }
  1639. #-> sub CPAN::Shell::u ;
  1640. sub u {
  1641. shift->_u_r_common("u",@_);
  1642. }
  1643. #-> sub CPAN::Shell::autobundle ;
  1644. sub autobundle {
  1645. my($self) = shift;
  1646. CPAN::Config->load unless $CPAN::Config_loaded++;
  1647. my(@bundle) = $self->_u_r_common("a",@_);
  1648. my($todir) = File::Spec->catdir($CPAN::Config->{'cpan_home'},"Bundle");
  1649. File::Path::mkpath($todir);
  1650. unless (-d $todir) {
  1651. $CPAN::Frontend->myprint("Couldn't mkdir $todir for some reason\n");
  1652. return;
  1653. }
  1654. my($y,$m,$d) = (localtime)[5,4,3];
  1655. $y+=1900;
  1656. $m++;
  1657. my($c) = 0;
  1658. my($me) = sprintf "Snapshot_%04d_%02d_%02d_%02d", $y, $m, $d, $c;
  1659. my($to) = File::Spec->catfile($todir,"$me.pm");
  1660. while (-f $to) {
  1661. $me = sprintf "Snapshot_%04d_%02d_%02d_%02d", $y, $m, $d, ++$c;
  1662. $to = File::Spec->catfile($todir,"$me.pm");
  1663. }
  1664. my($fh) = FileHandle->new(">$to") or Carp::croak "Can't open >$to: $!";
  1665. $fh->print(
  1666. "package Bundle::$me;\n\n",
  1667. "\$VERSION = '0.01';\n\n",
  1668. "1;\n\n",
  1669. "__END__\n\n",
  1670. "=head1 NAME\n\n",
  1671. "Bundle::$me - Snapshot of installation on ",
  1672. $Config::Config{'myhostname'},
  1673. " on ",
  1674. scalar(localtime),
  1675. "\n\n=head1 SYNOPSIS\n\n",
  1676. "perl -MCPAN -e 'install Bundle::$me'\n\n",
  1677. "=head1 CONTENTS\n\n",
  1678. join("\n", @bundle),
  1679. "\n\n=head1 CONFIGURATION\n\n",
  1680. Config->myconfig,
  1681. "\n\n=head1 AUTHOR\n\n",
  1682. "This Bundle has been generated automatically ",
  1683. "by the autobundle routine in CPAN.pm.\n",
  1684. );
  1685. $fh->close;
  1686. $CPAN::Frontend->myprint("\nWrote bundle file
  1687. $to\n\n");
  1688. }
  1689. #-> sub CPAN::Shell::expandany ;
  1690. sub expandany {
  1691. my($self,$s) = @_;
  1692. CPAN->debug("s[$s]") if $CPAN::DEBUG;
  1693. if ($s =~ m|/|) { # looks like a file
  1694. $s = CPAN::Distribution->normalize($s);
  1695. return $CPAN::META->instance('CPAN::Distribution',$s);
  1696. # Distributions spring into existence, not expand
  1697. } elsif ($s =~ m|^Bundle::|) {
  1698. $self->local_bundles; # scanning so late for bundles seems
  1699. # both attractive and crumpy: always
  1700. # current state but easy to forget
  1701. # somewhere
  1702. return $self->expand('Bundle',$s);
  1703. } else {
  1704. return $self->expand('Module',$s)
  1705. if $CPAN::META->exists('CPAN::Module',$s);
  1706. }
  1707. return;
  1708. }
  1709. #-> sub CPAN::Shell::expand ;
  1710. sub expand {
  1711. shift;
  1712. my($type,@args) = @_;
  1713. my($arg,@m);
  1714. CPAN->debug("type[$type]args[@args]") if $CPAN::DEBUG;
  1715. for $arg (@args) {
  1716. my($regex,$command);
  1717. if ($arg =~ m|^/(.*)/$|) {
  1718. $regex = $1;
  1719. } elsif ($arg =~ m/=/) {
  1720. $command = 1;
  1721. }
  1722. my $class = "CPAN::$type";
  1723. my $obj;
  1724. CPAN->debug(sprintf "class[%s]regex[%s]command[%s]",
  1725. $class,
  1726. defined $regex ? $regex : "UNDEFINED",
  1727. $command || "UNDEFINED",
  1728. ) if $CPAN::DEBUG;
  1729. if (defined $regex) {
  1730. for $obj (
  1731. sort
  1732. {$a->id cmp $b->id}
  1733. $CPAN::META->all_objects($class)
  1734. ) {
  1735. unless ($obj->id){
  1736. # BUG, we got an empty object somewhere
  1737. require Data::Dumper;
  1738. CPAN->debug(sprintf(
  1739. "Bug in CPAN: Empty id on obj[%s][%s]",
  1740. $obj,
  1741. Data::Dumper::Dumper($obj)
  1742. )) if $CPAN::DEBUG;
  1743. next;
  1744. }
  1745. push @m, $obj
  1746. if $obj->id =~ /$regex/i
  1747. or
  1748. (
  1749. (
  1750. $] < 5.00303 ### provide sort of
  1751. ### compatibility with 5.003
  1752. ||
  1753. $obj->can('name')
  1754. )
  1755. &&
  1756. $obj->name =~ /$regex/i
  1757. );
  1758. }
  1759. } elsif ($command) {
  1760. die "equal sign in command disabled (immature interface), ".
  1761. "you can set
  1762. ! \$CPAN::Shell::ADVANCED_QUERY=1
  1763. to enable it. But please note, this is HIGHLY EXPERIMENTAL code
  1764. that may go away anytime.\n"
  1765. unless $ADVANCED_QUERY;
  1766. my($method,$criterion) = $arg =~ /(.+?)=(.+)/;
  1767. my($matchcrit) = $criterion =~ m/^~(.+)/;
  1768. for my $self (
  1769. sort
  1770. {$a->id cmp $b->id}
  1771. $CPAN::META->all_objects($class)
  1772. ) {
  1773. my $lhs = $self->$method() or next; # () for 5.00503
  1774. if ($matchcrit) {
  1775. push @m, $self if $lhs =~ m/$matchcrit/;
  1776. } else {
  1777. push @m, $self if $lhs eq $criterion;
  1778. }
  1779. }
  1780. } else {
  1781. my($xarg) = $arg;
  1782. if ( $type eq 'Bundle' ) {
  1783. $xarg =~ s/^(Bundle::)?(.*)/Bundle::$2/;
  1784. } elsif ($type eq "Distribution") {
  1785. $xarg = CPAN::Distribution->normalize($arg);
  1786. }
  1787. if ($CPAN::META->exists($class,$xarg)) {
  1788. $obj = $CPAN::META->instance($class,$xarg);
  1789. } elsif ($CPAN::META->exists($class,$arg)) {
  1790. $obj = $CPAN::META->instance($class,$arg);
  1791. } else {
  1792. next;
  1793. }
  1794. push @m, $obj;
  1795. }
  1796. }
  1797. return wantarray ? @m : $m[0];
  1798. }
  1799. #-> sub CPAN::Shell::format_result ;
  1800. sub format_result {
  1801. my($self) = shift;
  1802. my($type,@args) = @_;
  1803. @args = '/./' unless @args;
  1804. my(@result) = $self->expand($type,@args);
  1805. my $result = @result == 1 ?
  1806. $result[0]->as_string :
  1807. @result == 0 ?
  1808. "No objects of type $type found for argument @args\n" :
  1809. join("",
  1810. (map {$_->as_glimpse} @result),
  1811. scalar @result, " items found\n",
  1812. );
  1813. $result;
  1814. }
  1815. # The only reason for this method is currently to have a reliable
  1816. # debugging utility that reveals which output is going through which
  1817. # channel. No, I don't like the colors ;-)
  1818. #-> sub CPAN::Shell::print_ornameted ;
  1819. sub print_ornamented {
  1820. my($self,$what,$ornament) = @_;
  1821. my $longest = 0;
  1822. return unless defined $what;
  1823. if ($CPAN::Config->{term_is_latin}){
  1824. # courtesy jhi:
  1825. $what
  1826. =~ s{([\xC0-\xDF])([\x80-\xBF])}{chr(ord($1)<<6&0xC0|ord($2)&0x3F)}eg; #};
  1827. }
  1828. if ($PRINT_ORNAMENTING) {
  1829. unless (defined &color) {
  1830. if ($CPAN::META->has_inst("Term::ANSIColor")) {
  1831. import Term::ANSIColor "color";
  1832. } else {
  1833. *color = sub { return "" };
  1834. }
  1835. }
  1836. my $line;
  1837. for $line (split /\n/, $what) {
  1838. $longest = length($line) if length($line) > $longest;
  1839. }
  1840. my $sprintf = "%-" . $longest . "s";
  1841. while ($what){
  1842. $what =~ s/(.*\n?)//m;
  1843. my $line = $1;
  1844. last unless $line;
  1845. my($nl) = chomp $line ? "\n" : "";
  1846. # print "line[$line]ornament[$ornament]sprintf[$sprintf]\n";
  1847. print color($ornament), sprintf($sprintf,$line), color("reset"), $nl;
  1848. }
  1849. } else {
  1850. # chomp $what;
  1851. # $what .= "\n"; # newlines unless $PRINT_ORNAMENTING
  1852. print $what;
  1853. }
  1854. }
  1855. sub myprint {
  1856. my($self,$what) = @_;
  1857. $self->print_ornamented($what, 'bold blue on_yellow');
  1858. }
  1859. sub myexit {
  1860. my($self,$what) = @_;
  1861. $self->myprint($what);
  1862. exit;
  1863. }
  1864. sub mywarn {
  1865. my($self,$what) = @_;
  1866. $self->print_ornamented($what, 'bold red on_yellow');
  1867. }
  1868. sub myconfess {
  1869. my($self,$what) = @_;
  1870. $self->print_ornamented($what, 'bold red on_white');
  1871. Carp::confess "died";
  1872. }
  1873. sub mydie {
  1874. my($self,$what) = @_;
  1875. $self->print_ornamented($what, 'bold red on_white');
  1876. die "\n";
  1877. }
  1878. sub setup_output {
  1879. return if -t STDOUT;
  1880. my $odef = select STDERR;
  1881. $| = 1;
  1882. select STDOUT;
  1883. $| = 1;
  1884. select $odef;
  1885. }
  1886. #-> sub CPAN::Shell::rematein ;
  1887. # RE-adme||MA-ke||TE-st||IN-stall
  1888. sub rematein {
  1889. shift;
  1890. my($meth,@some) = @_;
  1891. my $pragma = "";
  1892. if ($meth eq 'force') {
  1893. $pragma = $meth;
  1894. $meth = shift @some;
  1895. }
  1896. setup_output();
  1897. CPAN->debug("pragma[$pragma]meth[$meth] some[@some]") if $CPAN::DEBUG;
  1898. # Here is the place to set "test_count" on all involved parties to
  1899. # 0. We then can pass this counter on to the involved
  1900. # distributions and those can refuse to test if test_count > X. In
  1901. # the first stab at it we could use a 1 for "X".
  1902. # But when do I reset the distributions to start with 0 again?
  1903. # Jost suggested to have a random or cycling interaction ID that
  1904. # we pass through. But the ID is something that is just left lying
  1905. # around in addition to the counter, so I'd prefer to set the
  1906. # counter to 0 now, and repeat at the end of the loop. But what
  1907. # about dependencies? They appear later and are not reset, they
  1908. # enter the queue but not its copy. How do they get a sensible
  1909. # test_count?
  1910. # construct the queue
  1911. my($s,@s,@qcopy);
  1912. foreach $s (@some) {
  1913. my $obj;
  1914. if (ref $s) {
  1915. CPAN->debug("s is an object[$s]") if $CPAN::DEBUG;
  1916. $obj = $s;
  1917. } elsif ($s =~ m|^/|) { # looks like a regexp
  1918. $CPAN::Frontend->mywarn("Sorry, $meth with a regular expression is ".
  1919. "not supported\n");
  1920. sleep 2;
  1921. next;
  1922. } else {
  1923. CPAN->debug("calling expandany [$s]") if $CPAN::DEBUG;
  1924. $obj = CPAN::Shell->expandany($s);
  1925. }
  1926. if (ref $obj) {
  1927. $obj->color_cmd_tmps(0,1);
  1928. CPAN::Queue->new($obj->id);
  1929. push @qcopy, $obj;
  1930. } elsif ($CPAN::META->exists('CPAN::Author',$s)) {
  1931. $obj = $CPAN::META->instance('CPAN::Author',$s);
  1932. if ($meth =~ /^(dump|ls)$/) {
  1933. $obj->$meth();
  1934. } else {
  1935. $CPAN::Frontend->myprint(
  1936. join "",
  1937. "Don't be silly, you can't $meth ",
  1938. $obj->fullname,
  1939. " ;-)\n"
  1940. );
  1941. sleep 2;
  1942. }
  1943. } else {
  1944. $CPAN::Frontend
  1945. ->myprint(qq{Warning: Cannot $meth $s, }.
  1946. qq{don\'t know what it is.
  1947. Try the command
  1948. i /$s/
  1949. to find objects with matching identifiers.
  1950. });
  1951. sleep 2;
  1952. }
  1953. }
  1954. # queuerunner (please be warned: when I started to change the
  1955. # queue to hold objects instead of names, I made one or two
  1956. # mistakes and never found which. I reverted back instead)
  1957. while ($s = CPAN::Queue->first) {
  1958. my $obj;
  1959. if (ref $s) {
  1960. $obj = $s; # I do not believe, we would survive if this happened
  1961. } else {
  1962. $obj = CPAN::Shell->expandany($s);
  1963. }
  1964. if ($pragma
  1965. &&
  1966. ($] < 5.00303 || $obj->can($pragma))){
  1967. ### compatibility with 5.003
  1968. $obj->$pragma($meth); # the pragma "force" in
  1969. # "CPAN::Distribution" must know
  1970. # what we are intending
  1971. }
  1972. if ($]>=5.00303 && $obj->can('called_for')) {
  1973. $obj->called_for($s);
  1974. }
  1975. CPAN->debug(
  1976. qq{pragma[$pragma]meth[$meth]obj[$obj]as_string\[}.
  1977. $obj->as_string.
  1978. qq{\]}
  1979. ) if $CPAN::DEBUG;
  1980. if ($obj->$meth()){
  1981. CPAN::Queue->delete($s);
  1982. } else {
  1983. CPAN->debug("failed");
  1984. }
  1985. $obj->undelay;
  1986. CPAN::Queue->delete_first($s);
  1987. }
  1988. for my $obj (@qcopy) {
  1989. $obj->color_cmd_tmps(0,0);
  1990. }
  1991. }
  1992. #-> sub CPAN::Shell::dump ;
  1993. sub dump { shift->rematein('dump',@_); }
  1994. #-> sub CPAN::Shell::force ;
  1995. sub force { shift->rematein('force',@_); }
  1996. #-> sub CPAN::Shell::get ;
  1997. sub get { shift->rematein('get',@_); }
  1998. #-> sub CPAN::Shell::readme ;
  1999. sub readme { shift->rematein('readme',@_); }
  2000. #-> sub CPAN::Shell::make ;
  2001. sub make { shift->rematein('make',@_); }
  2002. #-> sub CPAN::Shell::test ;
  2003. sub test { shift->rematein('test',@_); }
  2004. #-> sub CPAN::Shell::install ;
  2005. sub install { shift->rematein('install',@_); }
  2006. #-> sub CPAN::Shell::clean ;
  2007. sub clean { shift->rematein('clean',@_); }
  2008. #-> sub CPAN::Shell::look ;
  2009. sub look { shift->rematein('look',@_); }
  2010. #-> sub CPAN::Shell::cvs_import ;
  2011. sub cvs_import { shift->rematein('cvs_import',@_); }
  2012. package CPAN::LWP::UserAgent;
  2013. sub config {
  2014. return if $SETUPDONE;
  2015. if ($CPAN::META->has_usable('LWP::UserAgent')) {
  2016. require LWP::UserAgent;
  2017. @ISA = qw(Exporter LWP::UserAgent);
  2018. $SETUPDONE++;
  2019. } else {
  2020. $CPAN::Frontend->mywarn("LWP::UserAgent not available\n");
  2021. }
  2022. }
  2023. sub get_basic_credentials {
  2024. my($self, $realm, $uri, $proxy) = @_;
  2025. return unless $proxy;
  2026. if ($USER && $PASSWD) {
  2027. } elsif (defined $CPAN::Config->{proxy_user} &&
  2028. defined $CPAN::Config->{proxy_pass}) {
  2029. $USER = $CPAN::Config->{proxy_user};
  2030. $PASSWD = $CPAN::Config->{proxy_pass};
  2031. } else {
  2032. require ExtUtils::MakeMaker;
  2033. ExtUtils::MakeMaker->import(qw(prompt));
  2034. $USER = prompt("Proxy authentication needed!
  2035. (Note: to permanently configure username and password run
  2036. o conf proxy_user your_username
  2037. o conf proxy_pass your_password
  2038. )\nUsername:");
  2039. if ($CPAN::META->has_inst("Term::ReadKey")) {
  2040. Term::ReadKey::ReadMode("noecho");
  2041. } else {
  2042. $CPAN::Frontend->mywarn("Warning: Term::ReadKey seems not to be available, your password will be echoed to the terminal!\n");
  2043. }
  2044. $PASSWD = prompt("Password:");
  2045. if ($CPAN::META->has_inst("Term::ReadKey")) {
  2046. Term::ReadKey::ReadMode("restore");
  2047. }
  2048. $CPAN::Frontend->myprint("\n\n");
  2049. }
  2050. return($USER,$PASSWD);
  2051. }
  2052. # mirror(): Its purpose is to deal with proxy authentication. When we
  2053. # call SUPER::mirror, we relly call the mirror method in
  2054. # LWP::UserAgent. LWP::UserAgent will then call
  2055. # $self->get_basic_credentials or some equivalent and this will be
  2056. # $self->dispatched to our own get_basic_credentials method.
  2057. # Our own get_basic_credentials sets $USER and $PASSWD, two globals.
  2058. # 407 stands for HTTP_PROXY_AUTHENTICATION_REQUIRED. Which means
  2059. # although we have gone through our get_basic_credentials, the proxy
  2060. # server refuses to connect. This could be a case where the username or
  2061. # password has changed in the meantime, so I'm trying once again without
  2062. # $USER and $PASSWD to give the get_basic_credentials routine another
  2063. # chance to set $USER and $PASSWD.
  2064. sub mirror {
  2065. my($self,$url,$aslocal) = @_;
  2066. my $result = $self->SUPER::mirror($url,$aslocal);
  2067. if ($result->code == 407) {
  2068. undef $USER;
  2069. undef $PASSWD;
  2070. $result = $self->SUPER::mirror($url,$aslocal);
  2071. }
  2072. $result;
  2073. }
  2074. package CPAN::FTP;
  2075. #-> sub CPAN::FTP::ftp_get ;
  2076. sub ftp_get {
  2077. my($class,$host,$dir,$file,$target) = @_;
  2078. $class->debug(
  2079. qq[Going to fetch file [$file] from dir [$dir]
  2080. on host [$host] as local [$target]\n]
  2081. ) if $CPAN::DEBUG;
  2082. my $ftp = Net::FTP->new($host);
  2083. return 0 unless defined $ftp;
  2084. $ftp->debug(1) if $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG;
  2085. $class->debug(qq[Going to login("anonymous","$Config::Config{cf_email}")]);
  2086. unless ( $ftp->login("anonymous",$Config::Config{'cf_email'}) ){
  2087. warn "Couldn't login on $host";
  2088. return;
  2089. }
  2090. unless ( $ftp->cwd($dir) ){
  2091. warn "Couldn't cwd $dir";
  2092. return;
  2093. }
  2094. $ftp->binary;
  2095. $class->debug(qq[Going to ->get("$file","$target")\n]) if $CPAN::DEBUG;
  2096. unless ( $ftp->get($file,$target) ){
  2097. warn "Couldn't fetch $file from $host\n";
  2098. return;
  2099. }
  2100. $ftp->quit; # it's ok if this fails
  2101. return 1;
  2102. }
  2103. # If more accuracy is wanted/needed, Chris Leach sent me this patch...
  2104. # > *** /install/perl/live/lib/CPAN.pm- Wed Sep 24 13:08:48 1997
  2105. # > --- /tmp/cp Wed Sep 24 13:26:40 1997
  2106. # > ***************
  2107. # > *** 1562,1567 ****
  2108. # > --- 1562,1580 ----
  2109. # > return 1 if substr($url,0,4) eq "file";
  2110. # > return 1 unless $url =~ m|://([^/]+)|;
  2111. # > my $host = $1;
  2112. # > + my $proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'};
  2113. # > + if ($proxy) {
  2114. # > + $proxy =~ m|://([^/:]+)|;
  2115. # > + $proxy = $1;
  2116. # > + my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'};
  2117. # > + if ($noproxy) {
  2118. # > + if ($host !~ /$noproxy$/) {
  2119. # > + $host = $proxy;
  2120. # > + }
  2121. # > + } else {
  2122. # > + $host = $proxy;
  2123. # > + }
  2124. # > + }
  2125. # > require Net::Ping;
  2126. # > return 1 unless $Net::Ping::VERSION >= 2;
  2127. # > my $p;
  2128. #-> sub CPAN::FTP::localize ;
  2129. sub localize {
  2130. my($self,$file,$aslocal,$force) = @_;
  2131. $force ||= 0;
  2132. Carp::croak "Usage: ->localize(cpan_file,as_local_file[,$force])"
  2133. unless defined $aslocal;
  2134. $self->debug("file[$file] aslocal[$aslocal] force[$force]")
  2135. if $CPAN::DEBUG;
  2136. if ($^O eq 'MacOS') {
  2137. # Comment by AK on 2000-09-03: Uniq short filenames would be
  2138. # available in CHECKSUMS file
  2139. my($name, $path) = File::Basename::fileparse($aslocal, '');
  2140. if (length($name) > 31) {
  2141. $name =~ s/(
  2142. \.(
  2143. readme(\.(gz|Z))? |
  2144. (tar\.)?(gz|Z) |
  2145. tgz |
  2146. zip |
  2147. pm\.(gz|Z)
  2148. )
  2149. )$//x;
  2150. my $suf = $1;
  2151. my $size = 31 - length($suf);
  2152. while (length($name) > $size) {
  2153. chop $name;
  2154. }
  2155. $name .= $suf;
  2156. $aslocal = File::Spec->catfile($path, $name);
  2157. }
  2158. }
  2159. return $aslocal if -f $aslocal && -r _ && !($force & 1);
  2160. my($restore) = 0;
  2161. if (-f $aslocal){
  2162. rename $aslocal, "$aslocal.bak";
  2163. $restore++;
  2164. }
  2165. my($aslocal_dir) = File::Basename::dirname($aslocal);
  2166. File::Path::mkpath($aslocal_dir);
  2167. $CPAN::Frontend->mywarn(qq{Warning: You are not allowed to write into }.
  2168. qq{directory "$aslocal_dir".
  2169. I\'ll continue, but if you encounter problems, they may be due
  2170. to insufficient permissions.\n}) unless -w $aslocal_dir;
  2171. # Inheritance is not easier to manage than a few if/else branches
  2172. if ($CPAN::META->has_usable('LWP::UserAgent')) {
  2173. unless ($Ua) {
  2174. CPAN::LWP::UserAgent->config;
  2175. eval {$Ua = CPAN::LWP::UserAgent->new;}; # Why is has_usable still not fit enough?
  2176. if ($@) {
  2177. $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n")
  2178. if $CPAN::DEBUG;
  2179. } else {
  2180. my($var);
  2181. $Ua->proxy('ftp', $var)
  2182. if $var = $CPAN::Config->{ftp_proxy} || $ENV{ftp_proxy};
  2183. $Ua->proxy('http', $var)
  2184. if $var = $CPAN::Config->{http_proxy} || $ENV{http_proxy};
  2185. # >>>>> On Wed, 13 Dec 2000 09:21:34 -0500, "Robison, Jonathon (J.M.)" <jrobiso2@visteon.com> said:
  2186. #
  2187. # > I note that although CPAN.pm can use proxies, it doesn't seem equipped to
  2188. # > use ones that require basic autorization.
  2189. #
  2190. # > Example of when I use it manually in my own stuff:
  2191. #
  2192. # > $ua->proxy(['http','ftp'], http://my.proxy.server:83');
  2193. # > $req->proxy_authorization_basic("username","password");
  2194. # > $res = $ua->request($req);
  2195. #
  2196. $Ua->no_proxy($var)
  2197. if $var = $CPAN::Config->{no_proxy} || $ENV{no_proxy};
  2198. }
  2199. }
  2200. }
  2201. for my $prx (qw(ftp_proxy http_proxy no_proxy)) {
  2202. $ENV{$prx} = $CPAN::Config->{$prx} if $CPAN::Config->{$prx};
  2203. }
  2204. # Try the list of urls for each single object. We keep a record
  2205. # where we did get a file from
  2206. my(@reordered,$last);
  2207. $CPAN::Config->{urllist} ||= [];
  2208. unless (ref $CPAN::Config->{urllist} eq 'ARRAY') {
  2209. warn "Malformed urllist; ignoring. Configuration file corrupt?\n";
  2210. }
  2211. $last = $#{$CPAN::Config->{urllist}};
  2212. if ($force & 2) { # local cpans probably out of date, don't reorder
  2213. @reordered = (0..$last);
  2214. } else {
  2215. @reordered =
  2216. sort {
  2217. (substr($CPAN::Config->{urllist}[$b],0,4) eq "file")
  2218. <=>
  2219. (substr($CPAN::Config->{urllist}[$a],0,4) eq "file")
  2220. or
  2221. defined($Thesite)
  2222. and
  2223. ($b == $Thesite)
  2224. <=>
  2225. ($a == $Thesite)
  2226. } 0..$last;
  2227. }
  2228. my(@levels);
  2229. if ($Themethod) {
  2230. @levels = ($Themethod, grep {$_ ne $Themethod} qw/easy hard hardest/);
  2231. } else {
  2232. @levels = qw/easy hard hardest/;
  2233. }
  2234. @levels = qw/easy/ if $^O eq 'MacOS';
  2235. my($levelno);
  2236. for $levelno (0..$#levels) {
  2237. my $level = $levels[$levelno];
  2238. my $method = "host$level";
  2239. my @host_seq = $level eq "easy" ?
  2240. @reordered : 0..$last; # reordered has CDROM up front
  2241. @host_seq = (0) unless @host_seq;
  2242. my $ret = $self->$method(\@host_seq,$file,$aslocal);
  2243. if ($ret) {
  2244. $Themethod = $level;
  2245. my $now = time;
  2246. # utime $now, $now, $aslocal; # too bad, if we do that, we
  2247. # might alter a local mirror
  2248. $self->debug("level[$level]") if $CPAN::DEBUG;
  2249. return $ret;
  2250. } else {
  2251. unlink $aslocal;
  2252. last if $CPAN::Signal; # need to cleanup
  2253. }
  2254. }
  2255. unless ($CPAN::Signal) {
  2256. my(@mess);
  2257. push @mess,
  2258. qq{Please check, if the URLs I found in your configuration file \(}.
  2259. join(", ", @{$CPAN::Config->{urllist}}).
  2260. qq{\) are valid. The urllist can be edited.},
  2261. qq{E.g. with 'o conf urllist push ftp://myurl/'};
  2262. $CPAN::Frontend->myprint(Text::Wrap::wrap("","",@mess). "\n\n");
  2263. sleep 2;
  2264. $CPAN::Frontend->myprint("Could not fetch $file\n");
  2265. }
  2266. if ($restore) {
  2267. rename "$aslocal.bak", $aslocal;
  2268. $CPAN::Frontend->myprint("Trying to get away with old file:\n" .
  2269. $self->ls($aslocal));
  2270. return $aslocal;
  2271. }
  2272. return;
  2273. }
  2274. sub hosteasy {
  2275. my($self,$host_seq,$file,$aslocal) = @_;
  2276. my($i);
  2277. HOSTEASY: for $i (@$host_seq) {
  2278. my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
  2279. $url .= "/" unless substr($url,-1) eq "/";
  2280. $url .= $file;
  2281. $self->debug("localizing perlish[$url]") if $CPAN::DEBUG;
  2282. if ($url =~ /^file:/) {
  2283. my $l;
  2284. if ($CPAN::META->has_inst('URI::URL')) {
  2285. my $u = URI::URL->new($url);
  2286. $l = $u->path;
  2287. } else { # works only on Unix, is poorly constructed, but
  2288. # hopefully better than nothing.
  2289. # RFC 1738 says fileurl BNF is
  2290. # fileurl = "file://" [ host | "localhost" ] "/" fpath
  2291. # Thanks to "Mark D. Baushke" <mdb@cisco.com> for
  2292. # the code
  2293. ($l = $url) =~ s|^file://[^/]*/|/|; # discard the host part
  2294. $l =~ s|^file:||; # assume they
  2295. # meant
  2296. # file://localhost
  2297. $l =~ s|^/||s unless -f $l; # e.g. /P:
  2298. $self->debug("without URI::URL we try local file $l") if $CPAN::DEBUG;
  2299. }
  2300. if ( -f $l && -r _) {
  2301. $Thesite = $i;
  2302. return $l;
  2303. }
  2304. # Maybe mirror has compressed it?
  2305. if (-f "$l.gz") {
  2306. $self->debug("found compressed $l.gz") if $CPAN::DEBUG;
  2307. CPAN::Tarzip->gunzip("$l.gz", $aslocal);
  2308. if ( -f $aslocal) {
  2309. $Thesite = $i;
  2310. return $aslocal;
  2311. }
  2312. }
  2313. }
  2314. if ($CPAN::META->has_usable('LWP')) {
  2315. $CPAN::Frontend->myprint("Fetching with LWP:
  2316. $url
  2317. ");
  2318. unless ($Ua) {
  2319. CPAN::LWP::UserAgent->config;
  2320. eval { $Ua = CPAN::LWP::UserAgent->new; };
  2321. if ($@) {
  2322. $CPAN::Frontend->mywarn("CPAN::LWP::UserAgent->new dies with $@\n");
  2323. }
  2324. }
  2325. my $res = $Ua->mirror($url, $aslocal);
  2326. if ($res->is_success) {
  2327. $Thesite = $i;
  2328. my $now = time;
  2329. utime $now, $now, $aslocal; # download time is more
  2330. # important than upload time
  2331. return $aslocal;
  2332. } elsif ($url !~ /\.gz(?!\n)\Z/) {
  2333. my $gzurl = "$url.gz";
  2334. $CPAN::Frontend->myprint("Fetching with LWP:
  2335. $gzurl
  2336. ");
  2337. $res = $Ua->mirror($gzurl, "$aslocal.gz");
  2338. if ($res->is_success &&
  2339. CPAN::Tarzip->gunzip("$aslocal.gz",$aslocal)
  2340. ) {
  2341. $Thesite = $i;
  2342. return $aslocal;
  2343. }
  2344. } else {
  2345. $CPAN::Frontend->myprint(sprintf(
  2346. "LWP failed with code[%s] message[%s]\n",
  2347. $res->code,
  2348. $res->message,
  2349. ));
  2350. # Alan Burlison informed me that in firewall environments
  2351. # Net::FTP can still succeed where LWP fails. So we do not
  2352. # skip Net::FTP anymore when LWP is available.
  2353. }
  2354. } else {
  2355. $CPAN::Frontend->myprint("LWP not available\n");
  2356. }
  2357. return if $CPAN::Signal;
  2358. if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
  2359. # that's the nice and easy way thanks to Graham
  2360. my($host,$dir,$getfile) = ($1,$2,$3);
  2361. if ($CPAN::META->has_usable('Net::FTP')) {
  2362. $dir =~ s|/+|/|g;
  2363. $CPAN::Frontend->myprint("Fetching with Net::FTP:
  2364. $url
  2365. ");
  2366. $self->debug("getfile[$getfile]dir[$dir]host[$host]" .
  2367. "aslocal[$aslocal]") if $CPAN::DEBUG;
  2368. if (CPAN::FTP->ftp_get($host,$dir,$getfile,$aslocal)) {
  2369. $Thesite = $i;
  2370. return $aslocal;
  2371. }
  2372. if ($aslocal !~ /\.gz(?!\n)\Z/) {
  2373. my $gz = "$aslocal.gz";
  2374. $CPAN::Frontend->myprint("Fetching with Net::FTP
  2375. $url.gz
  2376. ");
  2377. if (CPAN::FTP->ftp_get($host,
  2378. $dir,
  2379. "$getfile.gz",
  2380. $gz) &&
  2381. CPAN::Tarzip->gunzip($gz,$aslocal)
  2382. ){
  2383. $Thesite = $i;
  2384. return $aslocal;
  2385. }
  2386. }
  2387. # next HOSTEASY;
  2388. }
  2389. }
  2390. return if $CPAN::Signal;
  2391. }
  2392. }
  2393. sub hosthard {
  2394. my($self,$host_seq,$file,$aslocal) = @_;
  2395. # Came back if Net::FTP couldn't establish connection (or
  2396. # failed otherwise) Maybe they are behind a firewall, but they
  2397. # gave us a socksified (or other) ftp program...
  2398. my($i);
  2399. my($devnull) = $CPAN::Config->{devnull} || "";
  2400. # < /dev/null ";
  2401. my($aslocal_dir) = File::Basename::dirname($aslocal);
  2402. File::Path::mkpath($aslocal_dir);
  2403. HOSTHARD: for $i (@$host_seq) {
  2404. my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
  2405. $url .= "/" unless substr($url,-1) eq "/";
  2406. $url .= $file;
  2407. my($proto,$host,$dir,$getfile);
  2408. # Courtesy Mark Conty mark_conty@cargill.com change from
  2409. # if ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
  2410. # to
  2411. if ($url =~ m|^([^:]+)://(.*?)/(.*)/(.*)|) {
  2412. # proto not yet used
  2413. ($proto,$host,$dir,$getfile) = ($1,$2,$3,$4);
  2414. } else {
  2415. next HOSTHARD; # who said, we could ftp anything except ftp?
  2416. }
  2417. next HOSTHARD if $proto eq "file"; # file URLs would have had
  2418. # success above. Likely a bogus URL
  2419. $self->debug("localizing funkyftpwise[$url]") if $CPAN::DEBUG;
  2420. my($f,$funkyftp);
  2421. for $f ('lynx','ncftpget','ncftp','wget') {
  2422. next unless exists $CPAN::Config->{$f};
  2423. $funkyftp = $CPAN::Config->{$f};
  2424. next unless defined $funkyftp;
  2425. next if $funkyftp =~ /^\s*$/;
  2426. my($asl_ungz, $asl_gz);
  2427. ($asl_ungz = $aslocal) =~ s/\.gz//;
  2428. $asl_gz = "$asl_ungz.gz";
  2429. my($src_switch) = "";
  2430. if ($f eq "lynx"){
  2431. $src_switch = " -source";
  2432. } elsif ($f eq "ncftp"){
  2433. $src_switch = " -c";
  2434. } elsif ($f eq "wget"){
  2435. $src_switch = " -O -";
  2436. }
  2437. my($chdir) = "";
  2438. my($stdout_redir) = " > $asl_ungz";
  2439. if ($f eq "ncftpget"){
  2440. $chdir = "cd $aslocal_dir && ";
  2441. $stdout_redir = "";
  2442. }
  2443. $CPAN::Frontend->myprint(
  2444. qq[
  2445. Trying with "$funkyftp$src_switch" to get
  2446. $url
  2447. ]);
  2448. my($system) =
  2449. "$chdir$funkyftp$src_switch \"$url\" $devnull$stdout_redir";
  2450. $self->debug("system[$system]") if $CPAN::DEBUG;
  2451. my($wstatus);
  2452. if (($wstatus = system($system)) == 0
  2453. &&
  2454. ($f eq "lynx" ?
  2455. -s $asl_ungz # lynx returns 0 when it fails somewhere
  2456. : 1
  2457. )
  2458. ) {
  2459. if (-s $aslocal) {
  2460. # Looks good
  2461. } elsif ($asl_ungz ne $aslocal) {
  2462. # test gzip integrity
  2463. if (CPAN::Tarzip->gtest($asl_ungz)) {
  2464. # e.g. foo.tar is gzipped --> foo.tar.gz
  2465. rename $asl_ungz, $aslocal;
  2466. } else {
  2467. CPAN::Tarzip->gzip($asl_ungz,$asl_gz);
  2468. }
  2469. }
  2470. $Thesite = $i;
  2471. return $aslocal;
  2472. } elsif ($url !~ /\.gz(?!\n)\Z/) {
  2473. unlink $asl_ungz if
  2474. -f $asl_ungz && -s _ == 0;
  2475. my $gz = "$aslocal.gz";
  2476. my $gzurl = "$url.gz";
  2477. $CPAN::Frontend->myprint(
  2478. qq[
  2479. Trying with "$funkyftp$src_switch" to get
  2480. $url.gz
  2481. ]);
  2482. my($system) = "$funkyftp$src_switch \"$url.gz\" $devnull > $asl_gz";
  2483. $self->debug("system[$system]") if $CPAN::DEBUG;
  2484. my($wstatus);
  2485. if (($wstatus = system($system)) == 0
  2486. &&
  2487. -s $asl_gz
  2488. ) {
  2489. # test gzip integrity
  2490. if (CPAN::Tarzip->gtest($asl_gz)) {
  2491. CPAN::Tarzip->gunzip($asl_gz,$aslocal);
  2492. } else {
  2493. # somebody uncompressed file for us?
  2494. rename $asl_ungz, $aslocal;
  2495. }
  2496. $Thesite = $i;
  2497. return $aslocal;
  2498. } else {
  2499. unlink $asl_gz if -f $asl_gz;
  2500. }
  2501. } else {
  2502. my $estatus = $wstatus >> 8;
  2503. my $size = -f $aslocal ?
  2504. ", left\n$aslocal with size ".-s _ :
  2505. "\nWarning: expected file [$aslocal] doesn't exist";
  2506. $CPAN::Frontend->myprint(qq{
  2507. System call "$system"
  2508. returned status $estatus (wstat $wstatus)$size
  2509. });
  2510. }
  2511. return if $CPAN::Signal;
  2512. } # lynx,ncftpget,ncftp
  2513. } # host
  2514. }
  2515. sub hosthardest {
  2516. my($self,$host_seq,$file,$aslocal) = @_;
  2517. my($i);
  2518. my($aslocal_dir) = File::Basename::dirname($aslocal);
  2519. File::Path::mkpath($aslocal_dir);
  2520. my $ftpbin = $CPAN::Config->{ftp};
  2521. HOSTHARDEST: for $i (@$host_seq) {
  2522. unless (length $ftpbin && MM->maybe_command($ftpbin)) {
  2523. $CPAN::Frontend->myprint("No external ftp command available\n\n");
  2524. last HOSTHARDEST;
  2525. }
  2526. my $url = $CPAN::Config->{urllist}[$i] || $CPAN::Defaultsite;
  2527. $url .= "/" unless substr($url,-1) eq "/";
  2528. $url .= $file;
  2529. $self->debug("localizing ftpwise[$url]") if $CPAN::DEBUG;
  2530. unless ($url =~ m|^ftp://(.*?)/(.*)/(.*)|) {
  2531. next;
  2532. }
  2533. my($host,$dir,$getfile) = ($1,$2,$3);
  2534. my $timestamp = 0;
  2535. my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
  2536. $ctime,$blksize,$blocks) = stat($aslocal);
  2537. $timestamp = $mtime ||= 0;
  2538. my($netrc) = CPAN::FTP::netrc->new;
  2539. my($netrcfile) = $netrc->netrc;
  2540. my($verbose) = $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG ? " -v" : "";
  2541. my $targetfile = File::Basename::basename($aslocal);
  2542. my(@dialog);
  2543. push(
  2544. @dialog,
  2545. "lcd $aslocal_dir",
  2546. "cd /",
  2547. map("cd $_", split /\//, $dir), # RFC 1738
  2548. "bin",
  2549. "get $getfile $targetfile",
  2550. "quit"
  2551. );
  2552. if (! $netrcfile) {
  2553. CPAN->debug("No ~/.netrc file found") if $CPAN::DEBUG;
  2554. } elsif ($netrc->hasdefault || $netrc->contains($host)) {
  2555. CPAN->debug(sprintf("hasdef[%d]cont($host)[%d]",
  2556. $netrc->hasdefault,
  2557. $netrc->contains($host))) if $CPAN::DEBUG;
  2558. if ($netrc->protected) {
  2559. $CPAN::Frontend->myprint(qq{
  2560. Trying with external ftp to get
  2561. $url
  2562. As this requires some features that are not thoroughly tested, we\'re
  2563. not sure, that we get it right....
  2564. }
  2565. );
  2566. $self->talk_ftp("$ftpbin$verbose $host",
  2567. @dialog);
  2568. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  2569. $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
  2570. $mtime ||= 0;
  2571. if ($mtime > $timestamp) {
  2572. $CPAN::Frontend->myprint("GOT $aslocal\n");
  2573. $Thesite = $i;
  2574. return $aslocal;
  2575. } else {
  2576. $CPAN::Frontend->myprint("Hmm... Still failed!\n");
  2577. }
  2578. return if $CPAN::Signal;
  2579. } else {
  2580. $CPAN::Frontend->mywarn(qq{Your $netrcfile is not }.
  2581. qq{correctly protected.\n});
  2582. }
  2583. } else {
  2584. $CPAN::Frontend->mywarn("Your ~/.netrc neither contains $host
  2585. nor does it have a default entry\n");
  2586. }
  2587. # OK, they don't have a valid ~/.netrc. Use 'ftp -n'
  2588. # then and login manually to host, using e-mail as
  2589. # password.
  2590. $CPAN::Frontend->myprint(qq{Issuing "$ftpbin$verbose -n"\n});
  2591. unshift(
  2592. @dialog,
  2593. "open $host",
  2594. "user anonymous $Config::Config{'cf_email'}"
  2595. );
  2596. $self->talk_ftp("$ftpbin$verbose -n", @dialog);
  2597. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  2598. $atime,$mtime,$ctime,$blksize,$blocks) = stat($aslocal);
  2599. $mtime ||= 0;
  2600. if ($mtime > $timestamp) {
  2601. $CPAN::Frontend->myprint("GOT $aslocal\n");
  2602. $Thesite = $i;
  2603. return $aslocal;
  2604. } else {
  2605. $CPAN::Frontend->myprint("Bad luck... Still failed!\n");
  2606. }
  2607. return if $CPAN::Signal;
  2608. $CPAN::Frontend->myprint("Can't access URL $url.\n\n");
  2609. sleep 2;
  2610. } # host
  2611. }
  2612. sub talk_ftp {
  2613. my($self,$command,@dialog) = @_;
  2614. my $fh = FileHandle->new;
  2615. $fh->open("|$command") or die "Couldn't open ftp: $!";
  2616. foreach (@dialog) { $fh->print("$_\n") }
  2617. $fh->close; # Wait for process to complete
  2618. my $wstatus = $?;
  2619. my $estatus = $wstatus >> 8;
  2620. $CPAN::Frontend->myprint(qq{
  2621. Subprocess "|$command"
  2622. returned status $estatus (wstat $wstatus)
  2623. }) if $wstatus;
  2624. }
  2625. # find2perl needs modularization, too, all the following is stolen
  2626. # from there
  2627. # CPAN::FTP::ls
  2628. sub ls {
  2629. my($self,$name) = @_;
  2630. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
  2631. $atime,$mtime,$ctime,$blksize,$blocks) = lstat($name);
  2632. my($perms,%user,%group);
  2633. my $pname = $name;
  2634. if ($blocks) {
  2635. $blocks = int(($blocks + 1) / 2);
  2636. }
  2637. else {
  2638. $blocks = int(($sizemm + 1023) / 1024);
  2639. }
  2640. if (-f _) { $perms = '-'; }
  2641. elsif (-d _) { $perms = 'd'; }
  2642. elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
  2643. elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
  2644. elsif (-p _) { $perms = 'p'; }
  2645. elsif (-S _) { $perms = 's'; }
  2646. else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
  2647. my(@rwx) = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
  2648. my(@moname) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  2649. my $tmpmode = $mode;
  2650. my $tmp = $rwx[$tmpmode & 7];
  2651. $tmpmode >>= 3;
  2652. $tmp = $rwx[$tmpmode & 7] . $tmp;
  2653. $tmpmode >>= 3;
  2654. $tmp = $rwx[$tmpmode & 7] . $tmp;
  2655. substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
  2656. substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
  2657. substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
  2658. $perms .= $tmp;
  2659. my $user = $user{$uid} || $uid; # too lazy to implement lookup
  2660. my $group = $group{$gid} || $gid;
  2661. my($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
  2662. my($timeyear);
  2663. my($moname) = $moname[$mon];
  2664. if (-M _ > 365.25 / 2) {
  2665. $timeyear = $year + 1900;
  2666. }
  2667. else {
  2668. $timeyear = sprintf("%02d:%02d", $hour, $min);
  2669. }
  2670. sprintf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
  2671. $ino,
  2672. $blocks,
  2673. $perms,
  2674. $nlink,
  2675. $user,
  2676. $group,
  2677. $sizemm,
  2678. $moname,
  2679. $mday,
  2680. $timeyear,
  2681. $pname;
  2682. }
  2683. package CPAN::FTP::netrc;
  2684. sub new {
  2685. my($class) = @_;
  2686. my $file = File::Spec->catfile($ENV{HOME},".netrc");
  2687. my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  2688. $atime,$mtime,$ctime,$blksize,$blocks)
  2689. = stat($file);
  2690. $mode ||= 0;
  2691. my $protected = 0;
  2692. my($fh,@machines,$hasdefault);
  2693. $hasdefault = 0;
  2694. $fh = FileHandle->new or die "Could not create a filehandle";
  2695. if($fh->open($file)){
  2696. $protected = ($mode & 077) == 0;
  2697. local($/) = "";
  2698. NETRC: while (<$fh>) {
  2699. my(@tokens) = split " ", $_;
  2700. TOKEN: while (@tokens) {
  2701. my($t) = shift @tokens;
  2702. if ($t eq "default"){
  2703. $hasdefault++;
  2704. last NETRC;
  2705. }
  2706. last TOKEN if $t eq "macdef";
  2707. if ($t eq "machine") {
  2708. push @machines, shift @tokens;
  2709. }
  2710. }
  2711. }
  2712. } else {
  2713. $file = $hasdefault = $protected = "";
  2714. }
  2715. bless {
  2716. 'mach' => [@machines],
  2717. 'netrc' => $file,
  2718. 'hasdefault' => $hasdefault,
  2719. 'protected' => $protected,
  2720. }, $class;
  2721. }
  2722. # CPAN::FTP::hasdefault;
  2723. sub hasdefault { shift->{'hasdefault'} }
  2724. sub netrc { shift->{'netrc'} }
  2725. sub protected { shift->{'protected'} }
  2726. sub contains {
  2727. my($self,$mach) = @_;
  2728. for ( @{$self->{'mach'}} ) {
  2729. return 1 if $_ eq $mach;
  2730. }
  2731. return 0;
  2732. }
  2733. package CPAN::Complete;
  2734. sub gnu_cpl {
  2735. my($text, $line, $start, $end) = @_;
  2736. my(@perlret) = cpl($text, $line, $start);
  2737. # find longest common match. Can anybody show me how to peruse
  2738. # T::R::Gnu to have this done automatically? Seems expensive.
  2739. return () unless @perlret;
  2740. my($newtext) = $text;
  2741. for (my $i = length($text)+1;;$i++) {
  2742. last unless length($perlret[0]) && length($perlret[0]) >= $i;
  2743. my $try = substr($perlret[0],0,$i);
  2744. my @tries = grep {substr($_,0,$i) eq $try} @perlret;
  2745. # warn "try[$try]tries[@tries]";
  2746. if (@tries == @perlret) {
  2747. $newtext = $try;
  2748. } else {
  2749. last;
  2750. }
  2751. }
  2752. ($newtext,@perlret);
  2753. }
  2754. #-> sub CPAN::Complete::cpl ;
  2755. sub cpl {
  2756. my($word,$line,$pos) = @_;
  2757. $word ||= "";
  2758. $line ||= "";
  2759. $pos ||= 0;
  2760. CPAN->debug("word [$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
  2761. $line =~ s/^\s*//;
  2762. if ($line =~ s/^(force\s*)//) {
  2763. $pos -= length($1);
  2764. }
  2765. my @return;
  2766. if ($pos == 0) {
  2767. @return = grep /^$word/, @CPAN::Complete::COMMANDS;
  2768. } elsif ( $line !~ /^[\!abcdghimorutl]/ ) {
  2769. @return = ();
  2770. } elsif ($line =~ /^(a|ls)\s/) {
  2771. @return = cplx('CPAN::Author',uc($word));
  2772. } elsif ($line =~ /^b\s/) {
  2773. CPAN::Shell->local_bundles;
  2774. @return = cplx('CPAN::Bundle',$word);
  2775. } elsif ($line =~ /^d\s/) {
  2776. @return = cplx('CPAN::Distribution',$word);
  2777. } elsif ($line =~ m/^(
  2778. [mru]|make|clean|dump|get|test|install|readme|look|cvs_import
  2779. )\s/x ) {
  2780. if ($word =~ /^Bundle::/) {
  2781. CPAN::Shell->local_bundles;
  2782. }
  2783. @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
  2784. } elsif ($line =~ /^i\s/) {
  2785. @return = cpl_any($word);
  2786. } elsif ($line =~ /^reload\s/) {
  2787. @return = cpl_reload($word,$line,$pos);
  2788. } elsif ($line =~ /^o\s/) {
  2789. @return = cpl_option($word,$line,$pos);
  2790. } elsif ($line =~ m/^\S+\s/ ) {
  2791. # fallback for future commands and what we have forgotten above
  2792. @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
  2793. } else {
  2794. @return = ();
  2795. }
  2796. return @return;
  2797. }
  2798. #-> sub CPAN::Complete::cplx ;
  2799. sub cplx {
  2800. my($class, $word) = @_;
  2801. # I believed for many years that this was sorted, today I
  2802. # realized, it wasn't sorted anymore. Now (rev 1.301 / v 1.55) I
  2803. # make it sorted again. Maybe sort was dropped when GNU-readline
  2804. # support came in? The RCS file is difficult to read on that:-(
  2805. sort grep /^\Q$word\E/, map { $_->id } $CPAN::META->all_objects($class);
  2806. }
  2807. #-> sub CPAN::Complete::cpl_any ;
  2808. sub cpl_any {
  2809. my($word) = shift;
  2810. return (
  2811. cplx('CPAN::Author',$word),
  2812. cplx('CPAN::Bundle',$word),
  2813. cplx('CPAN::Distribution',$word),
  2814. cplx('CPAN::Module',$word),
  2815. );
  2816. }
  2817. #-> sub CPAN::Complete::cpl_reload ;
  2818. sub cpl_reload {
  2819. my($word,$line,$pos) = @_;
  2820. $word ||= "";
  2821. my(@words) = split " ", $line;
  2822. CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
  2823. my(@ok) = qw(cpan index);
  2824. return @ok if @words == 1;
  2825. return grep /^\Q$word\E/, @ok if @words == 2 && $word;
  2826. }
  2827. #-> sub CPAN::Complete::cpl_option ;
  2828. sub cpl_option {
  2829. my($word,$line,$pos) = @_;
  2830. $word ||= "";
  2831. my(@words) = split " ", $line;
  2832. CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
  2833. my(@ok) = qw(conf debug);
  2834. return @ok if @words == 1;
  2835. return grep /^\Q$word\E/, @ok if @words == 2 && length($word);
  2836. if (0) {
  2837. } elsif ($words[1] eq 'index') {
  2838. return ();
  2839. } elsif ($words[1] eq 'conf') {
  2840. return CPAN::Config::cpl(@_);
  2841. } elsif ($words[1] eq 'debug') {
  2842. return sort grep /^\Q$word\E/, sort keys %CPAN::DEBUG, 'all';
  2843. }
  2844. }
  2845. package CPAN::Index;
  2846. #-> sub CPAN::Index::force_reload ;
  2847. sub force_reload {
  2848. my($class) = @_;
  2849. $CPAN::Index::LAST_TIME = 0;
  2850. $class->reload(1);
  2851. }
  2852. #-> sub CPAN::Index::reload ;
  2853. sub reload {
  2854. my($cl,$force) = @_;
  2855. my $time = time;
  2856. # XXX check if a newer one is available. (We currently read it
  2857. # from time to time)
  2858. for ($CPAN::Config->{index_expire}) {
  2859. $_ = 0.001 unless $_ && $_ > 0.001;
  2860. }
  2861. unless (1 || $CPAN::Have_warned->{readmetadatacache}++) {
  2862. # debug here when CPAN doesn't seem to read the Metadata
  2863. require Carp;
  2864. Carp::cluck("META-PROTOCOL[$CPAN::META->{PROTOCOL}]");
  2865. }
  2866. unless ($CPAN::META->{PROTOCOL}) {
  2867. $cl->read_metadata_cache;
  2868. $CPAN::META->{PROTOCOL} ||= "1.0";
  2869. }
  2870. if ( $CPAN::META->{PROTOCOL} < PROTOCOL ) {
  2871. # warn "Setting last_time to 0";
  2872. $LAST_TIME = 0; # No warning necessary
  2873. }
  2874. return if $LAST_TIME + $CPAN::Config->{index_expire}*86400 > $time
  2875. and ! $force;
  2876. if (0) {
  2877. # IFF we are developing, it helps to wipe out the memory
  2878. # between reloads, otherwise it is not what a user expects.
  2879. undef $CPAN::META; # Neue Gruendlichkeit since v1.52(r1.274)
  2880. $CPAN::META = CPAN->new;
  2881. }
  2882. {
  2883. my($debug,$t2);
  2884. local $LAST_TIME = $time;
  2885. local $CPAN::META->{PROTOCOL} = PROTOCOL;
  2886. my $needshort = $^O eq "dos";
  2887. $cl->rd_authindex($cl
  2888. ->reload_x(
  2889. "authors/01mailrc.txt.gz",
  2890. $needshort ?
  2891. File::Spec->catfile('authors', '01mailrc.gz') :
  2892. File::Spec->catfile('authors', '01mailrc.txt.gz'),
  2893. $force));
  2894. $t2 = time;
  2895. $debug = "timing reading 01[".($t2 - $time)."]";
  2896. $time = $t2;
  2897. return if $CPAN::Signal; # this is sometimes lengthy
  2898. $cl->rd_modpacks($cl
  2899. ->reload_x(
  2900. "modules/02packages.details.txt.gz",
  2901. $needshort ?
  2902. File::Spec->catfile('modules', '02packag.gz') :
  2903. File::Spec->catfile('modules', '02packages.details.txt.gz'),
  2904. $force));
  2905. $t2 = time;
  2906. $debug .= "02[".($t2 - $time)."]";
  2907. $time = $t2;
  2908. return if $CPAN::Signal; # this is sometimes lengthy
  2909. $cl->rd_modlist($cl
  2910. ->reload_x(
  2911. "modules/03modlist.data.gz",
  2912. $needshort ?
  2913. File::Spec->catfile('modules', '03mlist.gz') :
  2914. File::Spec->catfile('modules', '03modlist.data.gz'),
  2915. $force));
  2916. $cl->write_metadata_cache;
  2917. $t2 = time;
  2918. $debug .= "03[".($t2 - $time)."]";
  2919. $time = $t2;
  2920. CPAN->debug($debug) if $CPAN::DEBUG;
  2921. }
  2922. $LAST_TIME = $time;
  2923. $CPAN::META->{PROTOCOL} = PROTOCOL;
  2924. }
  2925. #-> sub CPAN::Index::reload_x ;
  2926. sub reload_x {
  2927. my($cl,$wanted,$localname,$force) = @_;
  2928. $force |= 2; # means we're dealing with an index here
  2929. CPAN::Config->load; # we should guarantee loading wherever we rely
  2930. # on Config XXX
  2931. $localname ||= $wanted;
  2932. my $abs_wanted = File::Spec->catfile($CPAN::Config->{'keep_source_where'},
  2933. $localname);
  2934. if (
  2935. -f $abs_wanted &&
  2936. -M $abs_wanted < $CPAN::Config->{'index_expire'} &&
  2937. !($force & 1)
  2938. ) {
  2939. my $s = $CPAN::Config->{'index_expire'} == 1 ? "" : "s";
  2940. $cl->debug(qq{$abs_wanted younger than $CPAN::Config->{'index_expire'} }.
  2941. qq{day$s. I\'ll use that.});
  2942. return $abs_wanted;
  2943. } else {
  2944. $force |= 1; # means we're quite serious about it.
  2945. }
  2946. return CPAN::FTP->localize($wanted,$abs_wanted,$force);
  2947. }
  2948. #-> sub CPAN::Index::rd_authindex ;
  2949. sub rd_authindex {
  2950. my($cl, $index_target) = @_;
  2951. my @lines;
  2952. return unless defined $index_target;
  2953. $CPAN::Frontend->myprint("Going to read $index_target\n");
  2954. local(*FH);
  2955. tie *FH, CPAN::Tarzip, $index_target;
  2956. local($/) = "\n";
  2957. push @lines, split /\012/ while <FH>;
  2958. foreach (@lines) {
  2959. my($userid,$fullname,$email) =
  2960. m/alias\s+(\S+)\s+\"([^\"\<]+)\s+\<([^\>]+)\>\"/;
  2961. next unless $userid && $fullname && $email;
  2962. # instantiate an author object
  2963. my $userobj = $CPAN::META->instance('CPAN::Author',$userid);
  2964. $userobj->set('FULLNAME' => $fullname, 'EMAIL' => $email);
  2965. return if $CPAN::Signal;
  2966. }
  2967. }
  2968. sub userid {
  2969. my($self,$dist) = @_;
  2970. $dist = $self->{'id'} unless defined $dist;
  2971. my($ret) = $dist =~ m|(?:\w/\w\w/)?([^/]+)/|;
  2972. $ret;
  2973. }
  2974. #-> sub CPAN::Index::rd_modpacks ;
  2975. sub rd_modpacks {
  2976. my($self, $index_target) = @_;
  2977. my @lines;
  2978. return unless defined $index_target;
  2979. $CPAN::Frontend->myprint("Going to read $index_target\n");
  2980. my $fh = CPAN::Tarzip->TIEHANDLE($index_target);
  2981. local($/) = "\n";
  2982. while ($_ = $fh->READLINE) {
  2983. s/\012/\n/g;
  2984. my @ls = map {"$_\n"} split /\n/, $_;
  2985. unshift @ls, "\n" x length($1) if /^(\n+)/;
  2986. push @lines, @ls;
  2987. }
  2988. # read header
  2989. my($line_count,$last_updated);
  2990. while (@lines) {
  2991. my $shift = shift(@lines);
  2992. last if $shift =~ /^\s*$/;
  2993. $shift =~ /^Line-Count:\s+(\d+)/ and $line_count = $1;
  2994. $shift =~ /^Last-Updated:\s+(.+)/ and $last_updated = $1;
  2995. }
  2996. if (not defined $line_count) {
  2997. warn qq{Warning: Your $index_target does not contain a Line-Count header.
  2998. Please check the validity of the index file by comparing it to more
  2999. than one CPAN mirror. I'll continue but problems seem likely to
  3000. happen.\a
  3001. };
  3002. sleep 5;
  3003. } elsif ($line_count != scalar @lines) {
  3004. warn sprintf qq{Warning: Your %s
  3005. contains a Line-Count header of %d but I see %d lines there. Please
  3006. check the validity of the index file by comparing it to more than one
  3007. CPAN mirror. I'll continue but problems seem likely to happen.\a\n},
  3008. $index_target, $line_count, scalar(@lines);
  3009. }
  3010. if (not defined $last_updated) {
  3011. warn qq{Warning: Your $index_target does not contain a Last-Updated header.
  3012. Please check the validity of the index file by comparing it to more
  3013. than one CPAN mirror. I'll continue but problems seem likely to
  3014. happen.\a
  3015. };
  3016. sleep 5;
  3017. } else {
  3018. $CPAN::Frontend
  3019. ->myprint(sprintf qq{ Database was generated on %s\n},
  3020. $last_updated);
  3021. $DATE_OF_02 = $last_updated;
  3022. if ($CPAN::META->has_inst(HTTP::Date)) {
  3023. require HTTP::Date;
  3024. my($age) = (time - HTTP::Date::str2time($last_updated))/3600/24;
  3025. if ($age > 30) {
  3026. $CPAN::Frontend
  3027. ->mywarn(sprintf
  3028. qq{Warning: This index file is %d days old.
  3029. Please check the host you chose as your CPAN mirror for staleness.
  3030. I'll continue but problems seem likely to happen.\a\n},
  3031. $age);
  3032. }
  3033. } else {
  3034. $CPAN::Frontend->myprint(" HTTP::Date not available\n");
  3035. }
  3036. }
  3037. # A necessity since we have metadata_cache: delete what isn't
  3038. # there anymore
  3039. my $secondtime = $CPAN::META->exists("CPAN::Module","CPAN");
  3040. CPAN->debug("secondtime[$secondtime]") if $CPAN::DEBUG;
  3041. my(%exists);
  3042. foreach (@lines) {
  3043. chomp;
  3044. # before 1.56 we split into 3 and discarded the rest. From
  3045. # 1.57 we assign remaining text to $comment thus allowing to
  3046. # influence isa_perl
  3047. my($mod,$version,$dist,$comment) = split " ", $_, 4;
  3048. my($bundle,$id,$userid);
  3049. if ($mod eq 'CPAN' &&
  3050. ! (
  3051. CPAN::Queue->exists('Bundle::CPAN') ||
  3052. CPAN::Queue->exists('CPAN')
  3053. )
  3054. ) {
  3055. local($^W)= 0;
  3056. if ($version > $CPAN::VERSION){
  3057. $CPAN::Frontend->myprint(qq{
  3058. There's a new CPAN.pm version (v$version) available!
  3059. [Current version is v$CPAN::VERSION]
  3060. You might want to try
  3061. install Bundle::CPAN
  3062. reload cpan
  3063. without quitting the current session. It should be a seamless upgrade
  3064. while we are running...
  3065. }); #});
  3066. sleep 2;
  3067. $CPAN::Frontend->myprint(qq{\n});
  3068. }
  3069. last if $CPAN::Signal;
  3070. } elsif ($mod =~ /^Bundle::(.*)/) {
  3071. $bundle = $1;
  3072. }
  3073. if ($bundle){
  3074. $id = $CPAN::META->instance('CPAN::Bundle',$mod);
  3075. # Let's make it a module too, because bundles have so much
  3076. # in common with modules.
  3077. # Changed in 1.57_63: seems like memory bloat now without
  3078. # any value, so commented out
  3079. # $CPAN::META->instance('CPAN::Module',$mod);
  3080. } else {
  3081. # instantiate a module object
  3082. $id = $CPAN::META->instance('CPAN::Module',$mod);
  3083. }
  3084. if ($id->cpan_file ne $dist){ # update only if file is
  3085. # different. CPAN prohibits same
  3086. # name with different version
  3087. $userid = $id->userid || $self->userid($dist);
  3088. $id->set(
  3089. 'CPAN_USERID' => $userid,
  3090. 'CPAN_VERSION' => $version,
  3091. 'CPAN_FILE' => $dist,
  3092. );
  3093. }
  3094. # instantiate a distribution object
  3095. if ($CPAN::META->exists('CPAN::Distribution',$dist)) {
  3096. # we do not need CONTAINSMODS unless we do something with
  3097. # this dist, so we better produce it on demand.
  3098. ## my $obj = $CPAN::META->instance(
  3099. ## 'CPAN::Distribution' => $dist
  3100. ## );
  3101. ## $obj->{CONTAINSMODS}{$mod} = undef; # experimental
  3102. } else {
  3103. $CPAN::META->instance(
  3104. 'CPAN::Distribution' => $dist
  3105. )->set(
  3106. 'CPAN_USERID' => $userid,
  3107. 'CPAN_COMMENT' => $comment,
  3108. );
  3109. }
  3110. if ($secondtime) {
  3111. for my $name ($mod,$dist) {
  3112. CPAN->debug("exists name[$name]") if $CPAN::DEBUG;
  3113. $exists{$name} = undef;
  3114. }
  3115. }
  3116. return if $CPAN::Signal;
  3117. }
  3118. undef $fh;
  3119. if ($secondtime) {
  3120. for my $class (qw(CPAN::Module CPAN::Bundle CPAN::Distribution)) {
  3121. for my $o ($CPAN::META->all_objects($class)) {
  3122. next if exists $exists{$o->{ID}};
  3123. $CPAN::META->delete($class,$o->{ID});
  3124. CPAN->debug("deleting ID[$o->{ID}] in class[$class]")
  3125. if $CPAN::DEBUG;
  3126. }
  3127. }
  3128. }
  3129. }
  3130. #-> sub CPAN::Index::rd_modlist ;
  3131. sub rd_modlist {
  3132. my($cl,$index_target) = @_;
  3133. return unless defined $index_target;
  3134. $CPAN::Frontend->myprint("Going to read $index_target\n");
  3135. my $fh = CPAN::Tarzip->TIEHANDLE($index_target);
  3136. my @eval;
  3137. local($/) = "\n";
  3138. while ($_ = $fh->READLINE) {
  3139. s/\012/\n/g;
  3140. my @ls = map {"$_\n"} split /\n/, $_;
  3141. unshift @ls, "\n" x length($1) if /^(\n+)/;
  3142. push @eval, @ls;
  3143. }
  3144. while (@eval) {
  3145. my $shift = shift(@eval);
  3146. if ($shift =~ /^Date:\s+(.*)/){
  3147. return if $DATE_OF_03 eq $1;
  3148. ($DATE_OF_03) = $1;
  3149. }
  3150. last if $shift =~ /^\s*$/;
  3151. }
  3152. undef $fh;
  3153. push @eval, q{CPAN::Modulelist->data;};
  3154. local($^W) = 0;
  3155. my($comp) = Safe->new("CPAN::Safe1");
  3156. my($eval) = join("", @eval);
  3157. my $ret = $comp->reval($eval);
  3158. Carp::confess($@) if $@;
  3159. return if $CPAN::Signal;
  3160. for (keys %$ret) {
  3161. my $obj = $CPAN::META->instance("CPAN::Module",$_);
  3162. delete $ret->{$_}{modid}; # not needed here, maybe elsewhere
  3163. $obj->set(%{$ret->{$_}});
  3164. return if $CPAN::Signal;
  3165. }
  3166. }
  3167. #-> sub CPAN::Index::write_metadata_cache ;
  3168. sub write_metadata_cache {
  3169. my($self) = @_;
  3170. return unless $CPAN::Config->{'cache_metadata'};
  3171. return unless $CPAN::META->has_usable("Storable");
  3172. my $cache;
  3173. foreach my $k (qw(CPAN::Bundle CPAN::Author CPAN::Module
  3174. CPAN::Distribution)) {
  3175. $cache->{$k} = $CPAN::META->{readonly}{$k}; # unsafe meta access, ok
  3176. }
  3177. my $metadata_file = File::Spec->catfile($CPAN::Config->{cpan_home},"Metadata");
  3178. $cache->{last_time} = $LAST_TIME;
  3179. $cache->{DATE_OF_02} = $DATE_OF_02;
  3180. $cache->{PROTOCOL} = PROTOCOL;
  3181. $CPAN::Frontend->myprint("Going to write $metadata_file\n");
  3182. eval { Storable::nstore($cache, $metadata_file) };
  3183. $CPAN::Frontend->mywarn($@) if $@; # ?? missing "\n" after $@ in mywarn ??
  3184. }
  3185. #-> sub CPAN::Index::read_metadata_cache ;
  3186. sub read_metadata_cache {
  3187. my($self) = @_;
  3188. return unless $CPAN::Config->{'cache_metadata'};
  3189. return unless $CPAN::META->has_usable("Storable");
  3190. my $metadata_file = File::Spec->catfile($CPAN::Config->{cpan_home},"Metadata");
  3191. return unless -r $metadata_file and -f $metadata_file;
  3192. $CPAN::Frontend->myprint("Going to read $metadata_file\n");
  3193. my $cache;
  3194. eval { $cache = Storable::retrieve($metadata_file) };
  3195. $CPAN::Frontend->mywarn($@) if $@; # ?? missing "\n" after $@ in mywarn ??
  3196. if (!$cache || ref $cache ne 'HASH'){
  3197. $LAST_TIME = 0;
  3198. return;
  3199. }
  3200. if (exists $cache->{PROTOCOL}) {
  3201. if (PROTOCOL > $cache->{PROTOCOL}) {
  3202. $CPAN::Frontend->mywarn(sprintf("Ignoring Metadata cache written ".
  3203. "with protocol v%s, requiring v%s\n",
  3204. $cache->{PROTOCOL},
  3205. PROTOCOL)
  3206. );
  3207. return;
  3208. }
  3209. } else {
  3210. $CPAN::Frontend->mywarn("Ignoring Metadata cache written ".
  3211. "with protocol v1.0\n");
  3212. return;
  3213. }
  3214. my $clcnt = 0;
  3215. my $idcnt = 0;
  3216. while(my($class,$v) = each %$cache) {
  3217. next unless $class =~ /^CPAN::/;
  3218. $CPAN::META->{readonly}{$class} = $v; # unsafe meta access, ok
  3219. while (my($id,$ro) = each %$v) {
  3220. $CPAN::META->{readwrite}{$class}{$id} ||=
  3221. $class->new(ID=>$id, RO=>$ro);
  3222. $idcnt++;
  3223. }
  3224. $clcnt++;
  3225. }
  3226. unless ($clcnt) { # sanity check
  3227. $CPAN::Frontend->myprint("Warning: Found no data in $metadata_file\n");
  3228. return;
  3229. }
  3230. if ($idcnt < 1000) {
  3231. $CPAN::Frontend->myprint("Warning: Found only $idcnt objects ".
  3232. "in $metadata_file\n");
  3233. return;
  3234. }
  3235. $CPAN::META->{PROTOCOL} ||=
  3236. $cache->{PROTOCOL}; # reading does not up or downgrade, but it
  3237. # does initialize to some protocol
  3238. $LAST_TIME = $cache->{last_time};
  3239. $DATE_OF_02 = $cache->{DATE_OF_02};
  3240. $CPAN::Frontend->myprint(" Database was generated on $DATE_OF_02\n")
  3241. if defined $DATE_OF_02; # An old cache may not contain DATE_OF_02
  3242. return;
  3243. }
  3244. package CPAN::InfoObj;
  3245. # Accessors
  3246. sub cpan_userid {
  3247. my $self = shift;
  3248. $self->{RO}{CPAN_USERID}
  3249. }
  3250. sub id { shift->{ID}; }
  3251. #-> sub CPAN::InfoObj::new ;
  3252. sub new {
  3253. my $this = bless {}, shift;
  3254. %$this = @_;
  3255. $this
  3256. }
  3257. # The set method may only be used by code that reads index data or
  3258. # otherwise "objective" data from the outside world. All session
  3259. # related material may do anything else with instance variables but
  3260. # must not touch the hash under the RO attribute. The reason is that
  3261. # the RO hash gets written to Metadata file and is thus persistent.
  3262. #-> sub CPAN::InfoObj::set ;
  3263. sub set {
  3264. my($self,%att) = @_;
  3265. my $class = ref $self;
  3266. # This must be ||=, not ||, because only if we write an empty
  3267. # reference, only then the set method will write into the readonly
  3268. # area. But for Distributions that spring into existence, maybe
  3269. # because of a typo, we do not like it that they are written into
  3270. # the readonly area and made permanent (at least for a while) and
  3271. # that is why we do not "allow" other places to call ->set.
  3272. unless ($self->id) {
  3273. CPAN->debug("Bug? Empty ID, rejecting");
  3274. return;
  3275. }
  3276. my $ro = $self->{RO} =
  3277. $CPAN::META->{readonly}{$class}{$self->id} ||= {};
  3278. while (my($k,$v) = each %att) {
  3279. $ro->{$k} = $v;
  3280. }
  3281. }
  3282. #-> sub CPAN::InfoObj::as_glimpse ;
  3283. sub as_glimpse {
  3284. my($self) = @_;
  3285. my(@m);
  3286. my $class = ref($self);
  3287. $class =~ s/^CPAN:://;
  3288. push @m, sprintf "%-15s %s\n", $class, $self->{ID};
  3289. join "", @m;
  3290. }
  3291. #-> sub CPAN::InfoObj::as_string ;
  3292. sub as_string {
  3293. my($self) = @_;
  3294. my(@m);
  3295. my $class = ref($self);
  3296. $class =~ s/^CPAN:://;
  3297. push @m, $class, " id = $self->{ID}\n";
  3298. for (sort keys %{$self->{RO}}) {
  3299. # next if m/^(ID|RO)$/;
  3300. my $extra = "";
  3301. if ($_ eq "CPAN_USERID") {
  3302. $extra .= " (".$self->author;
  3303. my $email; # old perls!
  3304. if ($email = $CPAN::META->instance("CPAN::Author",
  3305. $self->cpan_userid
  3306. )->email) {
  3307. $extra .= " <$email>";
  3308. } else {
  3309. $extra .= " <no email>";
  3310. }
  3311. $extra .= ")";
  3312. } elsif ($_ eq "FULLNAME") { # potential UTF-8 conversion
  3313. push @m, sprintf " %-12s %s\n", $_, $self->fullname;
  3314. next;
  3315. }
  3316. next unless defined $self->{RO}{$_};
  3317. push @m, sprintf " %-12s %s%s\n", $_, $self->{RO}{$_}, $extra;
  3318. }
  3319. for (sort keys %$self) {
  3320. next if m/^(ID|RO)$/;
  3321. if (ref($self->{$_}) eq "ARRAY") {
  3322. push @m, sprintf " %-12s %s\n", $_, "@{$self->{$_}}";
  3323. } elsif (ref($self->{$_}) eq "HASH") {
  3324. push @m, sprintf(
  3325. " %-12s %s\n",
  3326. $_,
  3327. join(" ",keys %{$self->{$_}}),
  3328. );
  3329. } else {
  3330. push @m, sprintf " %-12s %s\n", $_, $self->{$_};
  3331. }
  3332. }
  3333. join "", @m, "\n";
  3334. }
  3335. #-> sub CPAN::InfoObj::author ;
  3336. sub author {
  3337. my($self) = @_;
  3338. $CPAN::META->instance("CPAN::Author",$self->cpan_userid)->fullname;
  3339. }
  3340. #-> sub CPAN::InfoObj::dump ;
  3341. sub dump {
  3342. my($self) = @_;
  3343. require Data::Dumper;
  3344. print Data::Dumper::Dumper($self);
  3345. }
  3346. package CPAN::Author;
  3347. #-> sub CPAN::Author::id
  3348. sub id {
  3349. my $self = shift;
  3350. my $id = $self->{ID};
  3351. $CPAN::Frontend->mydie("Illegal author id[$id]") unless $id =~ /^[A-Z]/;
  3352. $id;
  3353. }
  3354. #-> sub CPAN::Author::as_glimpse ;
  3355. sub as_glimpse {
  3356. my($self) = @_;
  3357. my(@m);
  3358. my $class = ref($self);
  3359. $class =~ s/^CPAN:://;
  3360. push @m, sprintf(qq{%-15s %s ("%s" <%s>)\n},
  3361. $class,
  3362. $self->{ID},
  3363. $self->fullname,
  3364. $self->email);
  3365. join "", @m;
  3366. }
  3367. #-> sub CPAN::Author::fullname ;
  3368. sub fullname {
  3369. shift->{RO}{FULLNAME};
  3370. }
  3371. *name = \&fullname;
  3372. #-> sub CPAN::Author::email ;
  3373. sub email { shift->{RO}{EMAIL}; }
  3374. #-> sub CPAN::Author::ls ;
  3375. sub ls {
  3376. my $self = shift;
  3377. my $id = $self->id;
  3378. # adapted from CPAN::Distribution::verifyMD5 ;
  3379. my(@csf); # chksumfile
  3380. @csf = $self->id =~ /(.)(.)(.*)/;
  3381. $csf[1] = join "", @csf[0,1];
  3382. $csf[2] = join "", @csf[1,2];
  3383. my(@dl);
  3384. @dl = $self->dir_listing([$csf[0],"CHECKSUMS"], 0);
  3385. unless (grep {$_->[2] eq $csf[1]} @dl) {
  3386. $CPAN::Frontend->myprint("No files in the directory of $id\n");
  3387. return;
  3388. }
  3389. @dl = $self->dir_listing([@csf[0,1],"CHECKSUMS"], 0);
  3390. unless (grep {$_->[2] eq $csf[2]} @dl) {
  3391. $CPAN::Frontend->myprint("No files in the directory of $id\n");
  3392. return;
  3393. }
  3394. @dl = $self->dir_listing([@csf,"CHECKSUMS"], 1);
  3395. $CPAN::Frontend->myprint(join "", map {
  3396. sprintf("%8d %10s %s/%s\n", $_->[0], $_->[1], $id, $_->[2])
  3397. } sort { $a->[2] cmp $b->[2] } @dl);
  3398. }
  3399. # returns an array of arrays, the latter contain (size,mtime,filename)
  3400. #-> sub CPAN::Author::dir_listing ;
  3401. sub dir_listing {
  3402. my $self = shift;
  3403. my $chksumfile = shift;
  3404. my $recursive = shift;
  3405. my $lc_want =
  3406. File::Spec->catfile($CPAN::Config->{keep_source_where},
  3407. "authors", "id", @$chksumfile);
  3408. local($") = "/";
  3409. # connect "force" argument with "index_expire".
  3410. my $force = 0;
  3411. if (my @stat = stat $lc_want) {
  3412. $force = $stat[9] + $CPAN::Config->{index_expire}*86400 <= time;
  3413. }
  3414. my $lc_file = CPAN::FTP->localize("authors/id/@$chksumfile",
  3415. $lc_want,$force);
  3416. unless ($lc_file) {
  3417. $CPAN::Frontend->myprint("Trying $lc_want.gz\n");
  3418. $chksumfile->[-1] .= ".gz";
  3419. $lc_file = CPAN::FTP->localize("authors/id/@$chksumfile",
  3420. "$lc_want.gz",1);
  3421. if ($lc_file) {
  3422. $lc_file =~ s{\.gz(?!\n)\Z}{}; #};
  3423. CPAN::Tarzip->gunzip("$lc_file.gz",$lc_file);
  3424. } else {
  3425. return;
  3426. }
  3427. }
  3428. # adapted from CPAN::Distribution::MD5_check_file ;
  3429. my $fh = FileHandle->new;
  3430. my($cksum);
  3431. if (open $fh, $lc_file){
  3432. local($/);
  3433. my $eval = <$fh>;
  3434. $eval =~ s/\015?\012/\n/g;
  3435. close $fh;
  3436. my($comp) = Safe->new();
  3437. $cksum = $comp->reval($eval);
  3438. if ($@) {
  3439. rename $lc_file, "$lc_file.bad";
  3440. Carp::confess($@) if $@;
  3441. }
  3442. } else {
  3443. Carp::carp "Could not open $lc_file for reading";
  3444. }
  3445. my(@result,$f);
  3446. for $f (sort keys %$cksum) {
  3447. if (exists $cksum->{$f}{isdir}) {
  3448. if ($recursive) {
  3449. my(@dir) = @$chksumfile;
  3450. pop @dir;
  3451. push @dir, $f, "CHECKSUMS";
  3452. push @result, map {
  3453. [$_->[0], $_->[1], "$f/$_->[2]"]
  3454. } $self->dir_listing(\@dir,1);
  3455. } else {
  3456. push @result, [ 0, "-", $f ];
  3457. }
  3458. } else {
  3459. push @result, [
  3460. ($cksum->{$f}{"size"}||0),
  3461. $cksum->{$f}{"mtime"}||"---",
  3462. $f
  3463. ];
  3464. }
  3465. }
  3466. @result;
  3467. }
  3468. package CPAN::Distribution;
  3469. # Accessors
  3470. sub cpan_comment { shift->{RO}{CPAN_COMMENT} }
  3471. sub undelay {
  3472. my $self = shift;
  3473. delete $self->{later};
  3474. }
  3475. # CPAN::Distribution::normalize
  3476. sub normalize {
  3477. my($self,$s) = @_;
  3478. $s = $self->id unless defined $s;
  3479. if (
  3480. $s =~ tr|/|| == 1
  3481. or
  3482. $s !~ m|[A-Z]/[A-Z-]{2}/[A-Z-]{2,}/|
  3483. ) {
  3484. return $s if $s =~ m:^N/A|^Contact Author: ;
  3485. $s =~ s|^(.)(.)([^/]*/)(.+)$|$1/$1$2/$1$2$3$4| or
  3486. $CPAN::Frontend->mywarn("Strange distribution name [$s]\n");
  3487. CPAN->debug("s[$s]") if $CPAN::DEBUG;
  3488. }
  3489. $s;
  3490. }
  3491. #-> sub CPAN::Distribution::color_cmd_tmps ;
  3492. sub color_cmd_tmps {
  3493. my($self) = shift;
  3494. my($depth) = shift || 0;
  3495. my($color) = shift || 0;
  3496. my($ancestors) = shift || [];
  3497. # a distribution needs to recurse into its prereq_pms
  3498. return if exists $self->{incommandcolor}
  3499. && $self->{incommandcolor}==$color;
  3500. if ($depth>=100){
  3501. $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
  3502. }
  3503. # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
  3504. my $prereq_pm = $self->prereq_pm;
  3505. if (defined $prereq_pm) {
  3506. for my $pre (keys %$prereq_pm) {
  3507. my $premo = CPAN::Shell->expand("Module",$pre);
  3508. $premo->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
  3509. }
  3510. }
  3511. if ($color==0) {
  3512. delete $self->{sponsored_mods};
  3513. delete $self->{badtestcnt};
  3514. }
  3515. $self->{incommandcolor} = $color;
  3516. }
  3517. #-> sub CPAN::Distribution::as_string ;
  3518. sub as_string {
  3519. my $self = shift;
  3520. $self->containsmods;
  3521. $self->SUPER::as_string(@_);
  3522. }
  3523. #-> sub CPAN::Distribution::containsmods ;
  3524. sub containsmods {
  3525. my $self = shift;
  3526. return keys %{$self->{CONTAINSMODS}} if exists $self->{CONTAINSMODS};
  3527. my $dist_id = $self->{ID};
  3528. for my $mod ($CPAN::META->all_objects("CPAN::Module")) {
  3529. my $mod_file = $mod->cpan_file or next;
  3530. my $mod_id = $mod->{ID} or next;
  3531. # warn "mod_file[$mod_file] dist_id[$dist_id] mod_id[$mod_id]";
  3532. # sleep 1;
  3533. $self->{CONTAINSMODS}{$mod_id} = undef if $mod_file eq $dist_id;
  3534. }
  3535. keys %{$self->{CONTAINSMODS}};
  3536. }
  3537. #-> sub CPAN::Distribution::uptodate ;
  3538. sub uptodate {
  3539. my($self) = @_;
  3540. my $c;
  3541. foreach $c ($self->containsmods) {
  3542. my $obj = CPAN::Shell->expandany($c);
  3543. return 0 unless $obj->uptodate;
  3544. }
  3545. return 1;
  3546. }
  3547. #-> sub CPAN::Distribution::called_for ;
  3548. sub called_for {
  3549. my($self,$id) = @_;
  3550. $self->{CALLED_FOR} = $id if defined $id;
  3551. return $self->{CALLED_FOR};
  3552. }
  3553. #-> sub CPAN::Distribution::safe_chdir ;
  3554. sub safe_chdir {
  3555. my($self,$todir) = @_;
  3556. # we die if we cannot chdir and we are debuggable
  3557. Carp::confess("safe_chdir called without todir argument")
  3558. unless defined $todir and length $todir;
  3559. if (chdir $todir) {
  3560. $self->debug(sprintf "changed directory to %s", CPAN::anycwd())
  3561. if $CPAN::DEBUG;
  3562. } else {
  3563. my $cwd = CPAN::anycwd();
  3564. $CPAN::Frontend->mydie(qq{Could not chdir from cwd[$cwd] }.
  3565. qq{to todir[$todir]: $!});
  3566. }
  3567. }
  3568. #-> sub CPAN::Distribution::get ;
  3569. sub get {
  3570. my($self) = @_;
  3571. EXCUSE: {
  3572. my @e;
  3573. exists $self->{'build_dir'} and push @e,
  3574. "Is already unwrapped into directory $self->{'build_dir'}";
  3575. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  3576. }
  3577. my $sub_wd = CPAN::anycwd(); # for cleaning up as good as possible
  3578. #
  3579. # Get the file on local disk
  3580. #
  3581. my($local_file);
  3582. my($local_wanted) =
  3583. File::Spec->catfile(
  3584. $CPAN::Config->{keep_source_where},
  3585. "authors",
  3586. "id",
  3587. split(/\//,$self->id)
  3588. );
  3589. $self->debug("Doing localize") if $CPAN::DEBUG;
  3590. unless ($local_file =
  3591. CPAN::FTP->localize("authors/id/$self->{ID}",
  3592. $local_wanted)) {
  3593. my $note = "";
  3594. if ($CPAN::Index::DATE_OF_02) {
  3595. $note = "Note: Current database in memory was generated ".
  3596. "on $CPAN::Index::DATE_OF_02\n";
  3597. }
  3598. $CPAN::Frontend->mydie("Giving up on '$local_wanted'\n$note");
  3599. }
  3600. $self->debug("local_file[$local_file]") if $CPAN::DEBUG;
  3601. $self->{localfile} = $local_file;
  3602. return if $CPAN::Signal;
  3603. #
  3604. # Check integrity
  3605. #
  3606. if ($CPAN::META->has_inst("Digest::MD5")) {
  3607. $self->debug("Digest::MD5 is installed, verifying");
  3608. $self->verifyMD5;
  3609. } else {
  3610. $self->debug("Digest::MD5 is NOT installed");
  3611. }
  3612. return if $CPAN::Signal;
  3613. #
  3614. # Create a clean room and go there
  3615. #
  3616. $CPAN::META->{cachemgr} ||= CPAN::CacheMgr->new(); # unsafe meta access, ok
  3617. my $builddir = $CPAN::META->{cachemgr}->dir; # unsafe meta access, ok
  3618. $self->safe_chdir($builddir);
  3619. $self->debug("Removing tmp") if $CPAN::DEBUG;
  3620. File::Path::rmtree("tmp");
  3621. mkdir "tmp", 0755 or Carp::croak "Couldn't mkdir tmp: $!";
  3622. if ($CPAN::Signal){
  3623. $self->safe_chdir($sub_wd);
  3624. return;
  3625. }
  3626. $self->safe_chdir("tmp");
  3627. #
  3628. # Unpack the goods
  3629. #
  3630. if ($local_file =~ /(\.tar\.(gz|Z)|\.tgz)(?!\n)\Z/i){
  3631. $self->{was_uncompressed}++ unless CPAN::Tarzip->gtest($local_file);
  3632. $self->untar_me($local_file);
  3633. } elsif ( $local_file =~ /\.zip(?!\n)\Z/i ) {
  3634. $self->unzip_me($local_file);
  3635. } elsif ( $local_file =~ /\.pm\.(gz|Z)(?!\n)\Z/) {
  3636. $self->{was_uncompressed}++ unless CPAN::Tarzip->gtest($local_file);
  3637. $self->pm2dir_me($local_file);
  3638. } else {
  3639. $self->{archived} = "NO";
  3640. $self->safe_chdir($sub_wd);
  3641. return;
  3642. }
  3643. # we are still in the tmp directory!
  3644. # Let's check if the package has its own directory.
  3645. my $dh = DirHandle->new(File::Spec->curdir)
  3646. or Carp::croak("Couldn't opendir .: $!");
  3647. my @readdir = grep $_ !~ /^\.\.?(?!\n)\Z/s, $dh->read; ### MAC??
  3648. $dh->close;
  3649. my ($distdir,$packagedir);
  3650. if (@readdir == 1 && -d $readdir[0]) {
  3651. $distdir = $readdir[0];
  3652. $packagedir = File::Spec->catdir($builddir,$distdir);
  3653. $self->debug("packagedir[$packagedir]builddir[$builddir]distdir[$distdir]")
  3654. if $CPAN::DEBUG;
  3655. -d $packagedir and $CPAN::Frontend->myprint("Removing previously used ".
  3656. "$packagedir\n");
  3657. File::Path::rmtree($packagedir);
  3658. rename($distdir,$packagedir) or
  3659. Carp::confess("Couldn't rename $distdir to $packagedir: $!");
  3660. $self->debug(sprintf("renamed distdir[%s] to packagedir[%s] -e[%s]-d[%s]",
  3661. $distdir,
  3662. $packagedir,
  3663. -e $packagedir,
  3664. -d $packagedir,
  3665. )) if $CPAN::DEBUG;
  3666. } else {
  3667. my $userid = $self->cpan_userid;
  3668. unless ($userid) {
  3669. CPAN->debug("no userid? self[$self]");
  3670. $userid = "anon";
  3671. }
  3672. my $pragmatic_dir = $userid . '000';
  3673. $pragmatic_dir =~ s/\W_//g;
  3674. $pragmatic_dir++ while -d "../$pragmatic_dir";
  3675. $packagedir = File::Spec->catdir($builddir,$pragmatic_dir);
  3676. $self->debug("packagedir[$packagedir]") if $CPAN::DEBUG;
  3677. File::Path::mkpath($packagedir);
  3678. my($f);
  3679. for $f (@readdir) { # is already without "." and ".."
  3680. my $to = File::Spec->catdir($packagedir,$f);
  3681. rename($f,$to) or Carp::confess("Couldn't rename $f to $to: $!");
  3682. }
  3683. }
  3684. if ($CPAN::Signal){
  3685. $self->safe_chdir($sub_wd);
  3686. return;
  3687. }
  3688. $self->{'build_dir'} = $packagedir;
  3689. $self->safe_chdir($builddir);
  3690. File::Path::rmtree("tmp");
  3691. my($mpl) = File::Spec->catfile($packagedir,"Makefile.PL");
  3692. my($mpl_exists) = -f $mpl;
  3693. unless ($mpl_exists) {
  3694. # NFS has been reported to have racing problems after the
  3695. # renaming of a directory in some environments.
  3696. # This trick helps.
  3697. sleep 1;
  3698. my $mpldh = DirHandle->new($packagedir)
  3699. or Carp::croak("Couldn't opendir $packagedir: $!");
  3700. $mpl_exists = grep /^Makefile\.PL$/, $mpldh->read;
  3701. $mpldh->close;
  3702. }
  3703. unless ($mpl_exists) {
  3704. $self->debug(sprintf("makefilepl[%s]anycwd[%s]",
  3705. $mpl,
  3706. CPAN::anycwd(),
  3707. )) if $CPAN::DEBUG;
  3708. my($configure) = File::Spec->catfile($packagedir,"Configure");
  3709. if (-f $configure) {
  3710. # do we have anything to do?
  3711. $self->{'configure'} = $configure;
  3712. } elsif (-f File::Spec->catfile($packagedir,"Makefile")) {
  3713. $CPAN::Frontend->myprint(qq{
  3714. Package comes with a Makefile and without a Makefile.PL.
  3715. We\'ll try to build it with that Makefile then.
  3716. });
  3717. $self->{writemakefile} = "YES";
  3718. sleep 2;
  3719. } else {
  3720. my $cf = $self->called_for || "unknown";
  3721. if ($cf =~ m|/|) {
  3722. $cf =~ s|.*/||;
  3723. $cf =~ s|\W.*||;
  3724. }
  3725. $cf =~ s|[/\\:]||g; # risk of filesystem damage
  3726. $cf = "unknown" unless length($cf);
  3727. $CPAN::Frontend->myprint(qq{Package seems to come without Makefile.PL.
  3728. (The test -f "$mpl" returned false.)
  3729. Writing one on our own (setting NAME to $cf)\a\n});
  3730. $self->{had_no_makefile_pl}++;
  3731. sleep 3;
  3732. # Writing our own Makefile.PL
  3733. my $fh = FileHandle->new;
  3734. $fh->open(">$mpl")
  3735. or Carp::croak("Could not open >$mpl: $!");
  3736. $fh->print(
  3737. qq{# This Makefile.PL has been autogenerated by the module CPAN.pm
  3738. # because there was no Makefile.PL supplied.
  3739. # Autogenerated on: }.scalar localtime().qq{
  3740. use ExtUtils::MakeMaker;
  3741. WriteMakefile(NAME => q[$cf]);
  3742. });
  3743. $fh->close;
  3744. }
  3745. }
  3746. return $self;
  3747. }
  3748. # CPAN::Distribution::untar_me ;
  3749. sub untar_me {
  3750. my($self,$local_file) = @_;
  3751. $self->{archived} = "tar";
  3752. if (CPAN::Tarzip->untar($local_file)) {
  3753. $self->{unwrapped} = "YES";
  3754. } else {
  3755. $self->{unwrapped} = "NO";
  3756. }
  3757. }
  3758. # CPAN::Distribution::unzip_me ;
  3759. sub unzip_me {
  3760. my($self,$local_file) = @_;
  3761. $self->{archived} = "zip";
  3762. if (CPAN::Tarzip->unzip($local_file)) {
  3763. $self->{unwrapped} = "YES";
  3764. } else {
  3765. $self->{unwrapped} = "NO";
  3766. }
  3767. return;
  3768. }
  3769. sub pm2dir_me {
  3770. my($self,$local_file) = @_;
  3771. $self->{archived} = "pm";
  3772. my $to = File::Basename::basename($local_file);
  3773. $to =~ s/\.(gz|Z)(?!\n)\Z//;
  3774. if (CPAN::Tarzip->gunzip($local_file,$to)) {
  3775. $self->{unwrapped} = "YES";
  3776. } else {
  3777. $self->{unwrapped} = "NO";
  3778. }
  3779. }
  3780. #-> sub CPAN::Distribution::new ;
  3781. sub new {
  3782. my($class,%att) = @_;
  3783. # $CPAN::META->{cachemgr} ||= CPAN::CacheMgr->new();
  3784. my $this = { %att };
  3785. return bless $this, $class;
  3786. }
  3787. #-> sub CPAN::Distribution::look ;
  3788. sub look {
  3789. my($self) = @_;
  3790. if ($^O eq 'MacOS') {
  3791. $self->Mac::BuildTools::look;
  3792. return;
  3793. }
  3794. if ( $CPAN::Config->{'shell'} ) {
  3795. $CPAN::Frontend->myprint(qq{
  3796. Trying to open a subshell in the build directory...
  3797. });
  3798. } else {
  3799. $CPAN::Frontend->myprint(qq{
  3800. Your configuration does not define a value for subshells.
  3801. Please define it with "o conf shell <your shell>"
  3802. });
  3803. return;
  3804. }
  3805. my $dist = $self->id;
  3806. my $dir;
  3807. unless ($dir = $self->dir) {
  3808. $self->get;
  3809. }
  3810. unless ($dir ||= $self->dir) {
  3811. $CPAN::Frontend->mywarn(qq{
  3812. Could not determine which directory to use for looking at $dist.
  3813. });
  3814. return;
  3815. }
  3816. my $pwd = CPAN::anycwd();
  3817. $self->safe_chdir($dir);
  3818. $CPAN::Frontend->myprint(qq{Working directory is $dir\n});
  3819. unless (system($CPAN::Config->{'shell'}) == 0) {
  3820. my $code = $? >> 8;
  3821. $CPAN::Frontend->mywarn("Subprocess shell exit code $code\n");
  3822. }
  3823. $self->safe_chdir($pwd);
  3824. }
  3825. # CPAN::Distribution::cvs_import ;
  3826. sub cvs_import {
  3827. my($self) = @_;
  3828. $self->get;
  3829. my $dir = $self->dir;
  3830. my $package = $self->called_for;
  3831. my $module = $CPAN::META->instance('CPAN::Module', $package);
  3832. my $version = $module->cpan_version;
  3833. my $userid = $self->cpan_userid;
  3834. my $cvs_dir = (split /\//, $dir)[-1];
  3835. $cvs_dir =~ s/-\d+[^-]+(?!\n)\Z//;
  3836. my $cvs_root =
  3837. $CPAN::Config->{cvsroot} || $ENV{CVSROOT};
  3838. my $cvs_site_perl =
  3839. $CPAN::Config->{cvs_site_perl} || $ENV{CVS_SITE_PERL};
  3840. if ($cvs_site_perl) {
  3841. $cvs_dir = "$cvs_site_perl/$cvs_dir";
  3842. }
  3843. my $cvs_log = qq{"imported $package $version sources"};
  3844. $version =~ s/\./_/g;
  3845. my @cmd = ('cvs', '-d', $cvs_root, 'import', '-m', $cvs_log,
  3846. "$cvs_dir", $userid, "v$version");
  3847. my $pwd = CPAN::anycwd();
  3848. chdir($dir) or $CPAN::Frontend->mydie(qq{Could not chdir to "$dir": $!});
  3849. $CPAN::Frontend->myprint(qq{Working directory is $dir\n});
  3850. $CPAN::Frontend->myprint(qq{@cmd\n});
  3851. system(@cmd) == 0 or
  3852. $CPAN::Frontend->mydie("cvs import failed");
  3853. chdir($pwd) or $CPAN::Frontend->mydie(qq{Could not chdir to "$pwd": $!});
  3854. }
  3855. #-> sub CPAN::Distribution::readme ;
  3856. sub readme {
  3857. my($self) = @_;
  3858. my($dist) = $self->id;
  3859. my($sans,$suffix) = $dist =~ /(.+)\.(tgz|tar[\._-]gz|tar\.Z|zip)$/;
  3860. $self->debug("sans[$sans] suffix[$suffix]\n") if $CPAN::DEBUG;
  3861. my($local_file);
  3862. my($local_wanted) =
  3863. File::Spec->catfile(
  3864. $CPAN::Config->{keep_source_where},
  3865. "authors",
  3866. "id",
  3867. split(/\//,"$sans.readme"),
  3868. );
  3869. $self->debug("Doing localize") if $CPAN::DEBUG;
  3870. $local_file = CPAN::FTP->localize("authors/id/$sans.readme",
  3871. $local_wanted)
  3872. or $CPAN::Frontend->mydie(qq{No $sans.readme found});;
  3873. if ($^O eq 'MacOS') {
  3874. Mac::BuildTools::launch_file($local_file);
  3875. return;
  3876. }
  3877. my $fh_pager = FileHandle->new;
  3878. local($SIG{PIPE}) = "IGNORE";
  3879. $fh_pager->open("|$CPAN::Config->{'pager'}")
  3880. or die "Could not open pager $CPAN::Config->{'pager'}: $!";
  3881. my $fh_readme = FileHandle->new;
  3882. $fh_readme->open($local_file)
  3883. or $CPAN::Frontend->mydie(qq{Could not open "$local_file": $!});
  3884. $CPAN::Frontend->myprint(qq{
  3885. Displaying file
  3886. $local_file
  3887. with pager "$CPAN::Config->{'pager'}"
  3888. });
  3889. sleep 2;
  3890. $fh_pager->print(<$fh_readme>);
  3891. }
  3892. #-> sub CPAN::Distribution::verifyMD5 ;
  3893. sub verifyMD5 {
  3894. my($self) = @_;
  3895. EXCUSE: {
  3896. my @e;
  3897. $self->{MD5_STATUS} ||= "";
  3898. $self->{MD5_STATUS} eq "OK" and push @e, "MD5 Checksum was ok";
  3899. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  3900. }
  3901. my($lc_want,$lc_file,@local,$basename);
  3902. @local = split(/\//,$self->id);
  3903. pop @local;
  3904. push @local, "CHECKSUMS";
  3905. $lc_want =
  3906. File::Spec->catfile($CPAN::Config->{keep_source_where},
  3907. "authors", "id", @local);
  3908. local($") = "/";
  3909. if (
  3910. -s $lc_want
  3911. &&
  3912. $self->MD5_check_file($lc_want)
  3913. ) {
  3914. return $self->{MD5_STATUS} = "OK";
  3915. }
  3916. $lc_file = CPAN::FTP->localize("authors/id/@local",
  3917. $lc_want,1);
  3918. unless ($lc_file) {
  3919. $CPAN::Frontend->myprint("Trying $lc_want.gz\n");
  3920. $local[-1] .= ".gz";
  3921. $lc_file = CPAN::FTP->localize("authors/id/@local",
  3922. "$lc_want.gz",1);
  3923. if ($lc_file) {
  3924. $lc_file =~ s/\.gz(?!\n)\Z//;
  3925. CPAN::Tarzip->gunzip("$lc_file.gz",$lc_file);
  3926. } else {
  3927. return;
  3928. }
  3929. }
  3930. $self->MD5_check_file($lc_file);
  3931. }
  3932. #-> sub CPAN::Distribution::MD5_check_file ;
  3933. sub MD5_check_file {
  3934. my($self,$chk_file) = @_;
  3935. my($cksum,$file,$basename);
  3936. $file = $self->{localfile};
  3937. $basename = File::Basename::basename($file);
  3938. my $fh = FileHandle->new;
  3939. if (open $fh, $chk_file){
  3940. local($/);
  3941. my $eval = <$fh>;
  3942. $eval =~ s/\015?\012/\n/g;
  3943. close $fh;
  3944. my($comp) = Safe->new();
  3945. $cksum = $comp->reval($eval);
  3946. if ($@) {
  3947. rename $chk_file, "$chk_file.bad";
  3948. Carp::confess($@) if $@;
  3949. }
  3950. } else {
  3951. Carp::carp "Could not open $chk_file for reading";
  3952. }
  3953. if (exists $cksum->{$basename}{md5}) {
  3954. $self->debug("Found checksum for $basename:" .
  3955. "$cksum->{$basename}{md5}\n") if $CPAN::DEBUG;
  3956. open($fh, $file);
  3957. binmode $fh;
  3958. my $eq = $self->eq_MD5($fh,$cksum->{$basename}{'md5'});
  3959. $fh->close;
  3960. $fh = CPAN::Tarzip->TIEHANDLE($file);
  3961. unless ($eq) {
  3962. # had to inline it, when I tied it, the tiedness got lost on
  3963. # the call to eq_MD5. (Jan 1998)
  3964. my $md5 = Digest::MD5->new;
  3965. my($data,$ref);
  3966. $ref = \$data;
  3967. while ($fh->READ($ref, 4096) > 0){
  3968. $md5->add($data);
  3969. }
  3970. my $hexdigest = $md5->hexdigest;
  3971. $eq += $hexdigest eq $cksum->{$basename}{'md5-ungz'};
  3972. }
  3973. if ($eq) {
  3974. $CPAN::Frontend->myprint("Checksum for $file ok\n");
  3975. return $self->{MD5_STATUS} = "OK";
  3976. } else {
  3977. $CPAN::Frontend->myprint(qq{\nChecksum mismatch for }.
  3978. qq{distribution file. }.
  3979. qq{Please investigate.\n\n}.
  3980. $self->as_string,
  3981. $CPAN::META->instance(
  3982. 'CPAN::Author',
  3983. $self->cpan_userid
  3984. )->as_string);
  3985. my $wrap = qq{I\'d recommend removing $file. Its MD5
  3986. checksum is incorrect. Maybe you have configured your 'urllist' with
  3987. a bad URL. Please check this array with 'o conf urllist', and
  3988. retry.};
  3989. $CPAN::Frontend->mydie(Text::Wrap::wrap("","",$wrap));
  3990. # former versions just returned here but this seems a
  3991. # serious threat that deserves a die
  3992. # $CPAN::Frontend->myprint("\n\n");
  3993. # sleep 3;
  3994. # return;
  3995. }
  3996. # close $fh if fileno($fh);
  3997. } else {
  3998. $self->{MD5_STATUS} ||= "";
  3999. if ($self->{MD5_STATUS} eq "NIL") {
  4000. $CPAN::Frontend->mywarn(qq{
  4001. Warning: No md5 checksum for $basename in $chk_file.
  4002. The cause for this may be that the file is very new and the checksum
  4003. has not yet been calculated, but it may also be that something is
  4004. going awry right now.
  4005. });
  4006. my $answer = ExtUtils::MakeMaker::prompt("Proceed?", "yes");
  4007. $answer =~ /^\s*y/i or $CPAN::Frontend->mydie("Aborted.");
  4008. }
  4009. $self->{MD5_STATUS} = "NIL";
  4010. return;
  4011. }
  4012. }
  4013. #-> sub CPAN::Distribution::eq_MD5 ;
  4014. sub eq_MD5 {
  4015. my($self,$fh,$expectMD5) = @_;
  4016. my $md5 = Digest::MD5->new;
  4017. my($data);
  4018. while (read($fh, $data, 4096)){
  4019. $md5->add($data);
  4020. }
  4021. # $md5->addfile($fh);
  4022. my $hexdigest = $md5->hexdigest;
  4023. # warn "fh[$fh] hex[$hexdigest] aexp[$expectMD5]";
  4024. $hexdigest eq $expectMD5;
  4025. }
  4026. #-> sub CPAN::Distribution::force ;
  4027. # Both modules and distributions know if "force" is in effect by
  4028. # autoinspection, not by inspecting a global variable. One of the
  4029. # reason why this was chosen to work that way was the treatment of
  4030. # dependencies. They should not autpomatically inherit the force
  4031. # status. But this has the downside that ^C and die() will return to
  4032. # the prompt but will not be able to reset the force_update
  4033. # attributes. We try to correct for it currently in the read_metadata
  4034. # routine, and immediately before we check for a Signal. I hope this
  4035. # works out in one of v1.57_53ff
  4036. sub force {
  4037. my($self, $method) = @_;
  4038. for my $att (qw(
  4039. MD5_STATUS archived build_dir localfile make install unwrapped
  4040. writemakefile
  4041. )) {
  4042. delete $self->{$att};
  4043. }
  4044. if ($method && $method eq "install") {
  4045. $self->{"force_update"}++; # name should probably have been force_install
  4046. }
  4047. }
  4048. #-> sub CPAN::Distribution::unforce ;
  4049. sub unforce {
  4050. my($self) = @_;
  4051. delete $self->{'force_update'};
  4052. }
  4053. #-> sub CPAN::Distribution::isa_perl ;
  4054. sub isa_perl {
  4055. my($self) = @_;
  4056. my $file = File::Basename::basename($self->id);
  4057. if ($file =~ m{ ^ perl
  4058. -?
  4059. (5)
  4060. ([._-])
  4061. (
  4062. \d{3}(_[0-4][0-9])?
  4063. |
  4064. \d*[24680]\.\d+
  4065. )
  4066. \.tar[._-]gz
  4067. (?!\n)\Z
  4068. }xs){
  4069. return "$1.$3";
  4070. } elsif ($self->cpan_comment
  4071. &&
  4072. $self->cpan_comment =~ /isa_perl\(.+?\)/){
  4073. return $1;
  4074. }
  4075. }
  4076. #-> sub CPAN::Distribution::perl ;
  4077. sub perl {
  4078. my($self) = @_;
  4079. my($perl) = File::Spec->file_name_is_absolute($^X) ? $^X : "";
  4080. my $pwd = CPAN::anycwd();
  4081. my $candidate = File::Spec->catfile($pwd,$^X);
  4082. $perl ||= $candidate if MM->maybe_command($candidate);
  4083. unless ($perl) {
  4084. my ($component,$perl_name);
  4085. DIST_PERLNAME: foreach $perl_name ($^X, 'perl', 'perl5', "perl$]") {
  4086. PATH_COMPONENT: foreach $component (File::Spec->path(),
  4087. $Config::Config{'binexp'}) {
  4088. next unless defined($component) && $component;
  4089. my($abs) = File::Spec->catfile($component,$perl_name);
  4090. if (MM->maybe_command($abs)) {
  4091. $perl = $abs;
  4092. last DIST_PERLNAME;
  4093. }
  4094. }
  4095. }
  4096. }
  4097. $perl;
  4098. }
  4099. #-> sub CPAN::Distribution::make ;
  4100. sub make {
  4101. my($self) = @_;
  4102. $CPAN::Frontend->myprint(sprintf "Running make for %s\n", $self->id);
  4103. # Emergency brake if they said install Pippi and get newest perl
  4104. if ($self->isa_perl) {
  4105. if (
  4106. $self->called_for ne $self->id &&
  4107. ! $self->{force_update}
  4108. ) {
  4109. # if we die here, we break bundles
  4110. $CPAN::Frontend->mywarn(sprintf qq{
  4111. The most recent version "%s" of the module "%s"
  4112. comes with the current version of perl (%s).
  4113. I\'ll build that only if you ask for something like
  4114. force install %s
  4115. or
  4116. install %s
  4117. },
  4118. $CPAN::META->instance(
  4119. 'CPAN::Module',
  4120. $self->called_for
  4121. )->cpan_version,
  4122. $self->called_for,
  4123. $self->isa_perl,
  4124. $self->called_for,
  4125. $self->id);
  4126. sleep 5; return;
  4127. }
  4128. }
  4129. $self->get;
  4130. EXCUSE: {
  4131. my @e;
  4132. $self->{archived} eq "NO" and push @e,
  4133. "Is neither a tar nor a zip archive.";
  4134. $self->{unwrapped} eq "NO" and push @e,
  4135. "had problems unarchiving. Please build manually";
  4136. exists $self->{writemakefile} &&
  4137. $self->{writemakefile} =~ m/ ^ NO\s* ( .* ) /sx and push @e,
  4138. $1 || "Had some problem writing Makefile";
  4139. defined $self->{'make'} and push @e,
  4140. "Has already been processed within this session";
  4141. exists $self->{later} and length($self->{later}) and
  4142. push @e, $self->{later};
  4143. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  4144. }
  4145. $CPAN::Frontend->myprint("\n CPAN.pm: Going to build ".$self->id."\n\n");
  4146. my $builddir = $self->dir;
  4147. chdir $builddir or Carp::croak("Couldn't chdir $builddir: $!");
  4148. $self->debug("Changed directory to $builddir") if $CPAN::DEBUG;
  4149. if ($^O eq 'MacOS') {
  4150. Mac::BuildTools::make($self);
  4151. return;
  4152. }
  4153. my $system;
  4154. if ($self->{'configure'}) {
  4155. $system = $self->{'configure'};
  4156. } else {
  4157. my($perl) = $self->perl or die "Couldn\'t find executable perl\n";
  4158. my $switch = "";
  4159. # This needs a handler that can be turned on or off:
  4160. # $switch = "-MExtUtils::MakeMaker ".
  4161. # "-Mops=:default,:filesys_read,:filesys_open,require,chdir"
  4162. # if $] > 5.00310;
  4163. $system = "$perl $switch Makefile.PL $CPAN::Config->{makepl_arg}";
  4164. }
  4165. unless (exists $self->{writemakefile}) {
  4166. local($SIG{ALRM}) = sub { die "inactivity_timeout reached\n" };
  4167. my($ret,$pid);
  4168. $@ = "";
  4169. if ($CPAN::Config->{inactivity_timeout}) {
  4170. eval {
  4171. alarm $CPAN::Config->{inactivity_timeout};
  4172. local $SIG{CHLD}; # = sub { wait };
  4173. if (defined($pid = fork)) {
  4174. if ($pid) { #parent
  4175. # wait;
  4176. waitpid $pid, 0;
  4177. } else { #child
  4178. # note, this exec isn't necessary if
  4179. # inactivity_timeout is 0. On the Mac I'd
  4180. # suggest, we set it always to 0.
  4181. exec $system;
  4182. }
  4183. } else {
  4184. $CPAN::Frontend->myprint("Cannot fork: $!");
  4185. return;
  4186. }
  4187. };
  4188. alarm 0;
  4189. if ($@){
  4190. kill 9, $pid;
  4191. waitpid $pid, 0;
  4192. $CPAN::Frontend->myprint($@);
  4193. $self->{writemakefile} = "NO $@";
  4194. $@ = "";
  4195. return;
  4196. }
  4197. } else {
  4198. $ret = system($system);
  4199. if ($ret != 0) {
  4200. $self->{writemakefile} = "NO Makefile.PL returned status $ret";
  4201. return;
  4202. }
  4203. }
  4204. if (-f "Makefile") {
  4205. $self->{writemakefile} = "YES";
  4206. delete $self->{make_clean}; # if cleaned before, enable next
  4207. } else {
  4208. $self->{writemakefile} =
  4209. qq{NO Makefile.PL refused to write a Makefile.};
  4210. # It's probably worth it to record the reason, so let's retry
  4211. # local $/;
  4212. # my $fh = IO::File->new("$system |"); # STDERR? STDIN?
  4213. # $self->{writemakefile} .= <$fh>;
  4214. }
  4215. }
  4216. if ($CPAN::Signal){
  4217. delete $self->{force_update};
  4218. return;
  4219. }
  4220. if (my @prereq = $self->unsat_prereq){
  4221. return 1 if $self->follow_prereqs(@prereq); # signal success to the queuerunner
  4222. }
  4223. $system = join " ", $CPAN::Config->{'make'}, $CPAN::Config->{make_arg};
  4224. if (system($system) == 0) {
  4225. $CPAN::Frontend->myprint(" $system -- OK\n");
  4226. $self->{'make'} = "YES";
  4227. } else {
  4228. $self->{writemakefile} ||= "YES";
  4229. $self->{'make'} = "NO";
  4230. $CPAN::Frontend->myprint(" $system -- NOT OK\n");
  4231. }
  4232. }
  4233. sub follow_prereqs {
  4234. my($self) = shift;
  4235. my(@prereq) = @_;
  4236. my $id = $self->id;
  4237. $CPAN::Frontend->myprint("---- Unsatisfied dependencies detected ".
  4238. "during [$id] -----\n");
  4239. for my $p (@prereq) {
  4240. $CPAN::Frontend->myprint(" $p\n");
  4241. }
  4242. my $follow = 0;
  4243. if ($CPAN::Config->{prerequisites_policy} eq "follow") {
  4244. $follow = 1;
  4245. } elsif ($CPAN::Config->{prerequisites_policy} eq "ask") {
  4246. require ExtUtils::MakeMaker;
  4247. my $answer = ExtUtils::MakeMaker::prompt(
  4248. "Shall I follow them and prepend them to the queue
  4249. of modules we are processing right now?", "yes");
  4250. $follow = $answer =~ /^\s*y/i;
  4251. } else {
  4252. local($") = ", ";
  4253. $CPAN::Frontend->
  4254. myprint(" Ignoring dependencies on modules @prereq\n");
  4255. }
  4256. if ($follow) {
  4257. # color them as dirty
  4258. for my $p (@prereq) {
  4259. # warn "calling color_cmd_tmps(0,1)";
  4260. CPAN::Shell->expandany($p)->color_cmd_tmps(0,1);
  4261. }
  4262. CPAN::Queue->jumpqueue(@prereq,$id); # queue them and requeue yourself
  4263. $self->{later} = "Delayed until after prerequisites";
  4264. return 1; # signal success to the queuerunner
  4265. }
  4266. }
  4267. #-> sub CPAN::Distribution::unsat_prereq ;
  4268. sub unsat_prereq {
  4269. my($self) = @_;
  4270. my $prereq_pm = $self->prereq_pm or return;
  4271. my(@need);
  4272. NEED: while (my($need_module, $need_version) = each %$prereq_pm) {
  4273. my $nmo = $CPAN::META->instance("CPAN::Module",$need_module);
  4274. # we were too demanding:
  4275. next if $nmo->uptodate;
  4276. # if they have not specified a version, we accept any installed one
  4277. if (not defined $need_version or
  4278. $need_version == 0 or
  4279. $need_version eq "undef") {
  4280. next if defined $nmo->inst_file;
  4281. }
  4282. # We only want to install prereqs if either they're not installed
  4283. # or if the installed version is too old. We cannot omit this
  4284. # check, because if 'force' is in effect, nobody else will check.
  4285. {
  4286. local($^W) = 0;
  4287. if (
  4288. defined $nmo->inst_file &&
  4289. ! CPAN::Version->vgt($need_version, $nmo->inst_version)
  4290. ){
  4291. CPAN->debug(sprintf "id[%s]inst_file[%s]inst_version[%s]need_version[%s]",
  4292. $nmo->id,
  4293. $nmo->inst_file,
  4294. $nmo->inst_version,
  4295. CPAN::Version->readable($need_version)
  4296. );
  4297. next NEED;
  4298. }
  4299. }
  4300. if ($self->{sponsored_mods}{$need_module}++){
  4301. # We have already sponsored it and for some reason it's still
  4302. # not available. So we do nothing. Or what should we do?
  4303. # if we push it again, we have a potential infinite loop
  4304. next;
  4305. }
  4306. push @need, $need_module;
  4307. }
  4308. @need;
  4309. }
  4310. #-> sub CPAN::Distribution::prereq_pm ;
  4311. sub prereq_pm {
  4312. my($self) = @_;
  4313. return $self->{prereq_pm} if
  4314. exists $self->{prereq_pm_detected} && $self->{prereq_pm_detected};
  4315. return unless $self->{writemakefile}; # no need to have succeeded
  4316. # but we must have run it
  4317. my $build_dir = $self->{build_dir} or die "Panic: no build_dir?";
  4318. my $makefile = File::Spec->catfile($build_dir,"Makefile");
  4319. my(%p) = ();
  4320. my $fh;
  4321. if (-f $makefile
  4322. and
  4323. $fh = FileHandle->new("<$makefile\0")) {
  4324. local($/) = "\n";
  4325. # A.Speer @p -> %p, where %p is $p{Module::Name}=Required_Version
  4326. while (<$fh>) {
  4327. last if /MakeMaker post_initialize section/;
  4328. my($p) = m{^[\#]
  4329. \s+PREREQ_PM\s+=>\s+(.+)
  4330. }x;
  4331. next unless $p;
  4332. # warn "Found prereq expr[$p]";
  4333. # Regexp modified by A.Speer to remember actual version of file
  4334. # PREREQ_PM hash key wants, then add to
  4335. while ( $p =~ m/(?:\s)([\w\:]+)=>q\[(.*?)\],?/g ){
  4336. # In case a prereq is mentioned twice, complain.
  4337. if ( defined $p{$1} ) {
  4338. warn "Warning: PREREQ_PM mentions $1 more than once, last mention wins";
  4339. }
  4340. $p{$1} = $2;
  4341. }
  4342. last;
  4343. }
  4344. }
  4345. $self->{prereq_pm_detected}++;
  4346. return $self->{prereq_pm} = \%p;
  4347. }
  4348. #-> sub CPAN::Distribution::test ;
  4349. sub test {
  4350. my($self) = @_;
  4351. $self->make;
  4352. if ($CPAN::Signal){
  4353. delete $self->{force_update};
  4354. return;
  4355. }
  4356. $CPAN::Frontend->myprint("Running make test\n");
  4357. if (my @prereq = $self->unsat_prereq){
  4358. return 1 if $self->follow_prereqs(@prereq); # signal success to the queuerunner
  4359. }
  4360. EXCUSE: {
  4361. my @e;
  4362. exists $self->{make} or exists $self->{later} or push @e,
  4363. "Make had some problems, maybe interrupted? Won't test";
  4364. exists $self->{'make'} and
  4365. $self->{'make'} eq 'NO' and
  4366. push @e, "Can't test without successful make";
  4367. exists $self->{build_dir} or push @e, "Has no own directory";
  4368. $self->{badtestcnt} ||= 0;
  4369. $self->{badtestcnt} > 0 and
  4370. push @e, "Won't repeat unsuccessful test during this command";
  4371. exists $self->{later} and length($self->{later}) and
  4372. push @e, $self->{later};
  4373. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  4374. }
  4375. chdir $self->{'build_dir'} or
  4376. Carp::croak("Couldn't chdir to $self->{'build_dir'}");
  4377. $self->debug("Changed directory to $self->{'build_dir'}")
  4378. if $CPAN::DEBUG;
  4379. if ($^O eq 'MacOS') {
  4380. Mac::BuildTools::make_test($self);
  4381. return;
  4382. }
  4383. local $ENV{PERL5LIB} = $ENV{PERL5LIB} || "";
  4384. $CPAN::META->set_perl5lib;
  4385. my $system = join " ", $CPAN::Config->{'make'}, "test";
  4386. if (system($system) == 0) {
  4387. $CPAN::Frontend->myprint(" $system -- OK\n");
  4388. $CPAN::META->is_tested($self->{'build_dir'});
  4389. $self->{make_test} = "YES";
  4390. } else {
  4391. $self->{make_test} = "NO";
  4392. $self->{badtestcnt}++;
  4393. $CPAN::Frontend->myprint(" $system -- NOT OK\n");
  4394. }
  4395. }
  4396. #-> sub CPAN::Distribution::clean ;
  4397. sub clean {
  4398. my($self) = @_;
  4399. $CPAN::Frontend->myprint("Running make clean\n");
  4400. EXCUSE: {
  4401. my @e;
  4402. exists $self->{make_clean} and $self->{make_clean} eq "YES" and
  4403. push @e, "make clean already called once";
  4404. exists $self->{build_dir} or push @e, "Has no own directory";
  4405. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  4406. }
  4407. chdir $self->{'build_dir'} or
  4408. Carp::croak("Couldn't chdir to $self->{'build_dir'}");
  4409. $self->debug("Changed directory to $self->{'build_dir'}") if $CPAN::DEBUG;
  4410. if ($^O eq 'MacOS') {
  4411. Mac::BuildTools::make_clean($self);
  4412. return;
  4413. }
  4414. my $system = join " ", $CPAN::Config->{'make'}, "clean";
  4415. if (system($system) == 0) {
  4416. $CPAN::Frontend->myprint(" $system -- OK\n");
  4417. # $self->force;
  4418. # Jost Krieger pointed out that this "force" was wrong because
  4419. # it has the effect that the next "install" on this distribution
  4420. # will untar everything again. Instead we should bring the
  4421. # object's state back to where it is after untarring.
  4422. delete $self->{force_update};
  4423. delete $self->{install};
  4424. delete $self->{writemakefile};
  4425. delete $self->{make};
  4426. delete $self->{make_test}; # no matter if yes or no, tests must be redone
  4427. $self->{make_clean} = "YES";
  4428. } else {
  4429. # Hmmm, what to do if make clean failed?
  4430. $CPAN::Frontend->myprint(qq{ $system -- NOT OK
  4431. make clean did not succeed, marking directory as unusable for further work.
  4432. });
  4433. $self->force("make"); # so that this directory won't be used again
  4434. }
  4435. }
  4436. #-> sub CPAN::Distribution::install ;
  4437. sub install {
  4438. my($self) = @_;
  4439. $self->test;
  4440. if ($CPAN::Signal){
  4441. delete $self->{force_update};
  4442. return;
  4443. }
  4444. $CPAN::Frontend->myprint("Running make install\n");
  4445. EXCUSE: {
  4446. my @e;
  4447. exists $self->{build_dir} or push @e, "Has no own directory";
  4448. exists $self->{make} or exists $self->{later} or push @e,
  4449. "Make had some problems, maybe interrupted? Won't install";
  4450. exists $self->{'make'} and
  4451. $self->{'make'} eq 'NO' and
  4452. push @e, "make had returned bad status, install seems impossible";
  4453. push @e, "make test had returned bad status, ".
  4454. "won't install without force"
  4455. if exists $self->{'make_test'} and
  4456. $self->{'make_test'} eq 'NO' and
  4457. ! $self->{'force_update'};
  4458. exists $self->{'install'} and push @e,
  4459. $self->{'install'} eq "YES" ?
  4460. "Already done" : "Already tried without success";
  4461. exists $self->{later} and length($self->{later}) and
  4462. push @e, $self->{later};
  4463. $CPAN::Frontend->myprint(join "", map {" $_\n"} @e) and return if @e;
  4464. }
  4465. chdir $self->{'build_dir'} or
  4466. Carp::croak("Couldn't chdir to $self->{'build_dir'}");
  4467. $self->debug("Changed directory to $self->{'build_dir'}")
  4468. if $CPAN::DEBUG;
  4469. if ($^O eq 'MacOS') {
  4470. Mac::BuildTools::make_install($self);
  4471. return;
  4472. }
  4473. my $system = join(" ", $CPAN::Config->{'make'},
  4474. "install", $CPAN::Config->{make_install_arg});
  4475. my($stderr) = $^O =~ /Win/i ? "" : " 2>&1 ";
  4476. my($pipe) = FileHandle->new("$system $stderr |");
  4477. my($makeout) = "";
  4478. while (<$pipe>){
  4479. $CPAN::Frontend->myprint($_);
  4480. $makeout .= $_;
  4481. }
  4482. $pipe->close;
  4483. if ($?==0) {
  4484. $CPAN::Frontend->myprint(" $system -- OK\n");
  4485. $CPAN::META->is_installed($self->{'build_dir'});
  4486. return $self->{'install'} = "YES";
  4487. } else {
  4488. $self->{'install'} = "NO";
  4489. $CPAN::Frontend->myprint(" $system -- NOT OK\n");
  4490. if ($makeout =~ /permission/s && $> > 0) {
  4491. $CPAN::Frontend->myprint(qq{ You may have to su }.
  4492. qq{to root to install the package\n});
  4493. }
  4494. }
  4495. delete $self->{force_update};
  4496. }
  4497. #-> sub CPAN::Distribution::dir ;
  4498. sub dir {
  4499. shift->{'build_dir'};
  4500. }
  4501. package CPAN::Bundle;
  4502. sub look {
  4503. my $self = shift;
  4504. $CPAN::Frontend->myprint($self->as_string);
  4505. }
  4506. sub undelay {
  4507. my $self = shift;
  4508. delete $self->{later};
  4509. for my $c ( $self->contains ) {
  4510. my $obj = CPAN::Shell->expandany($c) or next;
  4511. $obj->undelay;
  4512. }
  4513. }
  4514. #-> sub CPAN::Bundle::color_cmd_tmps ;
  4515. sub color_cmd_tmps {
  4516. my($self) = shift;
  4517. my($depth) = shift || 0;
  4518. my($color) = shift || 0;
  4519. my($ancestors) = shift || [];
  4520. # a module needs to recurse to its cpan_file, a distribution needs
  4521. # to recurse into its prereq_pms, a bundle needs to recurse into its modules
  4522. return if exists $self->{incommandcolor}
  4523. && $self->{incommandcolor}==$color;
  4524. if ($depth>=100){
  4525. $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
  4526. }
  4527. # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
  4528. for my $c ( $self->contains ) {
  4529. my $obj = CPAN::Shell->expandany($c) or next;
  4530. CPAN->debug("c[$c]obj[$obj]") if $CPAN::DEBUG;
  4531. $obj->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
  4532. }
  4533. if ($color==0) {
  4534. delete $self->{badtestcnt};
  4535. }
  4536. $self->{incommandcolor} = $color;
  4537. }
  4538. #-> sub CPAN::Bundle::as_string ;
  4539. sub as_string {
  4540. my($self) = @_;
  4541. $self->contains;
  4542. # following line must be "=", not "||=" because we have a moving target
  4543. $self->{INST_VERSION} = $self->inst_version;
  4544. return $self->SUPER::as_string;
  4545. }
  4546. #-> sub CPAN::Bundle::contains ;
  4547. sub contains {
  4548. my($self) = @_;
  4549. my($inst_file) = $self->inst_file || "";
  4550. my($id) = $self->id;
  4551. $self->debug("inst_file[$inst_file]id[$id]") if $CPAN::DEBUG;
  4552. unless ($inst_file) {
  4553. # Try to get at it in the cpan directory
  4554. $self->debug("no inst_file") if $CPAN::DEBUG;
  4555. my $cpan_file;
  4556. $CPAN::Frontend->mydie("I don't know a bundle with ID $id\n") unless
  4557. $cpan_file = $self->cpan_file;
  4558. if ($cpan_file eq "N/A") {
  4559. $CPAN::Frontend->mydie("Bundle $id not found on disk and not on CPAN.
  4560. Maybe stale symlink? Maybe removed during session? Giving up.\n");
  4561. }
  4562. my $dist = $CPAN::META->instance('CPAN::Distribution',
  4563. $self->cpan_file);
  4564. $dist->get;
  4565. $self->debug($dist->as_string) if $CPAN::DEBUG;
  4566. my($todir) = $CPAN::Config->{'cpan_home'};
  4567. my(@me,$from,$to,$me);
  4568. @me = split /::/, $self->id;
  4569. $me[-1] .= ".pm";
  4570. $me = File::Spec->catfile(@me);
  4571. $from = $self->find_bundle_file($dist->{'build_dir'},$me);
  4572. $to = File::Spec->catfile($todir,$me);
  4573. File::Path::mkpath(File::Basename::dirname($to));
  4574. File::Copy::copy($from, $to)
  4575. or Carp::confess("Couldn't copy $from to $to: $!");
  4576. $inst_file = $to;
  4577. }
  4578. my @result;
  4579. my $fh = FileHandle->new;
  4580. local $/ = "\n";
  4581. open($fh,$inst_file) or die "Could not open '$inst_file': $!";
  4582. my $in_cont = 0;
  4583. $self->debug("inst_file[$inst_file]") if $CPAN::DEBUG;
  4584. while (<$fh>) {
  4585. $in_cont = m/^=(?!head1\s+CONTENTS)/ ? 0 :
  4586. m/^=head1\s+CONTENTS/ ? 1 : $in_cont;
  4587. next unless $in_cont;
  4588. next if /^=/;
  4589. s/\#.*//;
  4590. next if /^\s+$/;
  4591. chomp;
  4592. push @result, (split " ", $_, 2)[0];
  4593. }
  4594. close $fh;
  4595. delete $self->{STATUS};
  4596. $self->{CONTAINS} = \@result;
  4597. $self->debug("CONTAINS[@result]") if $CPAN::DEBUG;
  4598. unless (@result) {
  4599. $CPAN::Frontend->mywarn(qq{
  4600. The bundle file "$inst_file" may be a broken
  4601. bundlefile. It seems not to contain any bundle definition.
  4602. Please check the file and if it is bogus, please delete it.
  4603. Sorry for the inconvenience.
  4604. });
  4605. }
  4606. @result;
  4607. }
  4608. #-> sub CPAN::Bundle::find_bundle_file
  4609. sub find_bundle_file {
  4610. my($self,$where,$what) = @_;
  4611. $self->debug("where[$where]what[$what]") if $CPAN::DEBUG;
  4612. ### The following two lines let CPAN.pm become Bundle/CPAN.pm :-(
  4613. ### my $bu = File::Spec->catfile($where,$what);
  4614. ### return $bu if -f $bu;
  4615. my $manifest = File::Spec->catfile($where,"MANIFEST");
  4616. unless (-f $manifest) {
  4617. require ExtUtils::Manifest;
  4618. my $cwd = CPAN::anycwd();
  4619. chdir $where or $CPAN::Frontend->mydie(qq{Could not chdir to "$where": $!});
  4620. ExtUtils::Manifest::mkmanifest();
  4621. chdir $cwd or $CPAN::Frontend->mydie(qq{Could not chdir to "$cwd": $!});
  4622. }
  4623. my $fh = FileHandle->new($manifest)
  4624. or Carp::croak("Couldn't open $manifest: $!");
  4625. local($/) = "\n";
  4626. my $what2 = $what;
  4627. if ($^O eq 'MacOS') {
  4628. $what =~ s/^://;
  4629. $what =~ tr|:|/|;
  4630. $what2 =~ s/:Bundle://;
  4631. $what2 =~ tr|:|/|;
  4632. } else {
  4633. $what2 =~ s|Bundle[/\\]||;
  4634. }
  4635. my $bu;
  4636. while (<$fh>) {
  4637. next if /^\s*\#/;
  4638. my($file) = /(\S+)/;
  4639. if ($file =~ m|\Q$what\E$|) {
  4640. $bu = $file;
  4641. # return File::Spec->catfile($where,$bu); # bad
  4642. last;
  4643. }
  4644. # retry if she managed to
  4645. # have no Bundle directory
  4646. $bu = $file if $file =~ m|\Q$what2\E$|;
  4647. }
  4648. $bu =~ tr|/|:| if $^O eq 'MacOS';
  4649. return File::Spec->catfile($where, $bu) if $bu;
  4650. Carp::croak("Couldn't find a Bundle file in $where");
  4651. }
  4652. # needs to work quite differently from Module::inst_file because of
  4653. # cpan_home/Bundle/ directory and the possibility that we have
  4654. # shadowing effect. As it makes no sense to take the first in @INC for
  4655. # Bundles, we parse them all for $VERSION and take the newest.
  4656. #-> sub CPAN::Bundle::inst_file ;
  4657. sub inst_file {
  4658. my($self) = @_;
  4659. my($inst_file);
  4660. my(@me);
  4661. @me = split /::/, $self->id;
  4662. $me[-1] .= ".pm";
  4663. my($incdir,$bestv);
  4664. foreach $incdir ($CPAN::Config->{'cpan_home'},@INC) {
  4665. my $bfile = File::Spec->catfile($incdir, @me);
  4666. CPAN->debug("bfile[$bfile]") if $CPAN::DEBUG;
  4667. next unless -f $bfile;
  4668. my $foundv = MM->parse_version($bfile);
  4669. if (!$bestv || CPAN::Version->vgt($foundv,$bestv)) {
  4670. $self->{INST_FILE} = $bfile;
  4671. $self->{INST_VERSION} = $bestv = $foundv;
  4672. }
  4673. }
  4674. $self->{INST_FILE};
  4675. }
  4676. #-> sub CPAN::Bundle::inst_version ;
  4677. sub inst_version {
  4678. my($self) = @_;
  4679. $self->inst_file; # finds INST_VERSION as side effect
  4680. $self->{INST_VERSION};
  4681. }
  4682. #-> sub CPAN::Bundle::rematein ;
  4683. sub rematein {
  4684. my($self,$meth) = @_;
  4685. $self->debug("self[$self] meth[$meth]") if $CPAN::DEBUG;
  4686. my($id) = $self->id;
  4687. Carp::croak "Can't $meth $id, don't have an associated bundle file. :-(\n"
  4688. unless $self->inst_file || $self->cpan_file;
  4689. my($s,%fail);
  4690. for $s ($self->contains) {
  4691. my($type) = $s =~ m|/| ? 'CPAN::Distribution' :
  4692. $s =~ m|^Bundle::| ? 'CPAN::Bundle' : 'CPAN::Module';
  4693. if ($type eq 'CPAN::Distribution') {
  4694. $CPAN::Frontend->mywarn(qq{
  4695. The Bundle }.$self->id.qq{ contains
  4696. explicitly a file $s.
  4697. });
  4698. sleep 3;
  4699. }
  4700. # possibly noisy action:
  4701. $self->debug("type[$type] s[$s]") if $CPAN::DEBUG;
  4702. my $obj = $CPAN::META->instance($type,$s);
  4703. $obj->$meth();
  4704. if ($obj->isa(CPAN::Bundle)
  4705. &&
  4706. exists $obj->{install_failed}
  4707. &&
  4708. ref($obj->{install_failed}) eq "HASH"
  4709. ) {
  4710. for (keys %{$obj->{install_failed}}) {
  4711. $self->{install_failed}{$_} = undef; # propagate faiure up
  4712. # to me in a
  4713. # recursive call
  4714. $fail{$s} = 1; # the bundle itself may have succeeded but
  4715. # not all children
  4716. }
  4717. } else {
  4718. my $success;
  4719. $success = $obj->can("uptodate") ? $obj->uptodate : 0;
  4720. $success ||= $obj->{'install'} && $obj->{'install'} eq "YES";
  4721. if ($success) {
  4722. delete $self->{install_failed}{$s};
  4723. } else {
  4724. $fail{$s} = 1;
  4725. }
  4726. }
  4727. }
  4728. # recap with less noise
  4729. if ( $meth eq "install" ) {
  4730. if (%fail) {
  4731. require Text::Wrap;
  4732. my $raw = sprintf(qq{Bundle summary:
  4733. The following items in bundle %s had installation problems:},
  4734. $self->id
  4735. );
  4736. $CPAN::Frontend->myprint(Text::Wrap::fill("","",$raw));
  4737. $CPAN::Frontend->myprint("\n");
  4738. my $paragraph = "";
  4739. my %reported;
  4740. for $s ($self->contains) {
  4741. if ($fail{$s}){
  4742. $paragraph .= "$s ";
  4743. $self->{install_failed}{$s} = undef;
  4744. $reported{$s} = undef;
  4745. }
  4746. }
  4747. my $report_propagated;
  4748. for $s (sort keys %{$self->{install_failed}}) {
  4749. next if exists $reported{$s};
  4750. $paragraph .= "and the following items had problems
  4751. during recursive bundle calls: " unless $report_propagated++;
  4752. $paragraph .= "$s ";
  4753. }
  4754. $CPAN::Frontend->myprint(Text::Wrap::fill(" "," ",$paragraph));
  4755. $CPAN::Frontend->myprint("\n");
  4756. } else {
  4757. $self->{'install'} = 'YES';
  4758. }
  4759. }
  4760. }
  4761. #sub CPAN::Bundle::xs_file
  4762. sub xs_file {
  4763. # If a bundle contains another that contains an xs_file we have
  4764. # here, we just don't bother I suppose
  4765. return 0;
  4766. }
  4767. #-> sub CPAN::Bundle::force ;
  4768. sub force { shift->rematein('force',@_); }
  4769. #-> sub CPAN::Bundle::get ;
  4770. sub get { shift->rematein('get',@_); }
  4771. #-> sub CPAN::Bundle::make ;
  4772. sub make { shift->rematein('make',@_); }
  4773. #-> sub CPAN::Bundle::test ;
  4774. sub test {
  4775. my $self = shift;
  4776. $self->{badtestcnt} ||= 0;
  4777. $self->rematein('test',@_);
  4778. }
  4779. #-> sub CPAN::Bundle::install ;
  4780. sub install {
  4781. my $self = shift;
  4782. $self->rematein('install',@_);
  4783. }
  4784. #-> sub CPAN::Bundle::clean ;
  4785. sub clean { shift->rematein('clean',@_); }
  4786. #-> sub CPAN::Bundle::uptodate ;
  4787. sub uptodate {
  4788. my($self) = @_;
  4789. return 0 unless $self->SUPER::uptodate; # we mut have the current Bundle def
  4790. my $c;
  4791. foreach $c ($self->contains) {
  4792. my $obj = CPAN::Shell->expandany($c);
  4793. return 0 unless $obj->uptodate;
  4794. }
  4795. return 1;
  4796. }
  4797. #-> sub CPAN::Bundle::readme ;
  4798. sub readme {
  4799. my($self) = @_;
  4800. my($file) = $self->cpan_file or $CPAN::Frontend->myprint(qq{
  4801. No File found for bundle } . $self->id . qq{\n}), return;
  4802. $self->debug("self[$self] file[$file]") if $CPAN::DEBUG;
  4803. $CPAN::META->instance('CPAN::Distribution',$file)->readme;
  4804. }
  4805. package CPAN::Module;
  4806. # Accessors
  4807. # sub CPAN::Module::userid
  4808. sub userid {
  4809. my $self = shift;
  4810. return unless exists $self->{RO}; # should never happen
  4811. return $self->{RO}{userid} || $self->{RO}{CPAN_USERID};
  4812. }
  4813. # sub CPAN::Module::description
  4814. sub description { shift->{RO}{description} }
  4815. sub undelay {
  4816. my $self = shift;
  4817. delete $self->{later};
  4818. if ( my $dist = CPAN::Shell->expand("Distribution", $self->cpan_file) ) {
  4819. $dist->undelay;
  4820. }
  4821. }
  4822. #-> sub CPAN::Module::color_cmd_tmps ;
  4823. sub color_cmd_tmps {
  4824. my($self) = shift;
  4825. my($depth) = shift || 0;
  4826. my($color) = shift || 0;
  4827. my($ancestors) = shift || [];
  4828. # a module needs to recurse to its cpan_file
  4829. return if exists $self->{incommandcolor}
  4830. && $self->{incommandcolor}==$color;
  4831. if ($depth>=100){
  4832. $CPAN::Frontend->mydie(CPAN::Exception::RecursiveDependency->new($ancestors));
  4833. }
  4834. # warn "color_cmd_tmps $depth $color " . $self->id; # sleep 1;
  4835. if ( my $dist = CPAN::Shell->expand("Distribution", $self->cpan_file) ) {
  4836. $dist->color_cmd_tmps($depth+1,$color,[@$ancestors, $self->id]);
  4837. }
  4838. if ($color==0) {
  4839. delete $self->{badtestcnt};
  4840. }
  4841. $self->{incommandcolor} = $color;
  4842. }
  4843. #-> sub CPAN::Module::as_glimpse ;
  4844. sub as_glimpse {
  4845. my($self) = @_;
  4846. my(@m);
  4847. my $class = ref($self);
  4848. $class =~ s/^CPAN:://;
  4849. my $color_on = "";
  4850. my $color_off = "";
  4851. if (
  4852. $CPAN::Shell::COLOR_REGISTERED
  4853. &&
  4854. $CPAN::META->has_inst("Term::ANSIColor")
  4855. &&
  4856. $self->{RO}{description}
  4857. ) {
  4858. $color_on = Term::ANSIColor::color("green");
  4859. $color_off = Term::ANSIColor::color("reset");
  4860. }
  4861. push @m, sprintf("%-15s %s%-15s%s (%s)\n",
  4862. $class,
  4863. $color_on,
  4864. $self->id,
  4865. $color_off,
  4866. $self->cpan_file);
  4867. join "", @m;
  4868. }
  4869. #-> sub CPAN::Module::as_string ;
  4870. sub as_string {
  4871. my($self) = @_;
  4872. my(@m);
  4873. CPAN->debug("$self entering as_string") if $CPAN::DEBUG;
  4874. my $class = ref($self);
  4875. $class =~ s/^CPAN:://;
  4876. local($^W) = 0;
  4877. push @m, $class, " id = $self->{ID}\n";
  4878. my $sprintf = " %-12s %s\n";
  4879. push @m, sprintf($sprintf, 'DESCRIPTION', $self->description)
  4880. if $self->description;
  4881. my $sprintf2 = " %-12s %s (%s)\n";
  4882. my($userid);
  4883. $userid = $self->userid;
  4884. if ( $userid ){
  4885. my $author;
  4886. if ($author = CPAN::Shell->expand('Author',$userid)) {
  4887. my $email = "";
  4888. my $m; # old perls
  4889. if ($m = $author->email) {
  4890. $email = " <$m>";
  4891. }
  4892. push @m, sprintf(
  4893. $sprintf2,
  4894. 'CPAN_USERID',
  4895. $userid,
  4896. $author->fullname . $email
  4897. );
  4898. }
  4899. }
  4900. push @m, sprintf($sprintf, 'CPAN_VERSION', $self->cpan_version)
  4901. if $self->cpan_version;
  4902. push @m, sprintf($sprintf, 'CPAN_FILE', $self->cpan_file)
  4903. if $self->cpan_file;
  4904. my $sprintf3 = " %-12s %1s%1s%1s%1s (%s,%s,%s,%s)\n";
  4905. my(%statd,%stats,%statl,%stati);
  4906. @statd{qw,? i c a b R M S,} = qw,unknown idea
  4907. pre-alpha alpha beta released mature standard,;
  4908. @stats{qw,? m d u n a,} = qw,unknown mailing-list
  4909. developer comp.lang.perl.* none abandoned,;
  4910. @statl{qw,? p c + o h,} = qw,unknown perl C C++ other hybrid,;
  4911. @stati{qw,? f r O h,} = qw,unknown functions
  4912. references+ties object-oriented hybrid,;
  4913. $statd{' '} = 'unknown';
  4914. $stats{' '} = 'unknown';
  4915. $statl{' '} = 'unknown';
  4916. $stati{' '} = 'unknown';
  4917. push @m, sprintf(
  4918. $sprintf3,
  4919. 'DSLI_STATUS',
  4920. $self->{RO}{statd},
  4921. $self->{RO}{stats},
  4922. $self->{RO}{statl},
  4923. $self->{RO}{stati},
  4924. $statd{$self->{RO}{statd}},
  4925. $stats{$self->{RO}{stats}},
  4926. $statl{$self->{RO}{statl}},
  4927. $stati{$self->{RO}{stati}}
  4928. ) if $self->{RO}{statd};
  4929. my $local_file = $self->inst_file;
  4930. unless ($self->{MANPAGE}) {
  4931. if ($local_file) {
  4932. $self->{MANPAGE} = $self->manpage_headline($local_file);
  4933. } else {
  4934. # If we have already untarred it, we should look there
  4935. my $dist = $CPAN::META->instance('CPAN::Distribution',
  4936. $self->cpan_file);
  4937. # warn "dist[$dist]";
  4938. # mff=manifest file; mfh=manifest handle
  4939. my($mff,$mfh);
  4940. if (
  4941. $dist->{build_dir}
  4942. and
  4943. (-f ($mff = File::Spec->catfile($dist->{build_dir}, "MANIFEST")))
  4944. and
  4945. $mfh = FileHandle->new($mff)
  4946. ) {
  4947. CPAN->debug("mff[$mff]") if $CPAN::DEBUG;
  4948. my $lfre = $self->id; # local file RE
  4949. $lfre =~ s/::/./g;
  4950. $lfre .= "\\.pm\$";
  4951. my($lfl); # local file file
  4952. local $/ = "\n";
  4953. my(@mflines) = <$mfh>;
  4954. for (@mflines) {
  4955. s/^\s+//;
  4956. s/\s.*//s;
  4957. }
  4958. while (length($lfre)>5 and !$lfl) {
  4959. ($lfl) = grep /$lfre/, @mflines;
  4960. CPAN->debug("lfl[$lfl]lfre[$lfre]") if $CPAN::DEBUG;
  4961. $lfre =~ s/.+?\.//;
  4962. }
  4963. $lfl =~ s/\s.*//; # remove comments
  4964. $lfl =~ s/\s+//g; # chomp would maybe be too system-specific
  4965. my $lfl_abs = File::Spec->catfile($dist->{build_dir},$lfl);
  4966. # warn "lfl_abs[$lfl_abs]";
  4967. if (-f $lfl_abs) {
  4968. $self->{MANPAGE} = $self->manpage_headline($lfl_abs);
  4969. }
  4970. }
  4971. }
  4972. }
  4973. my($item);
  4974. for $item (qw/MANPAGE/) {
  4975. push @m, sprintf($sprintf, $item, $self->{$item})
  4976. if exists $self->{$item};
  4977. }
  4978. for $item (qw/CONTAINS/) {
  4979. push @m, sprintf($sprintf, $item, join(" ",@{$self->{$item}}))
  4980. if exists $self->{$item} && @{$self->{$item}};
  4981. }
  4982. push @m, sprintf($sprintf, 'INST_FILE',
  4983. $local_file || "(not installed)");
  4984. push @m, sprintf($sprintf, 'INST_VERSION',
  4985. $self->inst_version) if $local_file;
  4986. join "", @m, "\n";
  4987. }
  4988. sub manpage_headline {
  4989. my($self,$local_file) = @_;
  4990. my(@local_file) = $local_file;
  4991. $local_file =~ s/\.pm(?!\n)\Z/.pod/;
  4992. push @local_file, $local_file;
  4993. my(@result,$locf);
  4994. for $locf (@local_file) {
  4995. next unless -f $locf;
  4996. my $fh = FileHandle->new($locf)
  4997. or $Carp::Frontend->mydie("Couldn't open $locf: $!");
  4998. my $inpod = 0;
  4999. local $/ = "\n";
  5000. while (<$fh>) {
  5001. $inpod = m/^=(?!head1\s+NAME\s*$)/ ? 0 :
  5002. m/^=head1\s+NAME\s*$/ ? 1 : $inpod;
  5003. next unless $inpod;
  5004. next if /^=/;
  5005. next if /^\s+$/;
  5006. chomp;
  5007. push @result, $_;
  5008. }
  5009. close $fh;
  5010. last if @result;
  5011. }
  5012. join " ", @result;
  5013. }
  5014. #-> sub CPAN::Module::cpan_file ;
  5015. # Note: also inherited by CPAN::Bundle
  5016. sub cpan_file {
  5017. my $self = shift;
  5018. CPAN->debug(sprintf "id[%s]", $self->id) if $CPAN::DEBUG;
  5019. unless (defined $self->{RO}{CPAN_FILE}) {
  5020. CPAN::Index->reload;
  5021. }
  5022. if (exists $self->{RO}{CPAN_FILE} && defined $self->{RO}{CPAN_FILE}){
  5023. return $self->{RO}{CPAN_FILE};
  5024. } else {
  5025. my $userid = $self->userid;
  5026. if ( $userid ) {
  5027. if ($CPAN::META->exists("CPAN::Author",$userid)) {
  5028. my $author = $CPAN::META->instance("CPAN::Author",
  5029. $userid);
  5030. my $fullname = $author->fullname;
  5031. my $email = $author->email;
  5032. unless (defined $fullname && defined $email) {
  5033. return sprintf("Contact Author %s",
  5034. $userid,
  5035. );
  5036. }
  5037. return "Contact Author $fullname <$email>";
  5038. } else {
  5039. return "Contact Author $userid (Email address not available)";
  5040. }
  5041. } else {
  5042. return "N/A";
  5043. }
  5044. }
  5045. }
  5046. #-> sub CPAN::Module::cpan_version ;
  5047. sub cpan_version {
  5048. my $self = shift;
  5049. $self->{RO}{CPAN_VERSION} = 'undef'
  5050. unless defined $self->{RO}{CPAN_VERSION};
  5051. # I believe this is always a bug in the index and should be reported
  5052. # as such, but usually I find out such an error and do not want to
  5053. # provoke too many bugreports
  5054. $self->{RO}{CPAN_VERSION};
  5055. }
  5056. #-> sub CPAN::Module::force ;
  5057. sub force {
  5058. my($self) = @_;
  5059. $self->{'force_update'}++;
  5060. }
  5061. #-> sub CPAN::Module::rematein ;
  5062. sub rematein {
  5063. my($self,$meth) = @_;
  5064. $CPAN::Frontend->myprint(sprintf("Running %s for module %s\n",
  5065. $meth,
  5066. $self->id));
  5067. my $cpan_file = $self->cpan_file;
  5068. if ($cpan_file eq "N/A" || $cpan_file =~ /^Contact Author/){
  5069. $CPAN::Frontend->mywarn(sprintf qq{
  5070. The module %s isn\'t available on CPAN.
  5071. Either the module has not yet been uploaded to CPAN, or it is
  5072. temporary unavailable. Please contact the author to find out
  5073. more about the status. Try 'i %s'.
  5074. },
  5075. $self->id,
  5076. $self->id,
  5077. );
  5078. return;
  5079. }
  5080. my $pack = $CPAN::META->instance('CPAN::Distribution',$cpan_file);
  5081. $pack->called_for($self->id);
  5082. $pack->force($meth) if exists $self->{'force_update'};
  5083. $pack->$meth();
  5084. $pack->unforce if $pack->can("unforce") && exists $self->{'force_update'};
  5085. delete $self->{'force_update'};
  5086. }
  5087. #-> sub CPAN::Module::readme ;
  5088. sub readme { shift->rematein('readme') }
  5089. #-> sub CPAN::Module::look ;
  5090. sub look { shift->rematein('look') }
  5091. #-> sub CPAN::Module::cvs_import ;
  5092. sub cvs_import { shift->rematein('cvs_import') }
  5093. #-> sub CPAN::Module::get ;
  5094. sub get { shift->rematein('get',@_); }
  5095. #-> sub CPAN::Module::make ;
  5096. sub make {
  5097. my $self = shift;
  5098. $self->rematein('make');
  5099. }
  5100. #-> sub CPAN::Module::test ;
  5101. sub test {
  5102. my $self = shift;
  5103. $self->{badtestcnt} ||= 0;
  5104. $self->rematein('test',@_);
  5105. }
  5106. #-> sub CPAN::Module::uptodate ;
  5107. sub uptodate {
  5108. my($self) = @_;
  5109. my($latest) = $self->cpan_version;
  5110. $latest ||= 0;
  5111. my($inst_file) = $self->inst_file;
  5112. my($have) = 0;
  5113. if (defined $inst_file) {
  5114. $have = $self->inst_version;
  5115. }
  5116. local($^W)=0;
  5117. if ($inst_file
  5118. &&
  5119. ! CPAN::Version->vgt($latest, $have)
  5120. ) {
  5121. CPAN->debug("returning uptodate. inst_file[$inst_file] ".
  5122. "latest[$latest] have[$have]") if $CPAN::DEBUG;
  5123. return 1;
  5124. }
  5125. return;
  5126. }
  5127. #-> sub CPAN::Module::install ;
  5128. sub install {
  5129. my($self) = @_;
  5130. my($doit) = 0;
  5131. if ($self->uptodate
  5132. &&
  5133. not exists $self->{'force_update'}
  5134. ) {
  5135. $CPAN::Frontend->myprint( $self->id. " is up to date.\n");
  5136. } else {
  5137. $doit = 1;
  5138. }
  5139. if ($self->{RO}{stats} && $self->{RO}{stats} eq "a") {
  5140. $CPAN::Frontend->mywarn(qq{
  5141. \n\n\n ***WARNING***
  5142. The module $self->{ID} has no active maintainer.\n\n\n
  5143. });
  5144. sleep 5;
  5145. }
  5146. $self->rematein('install') if $doit;
  5147. }
  5148. #-> sub CPAN::Module::clean ;
  5149. sub clean { shift->rematein('clean') }
  5150. #-> sub CPAN::Module::inst_file ;
  5151. sub inst_file {
  5152. my($self) = @_;
  5153. my($dir,@packpath);
  5154. @packpath = split /::/, $self->{ID};
  5155. $packpath[-1] .= ".pm";
  5156. foreach $dir (@INC) {
  5157. my $pmfile = File::Spec->catfile($dir,@packpath);
  5158. if (-f $pmfile){
  5159. return $pmfile;
  5160. }
  5161. }
  5162. return;
  5163. }
  5164. #-> sub CPAN::Module::xs_file ;
  5165. sub xs_file {
  5166. my($self) = @_;
  5167. my($dir,@packpath);
  5168. @packpath = split /::/, $self->{ID};
  5169. push @packpath, $packpath[-1];
  5170. $packpath[-1] .= "." . $Config::Config{'dlext'};
  5171. foreach $dir (@INC) {
  5172. my $xsfile = File::Spec->catfile($dir,'auto',@packpath);
  5173. if (-f $xsfile){
  5174. return $xsfile;
  5175. }
  5176. }
  5177. return;
  5178. }
  5179. #-> sub CPAN::Module::inst_version ;
  5180. sub inst_version {
  5181. my($self) = @_;
  5182. my $parsefile = $self->inst_file or return;
  5183. local($^W) = 0 if $] < 5.00303 && $ExtUtils::MakeMaker::VERSION < 5.38;
  5184. my $have;
  5185. # there was a bug in 5.6.0 that let lots of unini warnings out of
  5186. # parse_version. Fixed shortly after 5.6.0 by PMQS. We can remove
  5187. # the following workaround after 5.6.1 is out.
  5188. local($SIG{__WARN__}) = sub { my $w = shift;
  5189. return if $w =~ /uninitialized/i;
  5190. warn $w;
  5191. };
  5192. $have = MM->parse_version($parsefile) || "undef";
  5193. $have =~ s/^ //; # since the %vd hack these two lines here are needed
  5194. $have =~ s/ $//; # trailing whitespace happens all the time
  5195. # My thoughts about why %vd processing should happen here
  5196. # Alt1 maintain it as string with leading v:
  5197. # read index files do nothing
  5198. # compare it use utility for compare
  5199. # print it do nothing
  5200. # Alt2 maintain it as what it is
  5201. # read index files convert
  5202. # compare it use utility because there's still a ">" vs "gt" issue
  5203. # print it use CPAN::Version for print
  5204. # Seems cleaner to hold it in memory as a string starting with a "v"
  5205. # If the author of this module made a mistake and wrote a quoted
  5206. # "v1.13" instead of v1.13, we simply leave it at that with the
  5207. # effect that *we* will treat it like a v-tring while the rest of
  5208. # perl won't. Seems sensible when we consider that any action we
  5209. # could take now would just add complexity.
  5210. $have = CPAN::Version->readable($have);
  5211. $have =~ s/\s*//g; # stringify to float around floating point issues
  5212. $have; # no stringify needed, \s* above matches always
  5213. }
  5214. package CPAN::Tarzip;
  5215. # CPAN::Tarzip::gzip
  5216. sub gzip {
  5217. my($class,$read,$write) = @_;
  5218. if ($CPAN::META->has_inst("Compress::Zlib")) {
  5219. my($buffer,$fhw);
  5220. $fhw = FileHandle->new($read)
  5221. or $CPAN::Frontend->mydie("Could not open $read: $!");
  5222. my $gz = Compress::Zlib::gzopen($write, "wb")
  5223. or $CPAN::Frontend->mydie("Cannot gzopen $write: $!\n");
  5224. $gz->gzwrite($buffer)
  5225. while read($fhw,$buffer,4096) > 0 ;
  5226. $gz->gzclose() ;
  5227. $fhw->close;
  5228. return 1;
  5229. } else {
  5230. system("$CPAN::Config->{gzip} -c $read > $write")==0;
  5231. }
  5232. }
  5233. # CPAN::Tarzip::gunzip
  5234. sub gunzip {
  5235. my($class,$read,$write) = @_;
  5236. if ($CPAN::META->has_inst("Compress::Zlib")) {
  5237. my($buffer,$fhw);
  5238. $fhw = FileHandle->new(">$write")
  5239. or $CPAN::Frontend->mydie("Could not open >$write: $!");
  5240. my $gz = Compress::Zlib::gzopen($read, "rb")
  5241. or $CPAN::Frontend->mydie("Cannot gzopen $read: $!\n");
  5242. $fhw->print($buffer)
  5243. while $gz->gzread($buffer) > 0 ;
  5244. $CPAN::Frontend->mydie("Error reading from $read: $!\n")
  5245. if $gz->gzerror != Compress::Zlib::Z_STREAM_END();
  5246. $gz->gzclose() ;
  5247. $fhw->close;
  5248. return 1;
  5249. } else {
  5250. system("$CPAN::Config->{gzip} -dc $read > $write")==0;
  5251. }
  5252. }
  5253. # CPAN::Tarzip::gtest
  5254. sub gtest {
  5255. my($class,$read) = @_;
  5256. # After I had reread the documentation in zlib.h, I discovered that
  5257. # uncompressed files do not lead to an gzerror (anymore?).
  5258. if ( $CPAN::META->has_inst("Compress::Zlib") ) {
  5259. my($buffer,$len);
  5260. $len = 0;
  5261. my $gz = Compress::Zlib::gzopen($read, "rb")
  5262. or $CPAN::Frontend->mydie(sprintf("Cannot gzopen %s: %s\n",
  5263. $read,
  5264. $Compress::Zlib::gzerrno));
  5265. while ($gz->gzread($buffer) > 0 ){
  5266. $len += length($buffer);
  5267. $buffer = "";
  5268. }
  5269. my $err = $gz->gzerror;
  5270. my $success = ! $err || $err == Compress::Zlib::Z_STREAM_END();
  5271. if ($len == -s $read){
  5272. $success = 0;
  5273. CPAN->debug("hit an uncompressed file") if $CPAN::DEBUG;
  5274. }
  5275. $gz->gzclose();
  5276. CPAN->debug("err[$err]success[$success]") if $CPAN::DEBUG;
  5277. return $success;
  5278. } else {
  5279. return system("$CPAN::Config->{gzip} -dt $read")==0;
  5280. }
  5281. }
  5282. # CPAN::Tarzip::TIEHANDLE
  5283. sub TIEHANDLE {
  5284. my($class,$file) = @_;
  5285. my $ret;
  5286. $class->debug("file[$file]");
  5287. if ($CPAN::META->has_inst("Compress::Zlib")) {
  5288. my $gz = Compress::Zlib::gzopen($file,"rb") or
  5289. die "Could not gzopen $file";
  5290. $ret = bless {GZ => $gz}, $class;
  5291. } else {
  5292. my $pipe = "$CPAN::Config->{gzip} --decompress --stdout $file |";
  5293. my $fh = FileHandle->new($pipe) or die "Could not pipe[$pipe]: $!";
  5294. binmode $fh;
  5295. $ret = bless {FH => $fh}, $class;
  5296. }
  5297. $ret;
  5298. }
  5299. # CPAN::Tarzip::READLINE
  5300. sub READLINE {
  5301. my($self) = @_;
  5302. if (exists $self->{GZ}) {
  5303. my $gz = $self->{GZ};
  5304. my($line,$bytesread);
  5305. $bytesread = $gz->gzreadline($line);
  5306. return undef if $bytesread <= 0;
  5307. return $line;
  5308. } else {
  5309. my $fh = $self->{FH};
  5310. return scalar <$fh>;
  5311. }
  5312. }
  5313. # CPAN::Tarzip::READ
  5314. sub READ {
  5315. my($self,$ref,$length,$offset) = @_;
  5316. die "read with offset not implemented" if defined $offset;
  5317. if (exists $self->{GZ}) {
  5318. my $gz = $self->{GZ};
  5319. my $byteread = $gz->gzread($$ref,$length);# 30eaf79e8b446ef52464b5422da328a8
  5320. return $byteread;
  5321. } else {
  5322. my $fh = $self->{FH};
  5323. return read($fh,$$ref,$length);
  5324. }
  5325. }
  5326. # CPAN::Tarzip::DESTROY
  5327. sub DESTROY {
  5328. my($self) = @_;
  5329. if (exists $self->{GZ}) {
  5330. my $gz = $self->{GZ};
  5331. $gz->gzclose() if defined $gz; # hard to say if it is allowed
  5332. # to be undef ever. AK, 2000-09
  5333. } else {
  5334. my $fh = $self->{FH};
  5335. $fh->close if defined $fh;
  5336. }
  5337. undef $self;
  5338. }
  5339. # CPAN::Tarzip::untar
  5340. sub untar {
  5341. my($class,$file) = @_;
  5342. my($prefer) = 0;
  5343. if (0) { # makes changing order easier
  5344. } elsif ($BUGHUNTING){
  5345. $prefer=2;
  5346. } elsif (MM->maybe_command($CPAN::Config->{gzip})
  5347. &&
  5348. MM->maybe_command($CPAN::Config->{'tar'})) {
  5349. # should be default until Archive::Tar is fixed
  5350. $prefer = 1;
  5351. } elsif (
  5352. $CPAN::META->has_inst("Archive::Tar")
  5353. &&
  5354. $CPAN::META->has_inst("Compress::Zlib") ) {
  5355. $prefer = 2;
  5356. } else {
  5357. $CPAN::Frontend->mydie(qq{
  5358. CPAN.pm needs either both external programs tar and gzip installed or
  5359. both the modules Archive::Tar and Compress::Zlib. Neither prerequisite
  5360. is available. Can\'t continue.
  5361. });
  5362. }
  5363. if ($prefer==1) { # 1 => external gzip+tar
  5364. my($system);
  5365. my $is_compressed = $class->gtest($file);
  5366. if ($is_compressed) {
  5367. $system = "$CPAN::Config->{gzip} --decompress --stdout " .
  5368. "< $file | $CPAN::Config->{tar} xvf -";
  5369. } else {
  5370. $system = "$CPAN::Config->{tar} xvf $file";
  5371. }
  5372. if (system($system) != 0) {
  5373. # people find the most curious tar binaries that cannot handle
  5374. # pipes
  5375. if ($is_compressed) {
  5376. (my $ungzf = $file) =~ s/\.gz(?!\n)\Z//;
  5377. if (CPAN::Tarzip->gunzip($file, $ungzf)) {
  5378. $CPAN::Frontend->myprint(qq{Uncompressed $file successfully\n});
  5379. } else {
  5380. $CPAN::Frontend->mydie(qq{Couldn\'t uncompress $file\n});
  5381. }
  5382. $file = $ungzf;
  5383. }
  5384. $system = "$CPAN::Config->{tar} xvf $file";
  5385. $CPAN::Frontend->myprint(qq{Using Tar:$system:\n});
  5386. if (system($system)==0) {
  5387. $CPAN::Frontend->myprint(qq{Untarred $file successfully\n});
  5388. } else {
  5389. $CPAN::Frontend->mydie(qq{Couldn\'t untar $file\n});
  5390. }
  5391. return 1;
  5392. } else {
  5393. return 1;
  5394. }
  5395. } elsif ($prefer==2) { # 2 => modules
  5396. my $tar = Archive::Tar->new($file,1);
  5397. my $af; # archive file
  5398. my @af;
  5399. if ($BUGHUNTING) {
  5400. # RCS 1.337 had this code, it turned out unacceptable slow but
  5401. # it revealed a bug in Archive::Tar. Code is only here to hunt
  5402. # the bug again. It should never be enabled in published code.
  5403. # GDGraph3d-0.53 was an interesting case according to Larry
  5404. # Virden.
  5405. warn(">>>Bughunting code enabled<<< " x 20);
  5406. for $af ($tar->list_files) {
  5407. if ($af =~ m!^(/|\.\./)!) {
  5408. $CPAN::Frontend->mydie("ALERT: Archive contains ".
  5409. "illegal member [$af]");
  5410. }
  5411. $CPAN::Frontend->myprint("$af\n");
  5412. $tar->extract($af); # slow but effective for finding the bug
  5413. return if $CPAN::Signal;
  5414. }
  5415. } else {
  5416. for $af ($tar->list_files) {
  5417. if ($af =~ m!^(/|\.\./)!) {
  5418. $CPAN::Frontend->mydie("ALERT: Archive contains ".
  5419. "illegal member [$af]");
  5420. }
  5421. $CPAN::Frontend->myprint("$af\n");
  5422. push @af, $af;
  5423. return if $CPAN::Signal;
  5424. }
  5425. $tar->extract(@af);
  5426. }
  5427. Mac::BuildTools::convert_files([$tar->list_files], 1)
  5428. if ($^O eq 'MacOS');
  5429. return 1;
  5430. }
  5431. }
  5432. sub unzip {
  5433. my($class,$file) = @_;
  5434. if ($CPAN::META->has_inst("Archive::Zip")) {
  5435. # blueprint of the code from Archive::Zip::Tree::extractTree();
  5436. my $zip = Archive::Zip->new();
  5437. my $status;
  5438. $status = $zip->read($file);
  5439. die "Read of file[$file] failed\n" if $status != Archive::Zip::AZ_OK();
  5440. $CPAN::META->debug("Successfully read file[$file]") if $CPAN::DEBUG;
  5441. my @members = $zip->members();
  5442. for my $member ( @members ) {
  5443. my $af = $member->fileName();
  5444. if ($af =~ m!^(/|\.\./)!) {
  5445. $CPAN::Frontend->mydie("ALERT: Archive contains ".
  5446. "illegal member [$af]");
  5447. }
  5448. my $status = $member->extractToFileNamed( $af );
  5449. $CPAN::META->debug("af[$af]status[$status]") if $CPAN::DEBUG;
  5450. die "Extracting of file[$af] from zipfile[$file] failed\n" if
  5451. $status != Archive::Zip::AZ_OK();
  5452. return if $CPAN::Signal;
  5453. }
  5454. return 1;
  5455. } else {
  5456. my $unzip = $CPAN::Config->{unzip} or
  5457. $CPAN::Frontend->mydie("Cannot unzip, no unzip program available");
  5458. my @system = ($unzip, $file);
  5459. return system(@system) == 0;
  5460. }
  5461. }
  5462. package CPAN::Version;
  5463. # CPAN::Version::vcmp courtesy Jost Krieger
  5464. sub vcmp {
  5465. my($self,$l,$r) = @_;
  5466. local($^W) = 0;
  5467. CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
  5468. return 0 if $l eq $r; # short circuit for quicker success
  5469. if ($l=~/^v/ <=> $r=~/^v/) {
  5470. for ($l,$r) {
  5471. next if /^v/;
  5472. $_ = $self->float2vv($_);
  5473. }
  5474. }
  5475. return
  5476. ($l ne "undef") <=> ($r ne "undef") ||
  5477. ($] >= 5.006 &&
  5478. $l =~ /^v/ &&
  5479. $r =~ /^v/ &&
  5480. $self->vstring($l) cmp $self->vstring($r)) ||
  5481. $l <=> $r ||
  5482. $l cmp $r;
  5483. }
  5484. sub vgt {
  5485. my($self,$l,$r) = @_;
  5486. $self->vcmp($l,$r) > 0;
  5487. }
  5488. sub vstring {
  5489. my($self,$n) = @_;
  5490. $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]";
  5491. pack "U*", split /\./, $n;
  5492. }
  5493. # vv => visible vstring
  5494. sub float2vv {
  5495. my($self,$n) = @_;
  5496. my($rev) = int($n);
  5497. $rev ||= 0;
  5498. my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit
  5499. # architecture influence
  5500. $mantissa ||= 0;
  5501. $mantissa .= "0" while length($mantissa)%3;
  5502. my $ret = "v" . $rev;
  5503. while ($mantissa) {
  5504. $mantissa =~ s/(\d{1,3})// or
  5505. die "Panic: length>0 but not a digit? mantissa[$mantissa]";
  5506. $ret .= ".".int($1);
  5507. }
  5508. # warn "n[$n]ret[$ret]";
  5509. $ret;
  5510. }
  5511. sub readable {
  5512. my($self,$n) = @_;
  5513. $n =~ /^([\w\-\+\.]+)/;
  5514. return $1 if defined $1 && length($1)>0;
  5515. # if the first user reaches version v43, he will be treated as "+".
  5516. # We'll have to decide about a new rule here then, depending on what
  5517. # will be the prevailing versioning behavior then.
  5518. if ($] < 5.006) { # or whenever v-strings were introduced
  5519. # we get them wrong anyway, whatever we do, because 5.005 will
  5520. # have already interpreted 0.2.4 to be "0.24". So even if he
  5521. # indexer sends us something like "v0.2.4" we compare wrongly.
  5522. # And if they say v1.2, then the old perl takes it as "v12"
  5523. $CPAN::Frontend->mywarn("Suspicious version string seen [$n]\n");
  5524. return $n;
  5525. }
  5526. my $better = sprintf "v%vd", $n;
  5527. CPAN->debug("n[$n] better[$better]") if $CPAN::DEBUG;
  5528. return $better;
  5529. }
  5530. package CPAN;
  5531. 1;
  5532. __END__
  5533. =head1 NAME
  5534. CPAN - query, download and build perl modules from CPAN sites
  5535. =head1 SYNOPSIS
  5536. Interactive mode:
  5537. perl -MCPAN -e shell;
  5538. Batch mode:
  5539. use CPAN;
  5540. autobundle, clean, install, make, recompile, test
  5541. =head1 STATUS
  5542. This module will eventually be replaced by CPANPLUS. CPANPLUS is kind
  5543. of a modern rewrite from ground up with greater extensibility and more
  5544. features but no full compatibility. If you're new to CPAN.pm, you
  5545. probably should investigate if CPANPLUS is the better choice for you.
  5546. If you're already used to CPAN.pm you're welcome to continue using it,
  5547. if you accept that its development is mostly (though not completely)
  5548. stalled.
  5549. =head1 DESCRIPTION
  5550. The CPAN module is designed to automate the make and install of perl
  5551. modules and extensions. It includes some primitive searching capabilities and
  5552. knows how to use Net::FTP or LWP (or lynx or an external ftp client)
  5553. to fetch the raw data from the net.
  5554. Modules are fetched from one or more of the mirrored CPAN
  5555. (Comprehensive Perl Archive Network) sites and unpacked in a dedicated
  5556. directory.
  5557. The CPAN module also supports the concept of named and versioned
  5558. I<bundles> of modules. Bundles simplify the handling of sets of
  5559. related modules. See Bundles below.
  5560. The package contains a session manager and a cache manager. There is
  5561. no status retained between sessions. The session manager keeps track
  5562. of what has been fetched, built and installed in the current
  5563. session. The cache manager keeps track of the disk space occupied by
  5564. the make processes and deletes excess space according to a simple FIFO
  5565. mechanism.
  5566. For extended searching capabilities there's a plugin for CPAN available,
  5567. L<C<CPAN::WAIT>|CPAN::WAIT>. C<CPAN::WAIT> is a full-text search engine
  5568. that indexes all documents available in CPAN authors directories. If
  5569. C<CPAN::WAIT> is installed on your system, the interactive shell of
  5570. CPAN.pm will enable the C<wq>, C<wr>, C<wd>, C<wl>, and C<wh> commands
  5571. which send queries to the WAIT server that has been configured for your
  5572. installation.
  5573. All other methods provided are accessible in a programmer style and in an
  5574. interactive shell style.
  5575. =head2 Interactive Mode
  5576. The interactive mode is entered by running
  5577. perl -MCPAN -e shell
  5578. which puts you into a readline interface. You will have the most fun if
  5579. you install Term::ReadKey and Term::ReadLine to enjoy both history and
  5580. command completion.
  5581. Once you are on the command line, type 'h' and the rest should be
  5582. self-explanatory.
  5583. The function call C<shell> takes two optional arguments, one is the
  5584. prompt, the second is the default initial command line (the latter
  5585. only works if a real ReadLine interface module is installed).
  5586. The most common uses of the interactive modes are
  5587. =over 2
  5588. =item Searching for authors, bundles, distribution files and modules
  5589. There are corresponding one-letter commands C<a>, C<b>, C<d>, and C<m>
  5590. for each of the four categories and another, C<i> for any of the
  5591. mentioned four. Each of the four entities is implemented as a class
  5592. with slightly differing methods for displaying an object.
  5593. Arguments you pass to these commands are either strings exactly matching
  5594. the identification string of an object or regular expressions that are
  5595. then matched case-insensitively against various attributes of the
  5596. objects. The parser recognizes a regular expression only if you
  5597. enclose it between two slashes.
  5598. The principle is that the number of found objects influences how an
  5599. item is displayed. If the search finds one item, the result is
  5600. displayed with the rather verbose method C<as_string>, but if we find
  5601. more than one, we display each object with the terse method
  5602. <as_glimpse>.
  5603. =item make, test, install, clean modules or distributions
  5604. These commands take any number of arguments and investigate what is
  5605. necessary to perform the action. If the argument is a distribution
  5606. file name (recognized by embedded slashes), it is processed. If it is
  5607. a module, CPAN determines the distribution file in which this module
  5608. is included and processes that, following any dependencies named in
  5609. the module's Makefile.PL (this behavior is controlled by
  5610. I<prerequisites_policy>.)
  5611. Any C<make> or C<test> are run unconditionally. An
  5612. install <distribution_file>
  5613. also is run unconditionally. But for
  5614. install <module>
  5615. CPAN checks if an install is actually needed for it and prints
  5616. I<module up to date> in the case that the distribution file containing
  5617. the module doesn't need to be updated.
  5618. CPAN also keeps track of what it has done within the current session
  5619. and doesn't try to build a package a second time regardless if it
  5620. succeeded or not. The C<force> command takes as a first argument the
  5621. method to invoke (currently: C<make>, C<test>, or C<install>) and executes the
  5622. command from scratch.
  5623. Example:
  5624. cpan> install OpenGL
  5625. OpenGL is up to date.
  5626. cpan> force install OpenGL
  5627. Running make
  5628. OpenGL-0.4/
  5629. OpenGL-0.4/COPYRIGHT
  5630. [...]
  5631. A C<clean> command results in a
  5632. make clean
  5633. being executed within the distribution file's working directory.
  5634. =item get, readme, look module or distribution
  5635. C<get> downloads a distribution file without further action. C<readme>
  5636. displays the README file of the associated distribution. C<Look> gets
  5637. and untars (if not yet done) the distribution file, changes to the
  5638. appropriate directory and opens a subshell process in that directory.
  5639. =item ls author
  5640. C<ls> lists all distribution files in and below an author's CPAN
  5641. directory. Only those files that contain modules are listed and if
  5642. there is more than one for any given module, only the most recent one
  5643. is listed.
  5644. =item Signals
  5645. CPAN.pm installs signal handlers for SIGINT and SIGTERM. While you are
  5646. in the cpan-shell it is intended that you can press C<^C> anytime and
  5647. return to the cpan-shell prompt. A SIGTERM will cause the cpan-shell
  5648. to clean up and leave the shell loop. You can emulate the effect of a
  5649. SIGTERM by sending two consecutive SIGINTs, which usually means by
  5650. pressing C<^C> twice.
  5651. CPAN.pm ignores a SIGPIPE. If the user sets inactivity_timeout, a
  5652. SIGALRM is used during the run of the C<perl Makefile.PL> subprocess.
  5653. =back
  5654. =head2 CPAN::Shell
  5655. The commands that are available in the shell interface are methods in
  5656. the package CPAN::Shell. If you enter the shell command, all your
  5657. input is split by the Text::ParseWords::shellwords() routine which
  5658. acts like most shells do. The first word is being interpreted as the
  5659. method to be called and the rest of the words are treated as arguments
  5660. to this method. Continuation lines are supported if a line ends with a
  5661. literal backslash.
  5662. =head2 autobundle
  5663. C<autobundle> writes a bundle file into the
  5664. C<$CPAN::Config-E<gt>{cpan_home}/Bundle> directory. The file contains
  5665. a list of all modules that are both available from CPAN and currently
  5666. installed within @INC. The name of the bundle file is based on the
  5667. current date and a counter.
  5668. =head2 recompile
  5669. recompile() is a very special command in that it takes no argument and
  5670. runs the make/test/install cycle with brute force over all installed
  5671. dynamically loadable extensions (aka XS modules) with 'force' in
  5672. effect. The primary purpose of this command is to finish a network
  5673. installation. Imagine, you have a common source tree for two different
  5674. architectures. You decide to do a completely independent fresh
  5675. installation. You start on one architecture with the help of a Bundle
  5676. file produced earlier. CPAN installs the whole Bundle for you, but
  5677. when you try to repeat the job on the second architecture, CPAN
  5678. responds with a C<"Foo up to date"> message for all modules. So you
  5679. invoke CPAN's recompile on the second architecture and you're done.
  5680. Another popular use for C<recompile> is to act as a rescue in case your
  5681. perl breaks binary compatibility. If one of the modules that CPAN uses
  5682. is in turn depending on binary compatibility (so you cannot run CPAN
  5683. commands), then you should try the CPAN::Nox module for recovery.
  5684. =head2 The four C<CPAN::*> Classes: Author, Bundle, Module, Distribution
  5685. Although it may be considered internal, the class hierarchy does matter
  5686. for both users and programmer. CPAN.pm deals with above mentioned four
  5687. classes, and all those classes share a set of methods. A classical
  5688. single polymorphism is in effect. A metaclass object registers all
  5689. objects of all kinds and indexes them with a string. The strings
  5690. referencing objects have a separated namespace (well, not completely
  5691. separated):
  5692. Namespace Class
  5693. words containing a "/" (slash) Distribution
  5694. words starting with Bundle:: Bundle
  5695. everything else Module or Author
  5696. Modules know their associated Distribution objects. They always refer
  5697. to the most recent official release. Developers may mark their releases
  5698. as unstable development versions (by inserting an underbar into the
  5699. module version number which will also be reflected in the distribution
  5700. name when you run 'make dist'), so the really hottest and newest
  5701. distribution is not always the default. If a module Foo circulates
  5702. on CPAN in both version 1.23 and 1.23_90, CPAN.pm offers a convenient
  5703. way to install version 1.23 by saying
  5704. install Foo
  5705. This would install the complete distribution file (say
  5706. BAR/Foo-1.23.tar.gz) with all accompanying material. But if you would
  5707. like to install version 1.23_90, you need to know where the
  5708. distribution file resides on CPAN relative to the authors/id/
  5709. directory. If the author is BAR, this might be BAR/Foo-1.23_90.tar.gz;
  5710. so you would have to say
  5711. install BAR/Foo-1.23_90.tar.gz
  5712. The first example will be driven by an object of the class
  5713. CPAN::Module, the second by an object of class CPAN::Distribution.
  5714. =head2 Programmer's interface
  5715. If you do not enter the shell, the available shell commands are both
  5716. available as methods (C<CPAN::Shell-E<gt>install(...)>) and as
  5717. functions in the calling package (C<install(...)>).
  5718. There's currently only one class that has a stable interface -
  5719. CPAN::Shell. All commands that are available in the CPAN shell are
  5720. methods of the class CPAN::Shell. Each of the commands that produce
  5721. listings of modules (C<r>, C<autobundle>, C<u>) also return a list of
  5722. the IDs of all modules within the list.
  5723. =over 2
  5724. =item expand($type,@things)
  5725. The IDs of all objects available within a program are strings that can
  5726. be expanded to the corresponding real objects with the
  5727. C<CPAN::Shell-E<gt>expand("Module",@things)> method. Expand returns a
  5728. list of CPAN::Module objects according to the C<@things> arguments
  5729. given. In scalar context it only returns the first element of the
  5730. list.
  5731. =item expandany(@things)
  5732. Like expand, but returns objects of the appropriate type, i.e.
  5733. CPAN::Bundle objects for bundles, CPAN::Module objects for modules and
  5734. CPAN::Distribution objects fro distributions.
  5735. =item Programming Examples
  5736. This enables the programmer to do operations that combine
  5737. functionalities that are available in the shell.
  5738. # install everything that is outdated on my disk:
  5739. perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
  5740. # install my favorite programs if necessary:
  5741. for $mod (qw(Net::FTP Digest::MD5 Data::Dumper)){
  5742. my $obj = CPAN::Shell->expand('Module',$mod);
  5743. $obj->install;
  5744. }
  5745. # list all modules on my disk that have no VERSION number
  5746. for $mod (CPAN::Shell->expand("Module","/./")){
  5747. next unless $mod->inst_file;
  5748. # MakeMaker convention for undefined $VERSION:
  5749. next unless $mod->inst_version eq "undef";
  5750. print "No VERSION in ", $mod->id, "\n";
  5751. }
  5752. # find out which distribution on CPAN contains a module:
  5753. print CPAN::Shell->expand("Module","Apache::Constants")->cpan_file
  5754. Or if you want to write a cronjob to watch The CPAN, you could list
  5755. all modules that need updating. First a quick and dirty way:
  5756. perl -e 'use CPAN; CPAN::Shell->r;'
  5757. If you don't want to get any output in the case that all modules are
  5758. up to date, you can parse the output of above command for the regular
  5759. expression //modules are up to date// and decide to mail the output
  5760. only if it doesn't match. Ick?
  5761. If you prefer to do it more in a programmer style in one single
  5762. process, maybe something like this suits you better:
  5763. # list all modules on my disk that have newer versions on CPAN
  5764. for $mod (CPAN::Shell->expand("Module","/./")){
  5765. next unless $mod->inst_file;
  5766. next if $mod->uptodate;
  5767. printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
  5768. $mod->id, $mod->inst_version, $mod->cpan_version;
  5769. }
  5770. If that gives you too much output every day, you maybe only want to
  5771. watch for three modules. You can write
  5772. for $mod (CPAN::Shell->expand("Module","/Apache|LWP|CGI/")){
  5773. as the first line instead. Or you can combine some of the above
  5774. tricks:
  5775. # watch only for a new mod_perl module
  5776. $mod = CPAN::Shell->expand("Module","mod_perl");
  5777. exit if $mod->uptodate;
  5778. # new mod_perl arrived, let me know all update recommendations
  5779. CPAN::Shell->r;
  5780. =back
  5781. =head2 Methods in the other Classes
  5782. The programming interface for the classes CPAN::Module,
  5783. CPAN::Distribution, CPAN::Bundle, and CPAN::Author is still considered
  5784. beta and partially even alpha. In the following paragraphs only those
  5785. methods are documented that have proven useful over a longer time and
  5786. thus are unlikely to change.
  5787. =over 4
  5788. =item CPAN::Author::as_glimpse()
  5789. Returns a one-line description of the author
  5790. =item CPAN::Author::as_string()
  5791. Returns a multi-line description of the author
  5792. =item CPAN::Author::email()
  5793. Returns the author's email address
  5794. =item CPAN::Author::fullname()
  5795. Returns the author's name
  5796. =item CPAN::Author::name()
  5797. An alias for fullname
  5798. =item CPAN::Bundle::as_glimpse()
  5799. Returns a one-line description of the bundle
  5800. =item CPAN::Bundle::as_string()
  5801. Returns a multi-line description of the bundle
  5802. =item CPAN::Bundle::clean()
  5803. Recursively runs the C<clean> method on all items contained in the bundle.
  5804. =item CPAN::Bundle::contains()
  5805. Returns a list of objects' IDs contained in a bundle. The associated
  5806. objects may be bundles, modules or distributions.
  5807. =item CPAN::Bundle::force($method,@args)
  5808. Forces CPAN to perform a task that normally would have failed. Force
  5809. takes as arguments a method name to be called and any number of
  5810. additional arguments that should be passed to the called method. The
  5811. internals of the object get the needed changes so that CPAN.pm does
  5812. not refuse to take the action. The C<force> is passed recursively to
  5813. all contained objects.
  5814. =item CPAN::Bundle::get()
  5815. Recursively runs the C<get> method on all items contained in the bundle
  5816. =item CPAN::Bundle::inst_file()
  5817. Returns the highest installed version of the bundle in either @INC or
  5818. C<$CPAN::Config->{cpan_home}>. Note that this is different from
  5819. CPAN::Module::inst_file.
  5820. =item CPAN::Bundle::inst_version()
  5821. Like CPAN::Bundle::inst_file, but returns the $VERSION
  5822. =item CPAN::Bundle::uptodate()
  5823. Returns 1 if the bundle itself and all its members are uptodate.
  5824. =item CPAN::Bundle::install()
  5825. Recursively runs the C<install> method on all items contained in the bundle
  5826. =item CPAN::Bundle::make()
  5827. Recursively runs the C<make> method on all items contained in the bundle
  5828. =item CPAN::Bundle::readme()
  5829. Recursively runs the C<readme> method on all items contained in the bundle
  5830. =item CPAN::Bundle::test()
  5831. Recursively runs the C<test> method on all items contained in the bundle
  5832. =item CPAN::Distribution::as_glimpse()
  5833. Returns a one-line description of the distribution
  5834. =item CPAN::Distribution::as_string()
  5835. Returns a multi-line description of the distribution
  5836. =item CPAN::Distribution::clean()
  5837. Changes to the directory where the distribution has been unpacked and
  5838. runs C<make clean> there.
  5839. =item CPAN::Distribution::containsmods()
  5840. Returns a list of IDs of modules contained in a distribution file.
  5841. Only works for distributions listed in the 02packages.details.txt.gz
  5842. file. This typically means that only the most recent version of a
  5843. distribution is covered.
  5844. =item CPAN::Distribution::cvs_import()
  5845. Changes to the directory where the distribution has been unpacked and
  5846. runs something like
  5847. cvs -d $cvs_root import -m $cvs_log $cvs_dir $userid v$version
  5848. there.
  5849. =item CPAN::Distribution::dir()
  5850. Returns the directory into which this distribution has been unpacked.
  5851. =item CPAN::Distribution::force($method,@args)
  5852. Forces CPAN to perform a task that normally would have failed. Force
  5853. takes as arguments a method name to be called and any number of
  5854. additional arguments that should be passed to the called method. The
  5855. internals of the object get the needed changes so that CPAN.pm does
  5856. not refuse to take the action.
  5857. =item CPAN::Distribution::get()
  5858. Downloads the distribution from CPAN and unpacks it. Does nothing if
  5859. the distribution has already been downloaded and unpacked within the
  5860. current session.
  5861. =item CPAN::Distribution::install()
  5862. Changes to the directory where the distribution has been unpacked and
  5863. runs the external command C<make install> there. If C<make> has not
  5864. yet been run, it will be run first. A C<make test> will be issued in
  5865. any case and if this fails, the install will be canceled. The
  5866. cancellation can be avoided by letting C<force> run the C<install> for
  5867. you.
  5868. =item CPAN::Distribution::isa_perl()
  5869. Returns 1 if this distribution file seems to be a perl distribution.
  5870. Normally this is derived from the file name only, but the index from
  5871. CPAN can contain a hint to achieve a return value of true for other
  5872. filenames too.
  5873. =item CPAN::Distribution::look()
  5874. Changes to the directory where the distribution has been unpacked and
  5875. opens a subshell there. Exiting the subshell returns.
  5876. =item CPAN::Distribution::make()
  5877. First runs the C<get> method to make sure the distribution is
  5878. downloaded and unpacked. Changes to the directory where the
  5879. distribution has been unpacked and runs the external commands C<perl
  5880. Makefile.PL> and C<make> there.
  5881. =item CPAN::Distribution::prereq_pm()
  5882. Returns the hash reference that has been announced by a distribution
  5883. as the PREREQ_PM hash in the Makefile.PL. Note: works only after an
  5884. attempt has been made to C<make> the distribution. Returns undef
  5885. otherwise.
  5886. =item CPAN::Distribution::readme()
  5887. Downloads the README file associated with a distribution and runs it
  5888. through the pager specified in C<$CPAN::Config->{pager}>.
  5889. =item CPAN::Distribution::test()
  5890. Changes to the directory where the distribution has been unpacked and
  5891. runs C<make test> there.
  5892. =item CPAN::Distribution::uptodate()
  5893. Returns 1 if all the modules contained in the distribution are
  5894. uptodate. Relies on containsmods.
  5895. =item CPAN::Index::force_reload()
  5896. Forces a reload of all indices.
  5897. =item CPAN::Index::reload()
  5898. Reloads all indices if they have been read more than
  5899. C<$CPAN::Config->{index_expire}> days.
  5900. =item CPAN::InfoObj::dump()
  5901. CPAN::Author, CPAN::Bundle, CPAN::Module, and CPAN::Distribution
  5902. inherit this method. It prints the data structure associated with an
  5903. object. Useful for debugging. Note: the data structure is considered
  5904. internal and thus subject to change without notice.
  5905. =item CPAN::Module::as_glimpse()
  5906. Returns a one-line description of the module
  5907. =item CPAN::Module::as_string()
  5908. Returns a multi-line description of the module
  5909. =item CPAN::Module::clean()
  5910. Runs a clean on the distribution associated with this module.
  5911. =item CPAN::Module::cpan_file()
  5912. Returns the filename on CPAN that is associated with the module.
  5913. =item CPAN::Module::cpan_version()
  5914. Returns the latest version of this module available on CPAN.
  5915. =item CPAN::Module::cvs_import()
  5916. Runs a cvs_import on the distribution associated with this module.
  5917. =item CPAN::Module::description()
  5918. Returns a 44 character description of this module. Only available for
  5919. modules listed in The Module List (CPAN/modules/00modlist.long.html
  5920. or 00modlist.long.txt.gz)
  5921. =item CPAN::Module::force($method,@args)
  5922. Forces CPAN to perform a task that normally would have failed. Force
  5923. takes as arguments a method name to be called and any number of
  5924. additional arguments that should be passed to the called method. The
  5925. internals of the object get the needed changes so that CPAN.pm does
  5926. not refuse to take the action.
  5927. =item CPAN::Module::get()
  5928. Runs a get on the distribution associated with this module.
  5929. =item CPAN::Module::inst_file()
  5930. Returns the filename of the module found in @INC. The first file found
  5931. is reported just like perl itself stops searching @INC when it finds a
  5932. module.
  5933. =item CPAN::Module::inst_version()
  5934. Returns the version number of the module in readable format.
  5935. =item CPAN::Module::install()
  5936. Runs an C<install> on the distribution associated with this module.
  5937. =item CPAN::Module::look()
  5938. Changes to the directory where the distribution associated with this
  5939. module has been unpacked and opens a subshell there. Exiting the
  5940. subshell returns.
  5941. =item CPAN::Module::make()
  5942. Runs a C<make> on the distribution associated with this module.
  5943. =item CPAN::Module::manpage_headline()
  5944. If module is installed, peeks into the module's manpage, reads the
  5945. headline and returns it. Moreover, if the module has been downloaded
  5946. within this session, does the equivalent on the downloaded module even
  5947. if it is not installed.
  5948. =item CPAN::Module::readme()
  5949. Runs a C<readme> on the distribution associated with this module.
  5950. =item CPAN::Module::test()
  5951. Runs a C<test> on the distribution associated with this module.
  5952. =item CPAN::Module::uptodate()
  5953. Returns 1 if the module is installed and up-to-date.
  5954. =item CPAN::Module::userid()
  5955. Returns the author's ID of the module.
  5956. =back
  5957. =head2 Cache Manager
  5958. Currently the cache manager only keeps track of the build directory
  5959. ($CPAN::Config->{build_dir}). It is a simple FIFO mechanism that
  5960. deletes complete directories below C<build_dir> as soon as the size of
  5961. all directories there gets bigger than $CPAN::Config->{build_cache}
  5962. (in MB). The contents of this cache may be used for later
  5963. re-installations that you intend to do manually, but will never be
  5964. trusted by CPAN itself. This is due to the fact that the user might
  5965. use these directories for building modules on different architectures.
  5966. There is another directory ($CPAN::Config->{keep_source_where}) where
  5967. the original distribution files are kept. This directory is not
  5968. covered by the cache manager and must be controlled by the user. If
  5969. you choose to have the same directory as build_dir and as
  5970. keep_source_where directory, then your sources will be deleted with
  5971. the same fifo mechanism.
  5972. =head2 Bundles
  5973. A bundle is just a perl module in the namespace Bundle:: that does not
  5974. define any functions or methods. It usually only contains documentation.
  5975. It starts like a perl module with a package declaration and a $VERSION
  5976. variable. After that the pod section looks like any other pod with the
  5977. only difference being that I<one special pod section> exists starting with
  5978. (verbatim):
  5979. =head1 CONTENTS
  5980. In this pod section each line obeys the format
  5981. Module_Name [Version_String] [- optional text]
  5982. The only required part is the first field, the name of a module
  5983. (e.g. Foo::Bar, ie. I<not> the name of the distribution file). The rest
  5984. of the line is optional. The comment part is delimited by a dash just
  5985. as in the man page header.
  5986. The distribution of a bundle should follow the same convention as
  5987. other distributions.
  5988. Bundles are treated specially in the CPAN package. If you say 'install
  5989. Bundle::Tkkit' (assuming such a bundle exists), CPAN will install all
  5990. the modules in the CONTENTS section of the pod. You can install your
  5991. own Bundles locally by placing a conformant Bundle file somewhere into
  5992. your @INC path. The autobundle() command which is available in the
  5993. shell interface does that for you by including all currently installed
  5994. modules in a snapshot bundle file.
  5995. =head2 Prerequisites
  5996. If you have a local mirror of CPAN and can access all files with
  5997. "file:" URLs, then you only need a perl better than perl5.003 to run
  5998. this module. Otherwise Net::FTP is strongly recommended. LWP may be
  5999. required for non-UNIX systems or if your nearest CPAN site is
  6000. associated with a URL that is not C<ftp:>.
  6001. If you have neither Net::FTP nor LWP, there is a fallback mechanism
  6002. implemented for an external ftp command or for an external lynx
  6003. command.
  6004. =head2 Finding packages and VERSION
  6005. This module presumes that all packages on CPAN
  6006. =over 2
  6007. =item *
  6008. declare their $VERSION variable in an easy to parse manner. This
  6009. prerequisite can hardly be relaxed because it consumes far too much
  6010. memory to load all packages into the running program just to determine
  6011. the $VERSION variable. Currently all programs that are dealing with
  6012. version use something like this
  6013. perl -MExtUtils::MakeMaker -le \
  6014. 'print MM->parse_version(shift)' filename
  6015. If you are author of a package and wonder if your $VERSION can be
  6016. parsed, please try the above method.
  6017. =item *
  6018. come as compressed or gzipped tarfiles or as zip files and contain a
  6019. Makefile.PL (well, we try to handle a bit more, but without much
  6020. enthusiasm).
  6021. =back
  6022. =head2 Debugging
  6023. The debugging of this module is a bit complex, because we have
  6024. interferences of the software producing the indices on CPAN, of the
  6025. mirroring process on CPAN, of packaging, of configuration, of
  6026. synchronicity, and of bugs within CPAN.pm.
  6027. For code debugging in interactive mode you can try "o debug" which
  6028. will list options for debugging the various parts of the code. You
  6029. should know that "o debug" has built-in completion support.
  6030. For data debugging there is the C<dump> command which takes the same
  6031. arguments as make/test/install and outputs the object's Data::Dumper
  6032. dump.
  6033. =head2 Floppy, Zip, Offline Mode
  6034. CPAN.pm works nicely without network too. If you maintain machines
  6035. that are not networked at all, you should consider working with file:
  6036. URLs. Of course, you have to collect your modules somewhere first. So
  6037. you might use CPAN.pm to put together all you need on a networked
  6038. machine. Then copy the $CPAN::Config->{keep_source_where} (but not
  6039. $CPAN::Config->{build_dir}) directory on a floppy. This floppy is kind
  6040. of a personal CPAN. CPAN.pm on the non-networked machines works nicely
  6041. with this floppy. See also below the paragraph about CD-ROM support.
  6042. =head1 CONFIGURATION
  6043. When the CPAN module is used for the first time, a configuration
  6044. dialog tries to determine a couple of site specific options. The
  6045. result of the dialog is stored in a hash reference C< $CPAN::Config >
  6046. in a file CPAN/Config.pm.
  6047. The default values defined in the CPAN/Config.pm file can be
  6048. overridden in a user specific file: CPAN/MyConfig.pm. Such a file is
  6049. best placed in $HOME/.cpan/CPAN/MyConfig.pm, because $HOME/.cpan is
  6050. added to the search path of the CPAN module before the use() or
  6051. require() statements.
  6052. The configuration dialog can be started any time later again by
  6053. issueing the command C< o conf init > in the CPAN shell.
  6054. Currently the following keys in the hash reference $CPAN::Config are
  6055. defined:
  6056. build_cache size of cache for directories to build modules
  6057. build_dir locally accessible directory to build modules
  6058. index_expire after this many days refetch index files
  6059. cache_metadata use serializer to cache metadata
  6060. cpan_home local directory reserved for this package
  6061. dontload_hash anonymous hash: modules in the keys will not be
  6062. loaded by the CPAN::has_inst() routine
  6063. gzip location of external program gzip
  6064. histfile file to maintain history between sessions
  6065. histsize maximum number of lines to keep in histfile
  6066. inactivity_timeout breaks interactive Makefile.PLs after this
  6067. many seconds inactivity. Set to 0 to never break.
  6068. inhibit_startup_message
  6069. if true, does not print the startup message
  6070. keep_source_where directory in which to keep the source (if we do)
  6071. make location of external make program
  6072. make_arg arguments that should always be passed to 'make'
  6073. make_install_arg same as make_arg for 'make install'
  6074. makepl_arg arguments passed to 'perl Makefile.PL'
  6075. pager location of external program more (or any pager)
  6076. prerequisites_policy
  6077. what to do if you are missing module prerequisites
  6078. ('follow' automatically, 'ask' me, or 'ignore')
  6079. proxy_user username for accessing an authenticating proxy
  6080. proxy_pass password for accessing an authenticating proxy
  6081. scan_cache controls scanning of cache ('atstart' or 'never')
  6082. tar location of external program tar
  6083. term_is_latin if true internal UTF-8 is translated to ISO-8859-1
  6084. (and nonsense for characters outside latin range)
  6085. unzip location of external program unzip
  6086. urllist arrayref to nearby CPAN sites (or equivalent locations)
  6087. wait_list arrayref to a wait server to try (See CPAN::WAIT)
  6088. ftp_proxy, } the three usual variables for configuring
  6089. http_proxy, } proxy requests. Both as CPAN::Config variables
  6090. no_proxy } and as environment variables configurable.
  6091. You can set and query each of these options interactively in the cpan
  6092. shell with the command set defined within the C<o conf> command:
  6093. =over 2
  6094. =item C<o conf E<lt>scalar optionE<gt>>
  6095. prints the current value of the I<scalar option>
  6096. =item C<o conf E<lt>scalar optionE<gt> E<lt>valueE<gt>>
  6097. Sets the value of the I<scalar option> to I<value>
  6098. =item C<o conf E<lt>list optionE<gt>>
  6099. prints the current value of the I<list option> in MakeMaker's
  6100. neatvalue format.
  6101. =item C<o conf E<lt>list optionE<gt> [shift|pop]>
  6102. shifts or pops the array in the I<list option> variable
  6103. =item C<o conf E<lt>list optionE<gt> [unshift|push|splice] E<lt>listE<gt>>
  6104. works like the corresponding perl commands.
  6105. =back
  6106. =head2 Note on urllist parameter's format
  6107. urllist parameters are URLs according to RFC 1738. We do a little
  6108. guessing if your URL is not compliant, but if you have problems with
  6109. file URLs, please try the correct format. Either:
  6110. file://localhost/whatever/ftp/pub/CPAN/
  6111. or
  6112. file:///home/ftp/pub/CPAN/
  6113. =head2 urllist parameter has CD-ROM support
  6114. The C<urllist> parameter of the configuration table contains a list of
  6115. URLs that are to be used for downloading. If the list contains any
  6116. C<file> URLs, CPAN always tries to get files from there first. This
  6117. feature is disabled for index files. So the recommendation for the
  6118. owner of a CD-ROM with CPAN contents is: include your local, possibly
  6119. outdated CD-ROM as a C<file> URL at the end of urllist, e.g.
  6120. o conf urllist push file://localhost/CDROM/CPAN
  6121. CPAN.pm will then fetch the index files from one of the CPAN sites
  6122. that come at the beginning of urllist. It will later check for each
  6123. module if there is a local copy of the most recent version.
  6124. Another peculiarity of urllist is that the site that we could
  6125. successfully fetch the last file from automatically gets a preference
  6126. token and is tried as the first site for the next request. So if you
  6127. add a new site at runtime it may happen that the previously preferred
  6128. site will be tried another time. This means that if you want to disallow
  6129. a site for the next transfer, it must be explicitly removed from
  6130. urllist.
  6131. =head1 SECURITY
  6132. There's no strong security layer in CPAN.pm. CPAN.pm helps you to
  6133. install foreign, unmasked, unsigned code on your machine. We compare
  6134. to a checksum that comes from the net just as the distribution file
  6135. itself. If somebody has managed to tamper with the distribution file,
  6136. they may have as well tampered with the CHECKSUMS file. Future
  6137. development will go towards strong authentication.
  6138. =head1 EXPORT
  6139. Most functions in package CPAN are exported per default. The reason
  6140. for this is that the primary use is intended for the cpan shell or for
  6141. one-liners.
  6142. =head1 POPULATE AN INSTALLATION WITH LOTS OF MODULES
  6143. Populating a freshly installed perl with my favorite modules is pretty
  6144. easy if you maintain a private bundle definition file. To get a useful
  6145. blueprint of a bundle definition file, the command autobundle can be used
  6146. on the CPAN shell command line. This command writes a bundle definition
  6147. file for all modules that are installed for the currently running perl
  6148. interpreter. It's recommended to run this command only once and from then
  6149. on maintain the file manually under a private name, say
  6150. Bundle/my_bundle.pm. With a clever bundle file you can then simply say
  6151. cpan> install Bundle::my_bundle
  6152. then answer a few questions and then go out for a coffee.
  6153. Maintaining a bundle definition file means keeping track of two
  6154. things: dependencies and interactivity. CPAN.pm sometimes fails on
  6155. calculating dependencies because not all modules define all MakeMaker
  6156. attributes correctly, so a bundle definition file should specify
  6157. prerequisites as early as possible. On the other hand, it's a bit
  6158. annoying that many distributions need some interactive configuring. So
  6159. what I try to accomplish in my private bundle file is to have the
  6160. packages that need to be configured early in the file and the gentle
  6161. ones later, so I can go out after a few minutes and leave CPAN.pm
  6162. untended.
  6163. =head1 WORKING WITH CPAN.pm BEHIND FIREWALLS
  6164. Thanks to Graham Barr for contributing the following paragraphs about
  6165. the interaction between perl, and various firewall configurations. For
  6166. further informations on firewalls, it is recommended to consult the
  6167. documentation that comes with the ncftp program. If you are unable to
  6168. go through the firewall with a simple Perl setup, it is very likely
  6169. that you can configure ncftp so that it works for your firewall.
  6170. =head2 Three basic types of firewalls
  6171. Firewalls can be categorized into three basic types.
  6172. =over 4
  6173. =item http firewall
  6174. This is where the firewall machine runs a web server and to access the
  6175. outside world you must do it via the web server. If you set environment
  6176. variables like http_proxy or ftp_proxy to a values beginning with http://
  6177. or in your web browser you have to set proxy information then you know
  6178. you are running an http firewall.
  6179. To access servers outside these types of firewalls with perl (even for
  6180. ftp) you will need to use LWP.
  6181. =item ftp firewall
  6182. This where the firewall machine runs an ftp server. This kind of
  6183. firewall will only let you access ftp servers outside the firewall.
  6184. This is usually done by connecting to the firewall with ftp, then
  6185. entering a username like "user@outside.host.com"
  6186. To access servers outside these type of firewalls with perl you
  6187. will need to use Net::FTP.
  6188. =item One way visibility
  6189. I say one way visibility as these firewalls try to make themselves look
  6190. invisible to the users inside the firewall. An FTP data connection is
  6191. normally created by sending the remote server your IP address and then
  6192. listening for the connection. But the remote server will not be able to
  6193. connect to you because of the firewall. So for these types of firewall
  6194. FTP connections need to be done in a passive mode.
  6195. There are two that I can think off.
  6196. =over 4
  6197. =item SOCKS
  6198. If you are using a SOCKS firewall you will need to compile perl and link
  6199. it with the SOCKS library, this is what is normally called a 'socksified'
  6200. perl. With this executable you will be able to connect to servers outside
  6201. the firewall as if it is not there.
  6202. =item IP Masquerade
  6203. This is the firewall implemented in the Linux kernel, it allows you to
  6204. hide a complete network behind one IP address. With this firewall no
  6205. special compiling is needed as you can access hosts directly.
  6206. For accessing ftp servers behind such firewalls you may need to set
  6207. the environment variable C<FTP_PASSIVE> to a true value, e.g.
  6208. env FTP_PASSIVE=1 perl -MCPAN -eshell
  6209. or
  6210. perl -MCPAN -e '$ENV{FTP_PASSIVE} = 1; shell'
  6211. =back
  6212. =back
  6213. =head2 Configuring lynx or ncftp for going through a firewall
  6214. If you can go through your firewall with e.g. lynx, presumably with a
  6215. command such as
  6216. /usr/local/bin/lynx -pscott:tiger
  6217. then you would configure CPAN.pm with the command
  6218. o conf lynx "/usr/local/bin/lynx -pscott:tiger"
  6219. That's all. Similarly for ncftp or ftp, you would configure something
  6220. like
  6221. o conf ncftp "/usr/bin/ncftp -f /home/scott/ncftplogin.cfg"
  6222. Your mileage may vary...
  6223. =head1 FAQ
  6224. =over 4
  6225. =item 1)
  6226. I installed a new version of module X but CPAN keeps saying,
  6227. I have the old version installed
  6228. Most probably you B<do> have the old version installed. This can
  6229. happen if a module installs itself into a different directory in the
  6230. @INC path than it was previously installed. This is not really a
  6231. CPAN.pm problem, you would have the same problem when installing the
  6232. module manually. The easiest way to prevent this behaviour is to add
  6233. the argument C<UNINST=1> to the C<make install> call, and that is why
  6234. many people add this argument permanently by configuring
  6235. o conf make_install_arg UNINST=1
  6236. =item 2)
  6237. So why is UNINST=1 not the default?
  6238. Because there are people who have their precise expectations about who
  6239. may install where in the @INC path and who uses which @INC array. In
  6240. fine tuned environments C<UNINST=1> can cause damage.
  6241. =item 3)
  6242. I want to clean up my mess, and install a new perl along with
  6243. all modules I have. How do I go about it?
  6244. Run the autobundle command for your old perl and optionally rename the
  6245. resulting bundle file (e.g. Bundle/mybundle.pm), install the new perl
  6246. with the Configure option prefix, e.g.
  6247. ./Configure -Dprefix=/usr/local/perl-5.6.78.9
  6248. Install the bundle file you produced in the first step with something like
  6249. cpan> install Bundle::mybundle
  6250. and you're done.
  6251. =item 4)
  6252. When I install bundles or multiple modules with one command
  6253. there is too much output to keep track of.
  6254. You may want to configure something like
  6255. o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
  6256. o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"
  6257. so that STDOUT is captured in a file for later inspection.
  6258. =item 5)
  6259. I am not root, how can I install a module in a personal directory?
  6260. You will most probably like something like this:
  6261. o conf makepl_arg "LIB=~/myperl/lib \
  6262. INSTALLMAN1DIR=~/myperl/man/man1 \
  6263. INSTALLMAN3DIR=~/myperl/man/man3"
  6264. install Sybase::Sybperl
  6265. You can make this setting permanent like all C<o conf> settings with
  6266. C<o conf commit>.
  6267. You will have to add ~/myperl/man to the MANPATH environment variable
  6268. and also tell your perl programs to look into ~/myperl/lib, e.g. by
  6269. including
  6270. use lib "$ENV{HOME}/myperl/lib";
  6271. or setting the PERL5LIB environment variable.
  6272. Another thing you should bear in mind is that the UNINST parameter
  6273. should never be set if you are not root.
  6274. =item 6)
  6275. How to get a package, unwrap it, and make a change before building it?
  6276. look Sybase::Sybperl
  6277. =item 7)
  6278. I installed a Bundle and had a couple of fails. When I
  6279. retried, everything resolved nicely. Can this be fixed to work
  6280. on first try?
  6281. The reason for this is that CPAN does not know the dependencies of all
  6282. modules when it starts out. To decide about the additional items to
  6283. install, it just uses data found in the generated Makefile. An
  6284. undetected missing piece breaks the process. But it may well be that
  6285. your Bundle installs some prerequisite later than some depending item
  6286. and thus your second try is able to resolve everything. Please note,
  6287. CPAN.pm does not know the dependency tree in advance and cannot sort
  6288. the queue of things to install in a topologically correct order. It
  6289. resolves perfectly well IFF all modules declare the prerequisites
  6290. correctly with the PREREQ_PM attribute to MakeMaker. For bundles which
  6291. fail and you need to install often, it is recommended sort the Bundle
  6292. definition file manually. It is planned to improve the metadata
  6293. situation for dependencies on CPAN in general, but this will still
  6294. take some time.
  6295. =item 8)
  6296. In our intranet we have many modules for internal use. How
  6297. can I integrate these modules with CPAN.pm but without uploading
  6298. the modules to CPAN?
  6299. Have a look at the CPAN::Site module.
  6300. =item 9)
  6301. When I run CPAN's shell, I get error msg about line 1 to 4,
  6302. setting meta input/output via the /etc/inputrc file.
  6303. Some versions of readline are picky about capitalization in the
  6304. /etc/inputrc file and specifically RedHat 6.2 comes with a
  6305. /etc/inputrc that contains the word C<on> in lowercase. Change the
  6306. occurrences of C<on> to C<On> and the bug should disappear.
  6307. =item 10)
  6308. Some authors have strange characters in their names.
  6309. Internally CPAN.pm uses the UTF-8 charset. If your terminal is
  6310. expecting ISO-8859-1 charset, a converter can be activated by setting
  6311. term_is_latin to a true value in your config file. One way of doing so
  6312. would be
  6313. cpan> ! $CPAN::Config->{term_is_latin}=1
  6314. Extended support for converters will be made available as soon as perl
  6315. becomes stable with regard to charset issues.
  6316. =back
  6317. =head1 BUGS
  6318. We should give coverage for B<all> of the CPAN and not just the PAUSE
  6319. part, right? In this discussion CPAN and PAUSE have become equal --
  6320. but they are not. PAUSE is authors/, modules/ and scripts/. CPAN is
  6321. PAUSE plus the clpa/, doc/, misc/, ports/, and src/.
  6322. Future development should be directed towards a better integration of
  6323. the other parts.
  6324. If a Makefile.PL requires special customization of libraries, prompts
  6325. the user for special input, etc. then you may find CPAN is not able to
  6326. build the distribution. In that case, you should attempt the
  6327. traditional method of building a Perl module package from a shell.
  6328. =head1 AUTHOR
  6329. Andreas Koenig E<lt>andreas.koenig@anima.deE<gt>
  6330. =head1 TRANSLATIONS
  6331. Kawai,Takanori provides a Japanese translation of this manpage at
  6332. http://member.nifty.ne.jp/hippo2000/perltips/CPAN.htm
  6333. =head1 SEE ALSO
  6334. perl(1), CPAN::Nox(3)
  6335. =cut