Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6992 lines
220 KiB

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