use File::Basename ();
use File::Path ();
use vars qw($VERSION);
-$VERSION = substr q$Revision: 1.35 $, 10;
+$VERSION = substr q$Revision: 1.46 $, 10;
=head1 NAME
*prompt = \&ExtUtils::MakeMaker::prompt;
} else {
$fastread = 1;
- *prompt = sub {
+ $CPAN::Config->{urllist} ||= [];
+ # prototype should match that of &MakeMaker::prompt
+ *prompt = sub ($;$) {
my($q,$a) = @_;
my($ret) = defined $a ? $a : "";
printf qq{%s [%s]\n\n}, $q, $ret;
$default = $cpan_home;
while ($ans = prompt("CPAN build and cache directory?",$default)) {
- File::Path::mkpath($ans); # dies if it can't
- if (-d $ans && -w _) {
- last;
- } else {
- warn "Couldn't find directory $ans
+ eval { File::Path::mkpath($ans); }; # dies if it can't
+ if ($@) {
+ warn "Couldn't create directory $ans.
+Please retry.\n";
+ next;
+ }
+ if (-d $ans && -w _) {
+ last;
+ } else {
+ warn "Couldn't find directory $ans
or directory is not writable. Please retry.\n";
- }
+ }
}
$CPAN::Config->{cpan_home} = $ans;
print qq{
How big should the disk cache be for keeping the build directories
-with all the intermediate files?
+with all the intermediate files\?
};
} while ($ans ne 'atstart' && $ans ne 'never');
$CPAN::Config->{scan_cache} = $ans;
+ print qq{
+
+To considerably speed up the initial CPAN shell startup, it is
+possible to use Storable to create a cache of metadata. If Storable
+is not available, the normal index mechanism will be used.
+
+};
+
+ defined($default = $CPAN::Config->{cache_metadata}) or $default = 1;
+ do {
+ $ans = prompt("Cache metadata (yes/no)?", ($default ? 'yes' : 'no'));
+ } while ($ans !~ /^\s*[yn]/i);
+ $CPAN::Config->{cache_metadata} = ($ans =~ /^\s*y/i ? 1 : 0);
+
#
# prerequisites_policy
# Do we follow PREREQ_PM?
};
- $default = $CPAN::Config->{prerequisites_policy} || 'follow';
+ $default = $CPAN::Config->{prerequisites_policy} || 'ask';
do {
$ans =
prompt("Policy on building prerequisites (follow, ask or ignore)?",
require File::Copy;
File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
}
- if ( ! -f $mby ){
- print qq{You have no $mby
+ my $loopcount = 0;
+ local $^T = time;
+ while ($mby) {
+ if ( ! -f $mby ){
+ print qq{You have no $mby
+ I\'m trying to fetch one
+};
+ $mby = CPAN::FTP->localize($m,$mby,3);
+ } elsif (-M $mby > 60 && $loopcount == 0) {
+ print qq{Your $mby is older than 60 days,
I\'m trying to fetch one
};
- $mby = CPAN::FTP->localize($m,$mby,3);
- } elsif (-M $mby > 30 ) {
- print qq{Your $mby is older than 30 days,
+ $mby = CPAN::FTP->localize($m,$mby,3);
+ $loopcount++;
+ } elsif (-s $mby == 0) {
+ print qq{You have an empty $mby,
I\'m trying to fetch one
};
- $mby = CPAN::FTP->localize($m,$mby,3);
+ $mby = CPAN::FTP->localize($m,$mby,3);
+ } else {
+ last;
+ }
}
read_mirrored_by($mby);
+ bring_your_own();
}
sub find_exe {
}
sub read_mirrored_by {
- my($local) = @_;
+ my $local = shift or return;
my(%all,$url,$expected_size,$default,$ans,$host,$dst,$country,$continent,@location);
my $fh = FileHandle->new;
$fh->open($local) or die "Couldn't open $local: $!";
@urls = picklist (\@urls, $prompt, $default);
foreach (@urls) { s/ \(.*\)//; }
- %seen = map (($_ => 1), @urls);
+ push @{$CPAN::Config->{urllist}}, @urls;
+}
+sub bring_your_own {
+ my %seen = map (($_ => 1), @{$CPAN::Config->{urllist}});
+ my($ans,@urls);
do {
- $ans = prompt ("Enter another URL or RETURN to quit:", "");
+ my $prompt = "Enter another URL or RETURN to quit:";
+ unless (%seen) {
+ $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
+
+Please enter your CPAN site:};
+ }
+ $ans = prompt ($prompt, "");
if ($ans) {
- $ans =~ s|/?$|/|; # has to end with one slash
+ $ans =~ s|/?\z|/|; # has to end with one slash
$ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
if ($ans =~ /^\w+:\/./) {
- push @urls, $ans
- unless $seen{$ans};
- }
- else {
+ push @urls, $ans unless $seen{$ans}++;
+ } else {
print qq{"$ans" doesn\'t look like an URL at first sight.
I\'ll ignore it for now. You can add it to $INC{'CPAN/MyConfig.pm'}
later if you\'re sure it\'s right.\n};
}
}
- } while $ans;
+ } while $ans || !%seen;
push @{$CPAN::Config->{urllist}}, @urls;
# xxx delete or comment these out when you're happy that it works