integrate cfgperl contents into mainline
[p5sagit/p5-mst-13.2.git] / lib / CPAN / FirstTime.pm
index 14ef541..0e795da 100644 (file)
@@ -16,7 +16,7 @@ use FileHandle ();
 use File::Basename ();
 use File::Path ();
 use vars qw($VERSION);
-$VERSION = substr q$Revision: 1.33 $, 10;
+$VERSION = substr q$Revision: 1.38 $, 10;
 
 =head1 NAME
 
@@ -77,7 +77,9 @@ dialog anytime later by typing 'o conf init' at the cpan prompt.)
        *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;
@@ -113,13 +115,18 @@ First of all, I\'d like to create this directory. Where?
 
     $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;
 
@@ -183,7 +190,9 @@ policy to one of the three values.
 
     $default = $CPAN::Config->{prerequisites_policy} || 'follow';
     do {
-        $ans = prompt("Perform cache scanning (follow, ask or ignore)?", $default);
+      $ans =
+         prompt("Policy on building prerequisites (follow, ask or ignore)?",
+                $default);
     } while ($ans ne 'follow' && $ans ne 'ask' && $ans ne 'ignore');
     $CPAN::Config->{prerequisites_policy} = $ans;
 
@@ -200,9 +209,16 @@ those.
 
 };
 
+    my $old_warn = $^W;
+    local $^W if $^O eq 'MacOS';
     my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
+    local $^W = $old_warn;
     my $progname;
     for $progname (qw/gzip tar unzip make lynx ncftpget ncftp ftp/){
+      if ($^O eq 'MacOS') {
+          $CPAN::Config->{$progname} = 'not_here';
+          next;
+      }
       my $progcall = $progname;
       # we don't need ncftp if we have ncftpget
       next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
@@ -231,7 +247,8 @@ those.
     }
     my $path = $CPAN::Config->{'pager'} || 
        $ENV{PAGER} || find_exe("less",[@path]) || 
-           find_exe("more",[@path]) || "more";
+           find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
+           || "more";
     $ans = prompt("What is your favorite pager program?",$path);
     $CPAN::Config->{'pager'} = $ans;
     $path = $CPAN::Config->{'shell'};
@@ -240,9 +257,13 @@ those.
        $path = "";
     }
     $path ||= $ENV{SHELL};
-    $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
-    $ans = prompt("What is your favorite shell?",$path);
-    $CPAN::Config->{'shell'} = $ans;
+    if ($^O eq 'MacOS') {
+        $CPAN::Config->{'shell'} = 'not_here';
+    } else {
+        $path =~ s,\\,/,g if $^O eq 'os2';     # Cosmetic only
+        $ans = prompt("What is your favorite shell?",$path);
+        $CPAN::Config->{'shell'} = $ans;
+    }
 
     #
     # Arguments to make etc.
@@ -339,16 +360,27 @@ sub conf_sites {
     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;
+  while () {
+    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);
 }
@@ -396,6 +428,7 @@ sub read_mirrored_by {
     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: $!";
+    local $/ = "\012";
     while (<$fh>) {
        ($host) = /^([\w\.\-]+)/ unless defined $host;
        next unless defined $host;