Reinstate PERL_MALLOC_WRAP for bcc32 on Win32
[p5sagit/p5-mst-13.2.git] / lib / CPAN / FirstTime.pm
CommitLineData
8d97e4a1 1# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
5f05dabc 2package CPAN::Mirrored::By;
3
4sub new {
5 my($self,@arg) = @_;
6 bless [@arg], $self;
7}
da199366 8sub continent { shift->[0] }
9sub country { shift->[1] }
5f05dabc 10sub url { shift->[2] }
11
12package CPAN::FirstTime;
13
14use strict;
f915a99a 15use ExtUtils::MakeMaker ();
05454584 16use FileHandle ();
09d9d230 17use File::Basename ();
05454584 18use File::Path ();
5de3f0da 19use File::Spec;
5f05dabc 20use vars qw($VERSION);
73beb80c 21$VERSION = substr q$Revision: 1.60_01 $, 10;
5f05dabc 22
23=head1 NAME
24
25CPAN::FirstTime - Utility for CPAN::Config file Initialization
26
27=head1 SYNOPSIS
28
29CPAN::FirstTime::init()
30
31=head1 DESCRIPTION
32
33The init routine asks a few questions and writes a CPAN::Config
34file. Nothing special.
35
36=cut
37
38
39sub init {
40 my($configpm) = @_;
41 use Config;
f610777f 42 unless ($CPAN::VERSION) {
43 require CPAN::Nox;
44 }
5f05dabc 45 eval {require CPAN::Config;};
46 $CPAN::Config ||= {};
da199366 47 local($/) = "\n";
48 local($\) = "";
13bc20ff 49 local($|) = 1;
da199366 50
5fc0f0f6 51 my($ans,$default);
f610777f 52
da199366 53 #
54 # Files, directories
55 #
56
2e2b7522 57 print qq[
09d9d230 58
59CPAN is the world-wide archive of perl resources. It consists of about
60100 sites that all replicate the same contents all around the globe.
61Many countries have at least one CPAN site already. The resources
62found on CPAN are easily accessible with the CPAN.pm module. If you
63want to use CPAN.pm, you have to configure it properly.
64
65If you do not want to enter a dialog now, you can answer 'no' to this
66question and I\'ll try to autoconfigure. (Note: you can revisit this
67dialog anytime later by typing 'o conf init' at the cpan prompt.)
68
2e2b7522 69];
09d9d230 70
f915a99a 71 my $manual_conf = prompt("Are you ready for manual configuration?", "yes");
09d9d230 72 my $fastread;
73 {
f915a99a 74 if ($manual_conf =~ /^y/i) {
09d9d230 75 $fastread = 0;
09d9d230 76 } else {
77 $fastread = 1;
36263cb3 78 $CPAN::Config->{urllist} ||= [];
f915a99a 79
80 local $^W = 0;
c9d9b473 81 # prototype should match that of &MakeMaker::prompt
f915a99a 82 *_real_prompt = sub ($;$) {
09d9d230 83 my($q,$a) = @_;
84 my($ret) = defined $a ? $a : "";
85 printf qq{%s [%s]\n\n}, $q, $ret;
f915a99a 86
09d9d230 87 $ret;
88 };
89 }
90 }
91 print qq{
92
93The following questions are intended to help you with the
94configuration. The CPAN module needs a directory of its own to cache
95important index files and maybe keep a temporary mirror of CPAN files.
96This may be a site-wide directory or a personal directory.
97
5f05dabc 98};
99
5de3f0da 100 my $cpan_home = $CPAN::Config->{cpan_home} || File::Spec->catdir($ENV{HOME}, ".cpan");
5f05dabc 101 if (-d $cpan_home) {
102 print qq{
103
104I see you already have a directory
105 $cpan_home
106Shall we use it as the general CPAN build and cache directory?
107
108};
109 } else {
110 print qq{
111
112First of all, I\'d like to create this directory. Where?
113
114};
115 }
116
117 $default = $cpan_home;
05454584 118 while ($ans = prompt("CPAN build and cache directory?",$default)) {
5fc0f0f6 119 unless (File::Spec->file_name_is_absolute($ans)) {
120 require Cwd;
121 my $cwd = Cwd::cwd();
122 my $absans = File::Spec->catdir($cwd,$ans);
123 warn "The path '$ans' is not an absolute path. Please specify an absolute path\n";
124 $default = $absans;
125 next;
126 }
36263cb3 127 eval { File::Path::mkpath($ans); }; # dies if it can't
128 if ($@) {
129 warn "Couldn't create directory $ans.
130Please retry.\n";
131 next;
132 }
133 if (-d $ans && -w _) {
134 last;
135 } else {
136 warn "Couldn't find directory $ans
10b2abe6 137 or directory is not writable. Please retry.\n";
36263cb3 138 }
10b2abe6 139 }
5f05dabc 140 $CPAN::Config->{cpan_home} = $ans;
f610777f 141
5f05dabc 142 print qq{
143
144If you want, I can keep the source files after a build in the cpan
145home directory. If you choose so then future builds will take the
146files from there. If you don\'t want to keep them, answer 0 to the
147next question.
148
149};
150
5de3f0da 151 $CPAN::Config->{keep_source_where} = File::Spec->catdir($CPAN::Config->{cpan_home},"sources");
152 $CPAN::Config->{build_dir} = File::Spec->catdir($CPAN::Config->{cpan_home},"build");
5f05dabc 153
da199366 154 #
155 # Cache size, Index expire
156 #
157
5f05dabc 158 print qq{
159
160How big should the disk cache be for keeping the build directories
de34a54b 161with all the intermediate files\?
5f05dabc 162
163};
164
165 $default = $CPAN::Config->{build_cache} || 10;
166 $ans = prompt("Cache size for build directory (in MB)?", $default);
167 $CPAN::Config->{build_cache} = $ans;
168
169 # XXX This the time when we refetch the index files (in days)
170 $CPAN::Config->{'index_expire'} = 1;
171
f610777f 172 print qq{
173
174By default, each time the CPAN module is started, cache scanning
175is performed to keep the cache size in sync. To prevent from this,
176disable the cache scanning with 'never'.
177
178};
179
180 $default = $CPAN::Config->{scan_cache} || 'atstart';
181 do {
182 $ans = prompt("Perform cache scanning (atstart or never)?", $default);
183 } while ($ans ne 'atstart' && $ans ne 'never');
184 $CPAN::Config->{scan_cache} = $ans;
185
9d61fa1d 186 #
187 # cache_metadata
188 #
5e05dca5 189 print qq{
190
5a5fac02 191To considerably speed up the initial CPAN shell startup, it is
192possible to use Storable to create a cache of metadata. If Storable
193is not available, the normal index mechanism will be used.
5e05dca5 194
195};
196
5a5fac02 197 defined($default = $CPAN::Config->{cache_metadata}) or $default = 1;
5e05dca5 198 do {
199 $ans = prompt("Cache metadata (yes/no)?", ($default ? 'yes' : 'no'));
f915a99a 200 } while ($ans !~ /^[yn]/i);
201 $CPAN::Config->{cache_metadata} = ($ans =~ /^y/i ? 1 : 0);
5e05dca5 202
f610777f 203 #
9d61fa1d 204 # term_is_latin
205 #
206 print qq{
207
208The next option deals with the charset your terminal supports. In
209general CPAN is English speaking territory, thus the charset does not
210matter much, but some of the aliens out there who upload their
211software to CPAN bear names that are outside the ASCII range. If your
212terminal supports UTF-8, you say no to the next question, if it
213supports ISO-8859-1 (also known as LATIN1) then you say yes, and if it
214supports neither nor, your answer does not matter, you will not be
c049f953 215able to read the names of some authors anyway. If you answer no, names
9d61fa1d 216will be output in UTF-8.
217
218};
219
220 defined($default = $CPAN::Config->{term_is_latin}) or $default = 1;
221 do {
222 $ans = prompt("Your terminal expects ISO-8859-1 (yes/no)?",
223 ($default ? 'yes' : 'no'));
f915a99a 224 } while ($ans !~ /^[yn]/i);
225 $CPAN::Config->{term_is_latin} = ($ans =~ /^y/i ? 1 : 0);
9d61fa1d 226
227 #
5fc0f0f6 228 # save history in file histfile
229 #
230 print qq{
231
232If you have one of the readline packages (Term::ReadLine::Perl,
233Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
234shell will have history support. The next two questions deal with the
235filename of the history file and with its size. If you do not want to
236set this variable, please hit SPACE RETURN to the following question.
237
238};
239
240 defined($default = $CPAN::Config->{histfile}) or
241 $default = File::Spec->catfile($CPAN::Config->{cpan_home},"histfile");
242 $ans = prompt("File to save your history?", $default);
5fc0f0f6 243 $CPAN::Config->{histfile} = $ans;
244
245 if ($CPAN::Config->{histfile}) {
246 defined($default = $CPAN::Config->{histsize}) or $default = 100;
247 $ans = prompt("Number of lines to save?", $default);
248 $CPAN::Config->{histsize} = $ans;
249 }
250
251 #
f610777f 252 # prerequisites_policy
253 # Do we follow PREREQ_PM?
254 #
255 print qq{
256
257The CPAN module can detect when a module that which you are trying to
258build depends on prerequisites. If this happens, it can build the
259prerequisites for you automatically ('follow'), ask you for
260confirmation ('ask'), or just ignore them ('ignore'). Please set your
261policy to one of the three values.
262
263};
264
de34a54b 265 $default = $CPAN::Config->{prerequisites_policy} || 'ask';
f610777f 266 do {
f14b5cec 267 $ans =
268 prompt("Policy on building prerequisites (follow, ask or ignore)?",
269 $default);
f610777f 270 } while ($ans ne 'follow' && $ans ne 'ask' && $ans ne 'ignore');
271 $CPAN::Config->{prerequisites_policy} = $ans;
272
da199366 273 #
274 # External programs
275 #
276
5f05dabc 277 print qq{
278
9d61fa1d 279The CPAN module will need a few external programs to work properly.
280Please correct me, if I guess the wrong path for a program. Don\'t
281panic if you do not have some of them, just press ENTER for those. To
282disable the use of a download program, you can type a space followed
283by ENTER.
5f05dabc 284
285};
286
f14b5cec 287 my $old_warn = $^W;
288 local $^W if $^O eq 'MacOS';
55e314ee 289 my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
f14b5cec 290 local $^W = $old_warn;
09d9d230 291 my $progname;
73beb80c 292 for $progname (qw/gzip tar unzip make
293 curl lynx wget ncftpget ncftp ftp
294 gpg/)
295 {
f14b5cec 296 if ($^O eq 'MacOS') {
297 $CPAN::Config->{$progname} = 'not_here';
298 next;
299 }
09d9d230 300 my $progcall = $progname;
2e2b7522 301 # we don't need ncftp if we have ncftpget
302 next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
303 my $path = $CPAN::Config->{$progname}
304 || $Config::Config{$progname}
305 || "";
5de3f0da 306 if (File::Spec->file_name_is_absolute($path)) {
2e2b7522 307 # testing existence is not good enough, some have these exe
308 # extensions
309
310 # warn "Warning: configured $path does not exist\n" unless -e $path;
311 # $path = "";
312 } else {
313 $path = '';
314 }
315 unless ($path) {
316 # e.g. make -> nmake
317 $progcall = $Config::Config{$progname} if $Config::Config{$progname};
318 }
09d9d230 319
2e2b7522 320 $path ||= find_exe($progcall,[@path]);
321 warn "Warning: $progcall not found in PATH\n" unless
322 $path; # not -e $path, because find_exe already checked that
323 $ans = prompt("Where is your $progname program?",$path) || $path;
324 $CPAN::Config->{$progname} = $ans;
5f05dabc 325 }
326 my $path = $CPAN::Config->{'pager'} ||
327 $ENV{PAGER} || find_exe("less",[@path]) ||
f14b5cec 328 find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
329 || "more";
55e314ee 330 $ans = prompt("What is your favorite pager program?",$path);
5f05dabc 331 $CPAN::Config->{'pager'} = $ans;
55e314ee 332 $path = $CPAN::Config->{'shell'};
5de3f0da 333 if (File::Spec->file_name_is_absolute($path)) {
55e314ee 334 warn "Warning: configured $path does not exist\n" unless -e $path;
335 $path = "";
336 }
337 $path ||= $ENV{SHELL};
f14b5cec 338 if ($^O eq 'MacOS') {
339 $CPAN::Config->{'shell'} = 'not_here';
340 } else {
341 $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
342 $ans = prompt("What is your favorite shell?",$path);
343 $CPAN::Config->{'shell'} = $ans;
344 }
da199366 345
346 #
347 # Arguments to make etc.
348 #
349
5f05dabc 350 print qq{
351
da199366 352Every Makefile.PL is run by perl in a separate process. Likewise we
8d97e4a1 353run \'make\' and \'make install\' in processes. If you have any
354parameters \(e.g. PREFIX, LIB, UNINST or the like\) you want to pass
355to the calls, please specify them here.
5f05dabc 356
05454584 357If you don\'t understand this question, just press ENTER.
358
5f05dabc 359};
360
361 $default = $CPAN::Config->{makepl_arg} || "";
362 $CPAN::Config->{makepl_arg} =
8d97e4a1 363 prompt("Parameters for the 'perl Makefile.PL' command?
364Typical frequently used settings:
365
35576f8c 366 PREFIX=~/perl non-root users (please see manual for more hints)
8d97e4a1 367
368Your choice: ",$default);
5f05dabc 369 $default = $CPAN::Config->{make_arg} || "";
8d97e4a1 370 $CPAN::Config->{make_arg} = prompt("Parameters for the 'make' command?
371Typical frequently used setting:
372
373 -j3 dual processor system
374
375Your choice: ",$default);
5f05dabc 376
377 $default = $CPAN::Config->{make_install_arg} || $CPAN::Config->{make_arg} || "";
378 $CPAN::Config->{make_install_arg} =
8d97e4a1 379 prompt("Parameters for the 'make install' command?
380Typical frequently used setting:
381
382 UNINST=1 to always uninstall potentially conflicting files
383
384Your choice: ",$default);
5f05dabc 385
da199366 386 #
387 # Alarm period
388 #
389
10b2abe6 390 print qq{
391
392Sometimes you may wish to leave the processes run by CPAN alone
393without caring about them. As sometimes the Makefile.PL contains
394question you\'re expected to answer, you can set a timer that will
395kill a 'perl Makefile.PL' process after the specified time in seconds.
396
e50380aa 397If you set this value to 0, these processes will wait forever. This is
398the default and recommended setting.
10b2abe6 399
400};
401
402 $default = $CPAN::Config->{inactivity_timeout} || 0;
403 $CPAN::Config->{inactivity_timeout} =
09d9d230 404 prompt("Timeout for inactivity during Makefile.PL?",$default);
10b2abe6 405
09d9d230 406 # Proxies
da199366 407
09d9d230 408 print qq{
10b2abe6 409
09d9d230 410If you\'re accessing the net via proxies, you can specify them in the
411CPAN configuration or via environment variables. The variable in
412the \$CPAN::Config takes precedence.
5f05dabc 413
05454584 414};
09d9d230 415
416 for (qw/ftp_proxy http_proxy no_proxy/) {
417 $default = $CPAN::Config->{$_} || $ENV{$_};
418 $CPAN::Config->{$_} = prompt("Your $_?",$default);
5f05dabc 419 }
420
c049f953 421 if ($CPAN::Config->{ftp_proxy} ||
422 $CPAN::Config->{http_proxy}) {
423 $default = $CPAN::Config->{proxy_user} || $CPAN::LWP::UserAgent::USER;
424 print qq{
425
426If your proxy is an authenticating proxy, you can store your username
427permanently. If you do not want that, just press RETURN. You will then
428be asked for your username in every future session.
429
430};
431 if ($CPAN::Config->{proxy_user} = prompt("Your proxy user id?",$default)) {
432 print qq{
433
434Your password for the authenticating proxy can also be stored
435permanently on disk. If this violates your security policy, just press
436RETURN. You will then be asked for the password in every future
437session.
438
439};
440
441 if ($CPAN::META->has_inst("Term::ReadKey")) {
442 Term::ReadKey::ReadMode("noecho");
443 } else {
444 print qq{
445
446Warning: Term::ReadKey seems not to be available, your password will
447be echoed to the terminal!
448
449};
450 }
f915a99a 451 $CPAN::Config->{proxy_pass} = prompt_no_strip("Your proxy password?");
c049f953 452 if ($CPAN::META->has_inst("Term::ReadKey")) {
453 Term::ReadKey::ReadMode("restore");
454 }
455 $CPAN::Frontend->myprint("\n\n");
456 }
457 }
458
09d9d230 459 #
460 # MIRRORED.BY
461 #
462
463 conf_sites() unless $fastread;
464
e50380aa 465 # We don't ask that now, it will be noticed in time, won't it?
5f05dabc 466 $CPAN::Config->{'inhibit_startup_message'} = 0;
e50380aa 467 $CPAN::Config->{'getcwd'} = 'cwd';
5f05dabc 468
469 print "\n\n";
470 CPAN::Config->commit($configpm);
471}
472
09d9d230 473sub conf_sites {
474 my $m = 'MIRRORED.BY';
5de3f0da 475 my $mby = File::Spec->catfile($CPAN::Config->{keep_source_where},$m);
09d9d230 476 File::Path::mkpath(File::Basename::dirname($mby));
477 if (-f $mby && -f $m && -M $m < -M $mby) {
478 require File::Copy;
479 File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
480 }
911a92db 481 my $loopcount = 0;
de34a54b 482 local $^T = time;
d8773709 483 my $overwrite_local = 0;
484 if ($mby && -f $mby && -M _ <= 60 && -s _ > 0) {
485 my $mtime = localtime((stat _)[9]);
486 my $prompt = qq{Found $mby as of $mtime
487
c049f953 488I\'d use that as a database of CPAN sites. If that is OK for you,
489please answer 'y', but if you want me to get a new database now,
490please answer 'n' to the following question.
d8773709 491
c049f953 492Shall I use the local database in $mby?};
d8773709 493 my $ans = prompt($prompt,"y");
494 $overwrite_local = 1 unless $ans =~ /^y/i;
495 }
de34a54b 496 while ($mby) {
d8773709 497 if ($overwrite_local) {
498 print qq{Trying to overwrite $mby
499};
500 $mby = CPAN::FTP->localize($m,$mby,3);
501 $overwrite_local = 0;
502 } elsif ( ! -f $mby ){
36263cb3 503 print qq{You have no $mby
09d9d230 504 I\'m trying to fetch one
505};
36263cb3 506 $mby = CPAN::FTP->localize($m,$mby,3);
911a92db 507 } elsif (-M $mby > 60 && $loopcount == 0) {
508 print qq{Your $mby is older than 60 days,
09d9d230 509 I\'m trying to fetch one
510};
36263cb3 511 $mby = CPAN::FTP->localize($m,$mby,3);
911a92db 512 $loopcount++;
36263cb3 513 } elsif (-s $mby == 0) {
514 print qq{You have an empty $mby,
515 I\'m trying to fetch one
516};
517 $mby = CPAN::FTP->localize($m,$mby,3);
518 } else {
519 last;
520 }
09d9d230 521 }
522 read_mirrored_by($mby);
de34a54b 523 bring_your_own();
09d9d230 524}
525
5f05dabc 526sub find_exe {
527 my($exe,$path) = @_;
55e314ee 528 my($dir);
529 #warn "in find_exe exe[$exe] path[@$path]";
5f05dabc 530 for $dir (@$path) {
5de3f0da 531 my $abs = File::Spec->catfile($dir,$exe);
13bc20ff 532 if (($abs = MM->maybe_command($abs))) {
5f05dabc 533 return $abs;
534 }
535 }
536}
537
f610777f 538sub picklist {
539 my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
540 $default ||= '';
541
5fc0f0f6 542 my $pos = 0;
f610777f 543
544 my @nums;
545 while (1) {
ec385757 546
5fc0f0f6 547 # display, at most, 15 items at a time
548 my $limit = $#{ $items } - $pos;
549 $limit = 15 if $limit > 15;
550
551 # show the next $limit items, get the new position
552 $pos = display_some($items, $limit, $pos);
553 $pos = 0 if $pos >= @$items;
554
555 my $num = prompt($prompt,$default);
556
557 @nums = split (' ', $num);
558 my $i = scalar @$items;
559 (warn "invalid items entered, try again\n"), next
560 if grep (/\D/ || $_ < 1 || $_ > $i, @nums);
561 if ($require_nonempty) {
562 (warn "$empty_warning\n");
563 }
564 print "\n";
565
566 # a blank line continues...
567 next unless @nums;
568 last;
f610777f 569 }
f610777f 570 for (@nums) { $_-- }
571 @{$items}[@nums];
572}
573
ec385757 574sub display_some {
575 my ($items, $limit, $pos) = @_;
576 $pos ||= 0;
577
578 my @displayable = @$items[$pos .. ($pos + $limit)];
579 for my $item (@displayable) {
580 printf "(%d) %s\n", ++$pos, $item;
581 }
5fc0f0f6 582 printf("%d more items, hit SPACE RETURN to show them\n",
583 (@$items - $pos)
584 )
585 if $pos < @$items;
ec385757 586 return $pos;
587}
588
5f05dabc 589sub read_mirrored_by {
de34a54b 590 my $local = shift or return;
5f05dabc 591 my(%all,$url,$expected_size,$default,$ans,$host,$dst,$country,$continent,@location);
05454584 592 my $fh = FileHandle->new;
593 $fh->open($local) or die "Couldn't open $local: $!";
f14b5cec 594 local $/ = "\012";
05454584 595 while (<$fh>) {
5f05dabc 596 ($host) = /^([\w\.\-]+)/ unless defined $host;
597 next unless defined $host;
598 next unless /\s+dst_(dst|location)/;
599 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
600 ($continent, $country) = @location[-1,-2];
601 $continent =~ s/\s\(.*//;
f610777f 602 $continent =~ s/\W+$//; # if Jarkko doesn't know latitude/longitude
5f05dabc 603 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
604 next unless $host && $dst && $continent && $country;
605 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
606 undef $host;
607 $dst=$continent=$country="";
608 }
05454584 609 $fh->close;
5f05dabc 610 $CPAN::Config->{urllist} ||= [];
f610777f 611 my(@previous_urls);
612 if (@previous_urls = @{$CPAN::Config->{urllist}}) {
5f05dabc 613 $CPAN::Config->{urllist} = [];
5f05dabc 614 }
f610777f 615
5f05dabc 616 print qq{
617
f610777f 618Now we need to know where your favorite CPAN sites are located. Push
5f05dabc 619a few sites onto the array (just in case the first on the array won\'t
620work). If you are mirroring CPAN to your local workstation, specify a
621file: URL.
622
f610777f 623First, pick a nearby continent and country (you can pick several of
624each, separated by spaces, or none if you just want to keep your
625existing selections). Then, you will be presented with a list of URLs
626of CPAN mirrors in the countries you selected, along with previously
627selected URLs. Select some of those URLs, or just keep the old list.
628Finally, you will be prompted for any extra URLs -- file:, ftp:, or
629http: -- that host a CPAN mirror.
5f05dabc 630
631};
632
f610777f 633 my (@cont, $cont, %cont, @countries, @urls, %seen);
634 my $no_previous_warn =
635 "Sorry! since you don't have any existing picks, you must make a\n" .
636 "geographic selection.";
637 @cont = picklist([sort keys %all],
638 "Select your continent (or several nearby continents)",
639 '',
640 ! @previous_urls,
641 $no_previous_warn);
642
643
644 foreach $cont (@cont) {
645 my @c = sort keys %{$all{$cont}};
646 @cont{@c} = map ($cont, 0..$#c);
647 @c = map ("$_ ($cont)", @c) if @cont > 1;
648 push (@countries, @c);
5f05dabc 649 }
f610777f 650
651 if (@countries) {
652 @countries = picklist (\@countries,
653 "Select your country (or several nearby countries)",
654 '',
655 ! @previous_urls,
656 $no_previous_warn);
657 %seen = map (($_ => 1), @previous_urls);
658 # hmmm, should take list of defaults from CPAN::Config->{'urllist'}...
659 foreach $country (@countries) {
660 (my $bare_country = $country) =~ s/ \(.*\)//;
661 my @u = sort keys %{$all{$cont{$bare_country}}{$bare_country}};
662 @u = grep (! $seen{$_}, @u);
663 @u = map ("$_ ($bare_country)", @u)
664 if @countries > 1;
665 push (@urls, @u);
666 }
667 }
668 push (@urls, map ("$_ (previous pick)", @previous_urls));
5fc0f0f6 669 my $prompt = "Select as many URLs as you like (by number),
670put them on one line, separated by blanks, e.g. '1 4 5'";
f610777f 671 if (@previous_urls) {
672 $default = join (' ', ((scalar @urls) - (scalar @previous_urls) + 1) ..
673 (scalar @urls));
674 $prompt .= "\n(or just hit RETURN to keep your previous picks)";
675 }
676
677 @urls = picklist (\@urls, $prompt, $default);
678 foreach (@urls) { s/ \(.*\)//; }
de34a54b 679 push @{$CPAN::Config->{urllist}}, @urls;
680}
f610777f 681
de34a54b 682sub bring_your_own {
683 my %seen = map (($_ => 1), @{$CPAN::Config->{urllist}});
684 my($ans,@urls);
f610777f 685 do {
de34a54b 686 my $prompt = "Enter another URL or RETURN to quit:";
687 unless (%seen) {
688 $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
689
690Please enter your CPAN site:};
691 }
692 $ans = prompt ($prompt, "");
f610777f 693
694 if ($ans) {
de34a54b 695 $ans =~ s|/?\z|/|; # has to end with one slash
f610777f 696 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
697 if ($ans =~ /^\w+:\/./) {
8d97e4a1 698 push @urls, $ans unless $seen{$ans}++;
de34a54b 699 } else {
8d97e4a1 700 printf(qq{"%s" doesn\'t look like an URL at first sight.
701I\'ll ignore it for now.
702You can add it to your %s
703later if you\'re sure it\'s right.\n},
704 $ans,
705 $INC{'CPAN/MyConfig.pm'} || $INC{'CPAN/Config.pm'} || "configuration file",
706 );
f610777f 707 }
708 }
de34a54b 709 } while $ans || !%seen;
f610777f 710
711 push @{$CPAN::Config->{urllist}}, @urls;
712 # xxx delete or comment these out when you're happy that it works
713 print "New set of picks:\n";
714 map { print " $_\n" } @{$CPAN::Config->{urllist}};
5f05dabc 715}
716
f915a99a 717
718sub _strip_spaces {
719 $_[0] =~ s/^\s+//; # no leading spaces
720 $_[0] =~ s/\s+\z//; # no trailing spaces
721}
722
723
724sub prompt ($;$) {
725 my $ans = _real_prompt(@_);
726
727 _strip_spaces($ans);
728
729 return $ans;
730}
731
732
733sub prompt_no_strip ($;$) {
734 return _real_prompt(@_);
735}
736
737
738*_real_prompt = \*ExtUtils::MakeMaker::prompt;
739
740
5f05dabc 7411;