1 package CPAN::Mirrored::By;
7 sub continent { shift->[0] }
8 sub country { shift->[1] }
11 package CPAN::FirstTime;
14 use ExtUtils::MakeMaker qw(prompt);
16 use File::Basename ();
18 use vars qw($VERSION);
19 $VERSION = substr q$Revision: 1.40 $, 10;
23 CPAN::FirstTime - Utility for CPAN::Config file Initialization
27 CPAN::FirstTime::init()
31 The init routine asks a few questions and writes a CPAN::Config
32 file. Nothing special.
40 unless ($CPAN::VERSION) {
43 eval {require CPAN::Config;};
49 my($ans,$default,$local,$cont,$url,$expected_size);
57 CPAN is the world-wide archive of perl resources. It consists of about
58 100 sites that all replicate the same contents all around the globe.
59 Many countries have at least one CPAN site already. The resources
60 found on CPAN are easily accessible with the CPAN.pm module. If you
61 want to use CPAN.pm, you have to configure it properly.
63 If you do not want to enter a dialog now, you can answer 'no' to this
64 question and I\'ll try to autoconfigure. (Note: you can revisit this
65 dialog anytime later by typing 'o conf init' at the cpan prompt.)
70 ExtUtils::MakeMaker::prompt("Are you ready for manual configuration?",
75 if ($manual_conf =~ /^\s*y/i) {
77 *prompt = \&ExtUtils::MakeMaker::prompt;
80 $CPAN::Config->{urllist} ||= [];
81 # prototype should match that of &MakeMaker::prompt
84 my($ret) = defined $a ? $a : "";
85 printf qq{%s [%s]\n\n}, $q, $ret;
92 The following questions are intended to help you with the
93 configuration. The CPAN module needs a directory of its own to cache
94 important index files and maybe keep a temporary mirror of CPAN files.
95 This may be a site-wide directory or a personal directory.
99 my $cpan_home = $CPAN::Config->{cpan_home} || MM->catdir($ENV{HOME}, ".cpan");
103 I see you already have a directory
105 Shall we use it as the general CPAN build and cache directory?
111 First of all, I\'d like to create this directory. Where?
116 $default = $cpan_home;
117 while ($ans = prompt("CPAN build and cache directory?",$default)) {
118 eval { File::Path::mkpath($ans); }; # dies if it can't
120 warn "Couldn't create directory $ans.
124 if (-d $ans && -w _) {
127 warn "Couldn't find directory $ans
128 or directory is not writable. Please retry.\n";
131 $CPAN::Config->{cpan_home} = $ans;
135 If you want, I can keep the source files after a build in the cpan
136 home directory. If you choose so then future builds will take the
137 files from there. If you don\'t want to keep them, answer 0 to the
142 $CPAN::Config->{keep_source_where} = MM->catdir($CPAN::Config->{cpan_home},"sources");
143 $CPAN::Config->{build_dir} = MM->catdir($CPAN::Config->{cpan_home},"build");
146 # Cache size, Index expire
151 How big should the disk cache be for keeping the build directories
152 with all the intermediate files\?
156 $default = $CPAN::Config->{build_cache} || 10;
157 $ans = prompt("Cache size for build directory (in MB)?", $default);
158 $CPAN::Config->{build_cache} = $ans;
160 # XXX This the time when we refetch the index files (in days)
161 $CPAN::Config->{'index_expire'} = 1;
165 By default, each time the CPAN module is started, cache scanning
166 is performed to keep the cache size in sync. To prevent from this,
167 disable the cache scanning with 'never'.
171 $default = $CPAN::Config->{scan_cache} || 'atstart';
173 $ans = prompt("Perform cache scanning (atstart or never)?", $default);
174 } while ($ans ne 'atstart' && $ans ne 'never');
175 $CPAN::Config->{scan_cache} = $ans;
178 # prerequisites_policy
179 # Do we follow PREREQ_PM?
183 The CPAN module can detect when a module that which you are trying to
184 build depends on prerequisites. If this happens, it can build the
185 prerequisites for you automatically ('follow'), ask you for
186 confirmation ('ask'), or just ignore them ('ignore'). Please set your
187 policy to one of the three values.
191 $default = $CPAN::Config->{prerequisites_policy} || 'ask';
194 prompt("Policy on building prerequisites (follow, ask or ignore)?",
196 } while ($ans ne 'follow' && $ans ne 'ask' && $ans ne 'ignore');
197 $CPAN::Config->{prerequisites_policy} = $ans;
205 The CPAN module will need a few external programs to work
206 properly. Please correct me, if I guess the wrong path for a program.
207 Don\'t panic if you do not have some of them, just press ENTER for
213 local $^W if $^O eq 'MacOS';
214 my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
215 local $^W = $old_warn;
217 for $progname (qw/gzip tar unzip make lynx ncftpget ncftp ftp/){
218 if ($^O eq 'MacOS') {
219 $CPAN::Config->{$progname} = 'not_here';
222 my $progcall = $progname;
223 # we don't need ncftp if we have ncftpget
224 next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
225 my $path = $CPAN::Config->{$progname}
226 || $Config::Config{$progname}
228 if (MM->file_name_is_absolute($path)) {
229 # testing existence is not good enough, some have these exe
232 # warn "Warning: configured $path does not exist\n" unless -e $path;
239 $progcall = $Config::Config{$progname} if $Config::Config{$progname};
242 $path ||= find_exe($progcall,[@path]);
243 warn "Warning: $progcall not found in PATH\n" unless
244 $path; # not -e $path, because find_exe already checked that
245 $ans = prompt("Where is your $progname program?",$path) || $path;
246 $CPAN::Config->{$progname} = $ans;
248 my $path = $CPAN::Config->{'pager'} ||
249 $ENV{PAGER} || find_exe("less",[@path]) ||
250 find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
252 $ans = prompt("What is your favorite pager program?",$path);
253 $CPAN::Config->{'pager'} = $ans;
254 $path = $CPAN::Config->{'shell'};
255 if (MM->file_name_is_absolute($path)) {
256 warn "Warning: configured $path does not exist\n" unless -e $path;
259 $path ||= $ENV{SHELL};
260 if ($^O eq 'MacOS') {
261 $CPAN::Config->{'shell'} = 'not_here';
263 $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
264 $ans = prompt("What is your favorite shell?",$path);
265 $CPAN::Config->{'shell'} = $ans;
269 # Arguments to make etc.
274 Every Makefile.PL is run by perl in a separate process. Likewise we
275 run \'make\' and \'make install\' in processes. If you have any parameters
276 \(e.g. PREFIX, INSTALLPRIVLIB, UNINST or the like\) you want to pass to
277 the calls, please specify them here.
279 If you don\'t understand this question, just press ENTER.
283 $default = $CPAN::Config->{makepl_arg} || "";
284 $CPAN::Config->{makepl_arg} =
285 prompt("Parameters for the 'perl Makefile.PL' command?",$default);
286 $default = $CPAN::Config->{make_arg} || "";
287 $CPAN::Config->{make_arg} = prompt("Parameters for the 'make' command?",$default);
289 $default = $CPAN::Config->{make_install_arg} || $CPAN::Config->{make_arg} || "";
290 $CPAN::Config->{make_install_arg} =
291 prompt("Parameters for the 'make install' command?",$default);
299 Sometimes you may wish to leave the processes run by CPAN alone
300 without caring about them. As sometimes the Makefile.PL contains
301 question you\'re expected to answer, you can set a timer that will
302 kill a 'perl Makefile.PL' process after the specified time in seconds.
304 If you set this value to 0, these processes will wait forever. This is
305 the default and recommended setting.
309 $default = $CPAN::Config->{inactivity_timeout} || 0;
310 $CPAN::Config->{inactivity_timeout} =
311 prompt("Timeout for inactivity during Makefile.PL?",$default);
317 If you\'re accessing the net via proxies, you can specify them in the
318 CPAN configuration or via environment variables. The variable in
319 the \$CPAN::Config takes precedence.
323 for (qw/ftp_proxy http_proxy no_proxy/) {
324 $default = $CPAN::Config->{$_} || $ENV{$_};
325 $CPAN::Config->{$_} = prompt("Your $_?",$default);
332 conf_sites() unless $fastread;
334 unless (@{$CPAN::Config->{'wait_list'}||[]}) {
337 WAIT support is available as a Plugin. You need the CPAN::WAIT module
338 to actually use it. But we need to know your favorite WAIT server. If
339 you don\'t know a WAIT server near you, just press ENTER.
342 $default = "wait://ls6.informatik.uni-dortmund.de:1404";
343 $ans = prompt("Your favorite WAIT server?\n ",$default);
344 push @{$CPAN::Config->{'wait_list'}}, $ans;
347 # We don't ask that now, it will be noticed in time, won't it?
348 $CPAN::Config->{'inhibit_startup_message'} = 0;
349 $CPAN::Config->{'getcwd'} = 'cwd';
352 CPAN::Config->commit($configpm);
356 my $m = 'MIRRORED.BY';
357 my $mby = MM->catfile($CPAN::Config->{keep_source_where},$m);
358 File::Path::mkpath(File::Basename::dirname($mby));
359 if (-f $mby && -f $m && -M $m < -M $mby) {
361 File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
367 print qq{You have no $mby
368 I\'m trying to fetch one
370 $mby = CPAN::FTP->localize($m,$mby,3);
371 } elsif (-M $mby > 60 && $loopcount == 0) {
372 print qq{Your $mby is older than 60 days,
373 I\'m trying to fetch one
375 $mby = CPAN::FTP->localize($m,$mby,3);
377 } elsif (-s $mby == 0) {
378 print qq{You have an empty $mby,
379 I\'m trying to fetch one
381 $mby = CPAN::FTP->localize($m,$mby,3);
386 read_mirrored_by($mby);
393 #warn "in find_exe exe[$exe] path[@$path]";
395 my $abs = MM->catfile($dir,$exe);
396 if (($abs = MM->maybe_command($abs))) {
403 my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
407 for $item (@$items) {
408 printf "(%d) %s\n", ++$i, $item;
413 my $num = prompt($prompt,$default);
414 @nums = split (' ', $num);
415 (warn "invalid items entered, try again\n"), next
416 if grep (/\D/ || $_ < 1 || $_ > $i, @nums);
417 if ($require_nonempty) {
418 (warn "$empty_warning\n"), next
428 sub read_mirrored_by {
429 my $local = shift or return;
430 my(%all,$url,$expected_size,$default,$ans,$host,$dst,$country,$continent,@location);
431 my $fh = FileHandle->new;
432 $fh->open($local) or die "Couldn't open $local: $!";
435 ($host) = /^([\w\.\-]+)/ unless defined $host;
436 next unless defined $host;
437 next unless /\s+dst_(dst|location)/;
438 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
439 ($continent, $country) = @location[-1,-2];
440 $continent =~ s/\s\(.*//;
441 $continent =~ s/\W+$//; # if Jarkko doesn't know latitude/longitude
442 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
443 next unless $host && $dst && $continent && $country;
444 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
446 $dst=$continent=$country="";
449 $CPAN::Config->{urllist} ||= [];
451 if (@previous_urls = @{$CPAN::Config->{urllist}}) {
452 $CPAN::Config->{urllist} = [];
457 Now we need to know where your favorite CPAN sites are located. Push
458 a few sites onto the array (just in case the first on the array won\'t
459 work). If you are mirroring CPAN to your local workstation, specify a
462 First, pick a nearby continent and country (you can pick several of
463 each, separated by spaces, or none if you just want to keep your
464 existing selections). Then, you will be presented with a list of URLs
465 of CPAN mirrors in the countries you selected, along with previously
466 selected URLs. Select some of those URLs, or just keep the old list.
467 Finally, you will be prompted for any extra URLs -- file:, ftp:, or
468 http: -- that host a CPAN mirror.
472 my (@cont, $cont, %cont, @countries, @urls, %seen);
473 my $no_previous_warn =
474 "Sorry! since you don't have any existing picks, you must make a\n" .
475 "geographic selection.";
476 @cont = picklist([sort keys %all],
477 "Select your continent (or several nearby continents)",
483 foreach $cont (@cont) {
484 my @c = sort keys %{$all{$cont}};
485 @cont{@c} = map ($cont, 0..$#c);
486 @c = map ("$_ ($cont)", @c) if @cont > 1;
487 push (@countries, @c);
491 @countries = picklist (\@countries,
492 "Select your country (or several nearby countries)",
496 %seen = map (($_ => 1), @previous_urls);
497 # hmmm, should take list of defaults from CPAN::Config->{'urllist'}...
498 foreach $country (@countries) {
499 (my $bare_country = $country) =~ s/ \(.*\)//;
500 my @u = sort keys %{$all{$cont{$bare_country}}{$bare_country}};
501 @u = grep (! $seen{$_}, @u);
502 @u = map ("$_ ($bare_country)", @u)
507 push (@urls, map ("$_ (previous pick)", @previous_urls));
508 my $prompt = "Select as many URLs as you like";
509 if (@previous_urls) {
510 $default = join (' ', ((scalar @urls) - (scalar @previous_urls) + 1) ..
512 $prompt .= "\n(or just hit RETURN to keep your previous picks)";
515 @urls = picklist (\@urls, $prompt, $default);
516 foreach (@urls) { s/ \(.*\)//; }
517 push @{$CPAN::Config->{urllist}}, @urls;
521 my %seen = map (($_ => 1), @{$CPAN::Config->{urllist}});
524 my $prompt = "Enter another URL or RETURN to quit:";
526 $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
528 Please enter your CPAN site:};
530 $ans = prompt ($prompt, "");
533 $ans =~ s|/?\z|/|; # has to end with one slash
534 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
535 if ($ans =~ /^\w+:\/./) {
536 push @urls, $ans unless $seen{$ans}++;
538 print qq{"$ans" doesn\'t look like an URL at first sight.
539 I\'ll ignore it for now. You can add it to $INC{'CPAN/MyConfig.pm'}
540 later if you\'re sure it\'s right.\n};
543 } while $ans || !%seen;
545 push @{$CPAN::Config->{urllist}}, @urls;
546 # xxx delete or comment these out when you're happy that it works
547 print "New set of picks:\n";
548 map { print " $_\n" } @{$CPAN::Config->{urllist}};