Upgrade to Archive-Tar-1.28
[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;
e82b9348 3use strict;
1a43333d 4use vars qw($VERSION);
c9869e1c 5$VERSION = sprintf "%.2f", substr(q$Rev: 450 $,4)/100;
5f05dabc 6
7sub new {
8 my($self,@arg) = @_;
9 bless [@arg], $self;
10}
da199366 11sub continent { shift->[0] }
12sub country { shift->[1] }
5f05dabc 13sub url { shift->[2] }
14
15package CPAN::FirstTime;
16
17use strict;
f915a99a 18use ExtUtils::MakeMaker ();
05454584 19use FileHandle ();
09d9d230 20use File::Basename ();
05454584 21use File::Path ();
5de3f0da 22use File::Spec;
5f05dabc 23use vars qw($VERSION);
c9869e1c 24$VERSION = sprintf "%.2f", substr(q$Rev: 450 $,4)/100;
5f05dabc 25
26=head1 NAME
27
28CPAN::FirstTime - Utility for CPAN::Config file Initialization
29
30=head1 SYNOPSIS
31
32CPAN::FirstTime::init()
33
34=head1 DESCRIPTION
35
c9869e1c 36The init routine asks a few questions and writes a CPAN/Config.pm or
37CPAN/MyConfig.pm file (depending on what it is currently using).
38
5f05dabc 39
40=cut
41
9ddc4ed0 42use vars qw( %prompts );
43
5f05dabc 44sub init {
554a9ef5 45 my($configpm, %args) = @_;
5f05dabc 46 use Config;
9ddc4ed0 47 # extra arg in 'o conf init make' selects only $item =~ /make/
48 my $matcher = $args{args} && @{$args{args}} ? $args{args}[0] : '';
c9869e1c 49 CPAN->debug("matcher[$matcher]") if $CPAN::DEBUG;
554a9ef5 50
f610777f 51 unless ($CPAN::VERSION) {
52 require CPAN::Nox;
53 }
5f05dabc 54 eval {require CPAN::Config;};
55 $CPAN::Config ||= {};
da199366 56 local($/) = "\n";
57 local($\) = "";
13bc20ff 58 local($|) = 1;
da199366 59
5fc0f0f6 60 my($ans,$default);
f610777f 61
da199366 62 #
63 # Files, directories
64 #
65
9ddc4ed0 66 print $prompts{manual_config};
09d9d230 67
554a9ef5 68 my $manual_conf;
69
70 local *_real_prompt = \&ExtUtils::MakeMaker::prompt;
71 if ( $args{autoconfig} ) {
72 $manual_conf = "no";
73 } else {
74 $manual_conf = prompt("Are you ready for manual configuration?", "yes");
75 }
09d9d230 76 my $fastread;
77 {
f915a99a 78 if ($manual_conf =~ /^y/i) {
09d9d230 79 $fastread = 0;
09d9d230 80 } else {
81 $fastread = 1;
36263cb3 82 $CPAN::Config->{urllist} ||= [];
f915a99a 83
84 local $^W = 0;
c9d9b473 85 # prototype should match that of &MakeMaker::prompt
f915a99a 86 *_real_prompt = sub ($;$) {
09d9d230 87 my($q,$a) = @_;
88 my($ret) = defined $a ? $a : "";
554a9ef5 89 $CPAN::Frontend->myprint(sprintf qq{%s [%s]\n\n}, $q, $ret);
90 eval { require Time::HiRes };
91 unless ($@) {
92 Time::HiRes::sleep(0.1);
93 }
09d9d230 94 $ret;
95 };
96 }
97 }
9ddc4ed0 98
c9869e1c 99 $CPAN::Frontend->myprint($prompts{config_intro})
100 if !$matcher or 'config_intro' =~ /$matcher/;
9ddc4ed0 101
102 my $cpan_home = $CPAN::Config->{cpan_home}
103 || File::Spec->catdir($ENV{HOME}, ".cpan");
5f05dabc 104
5f05dabc 105 if (-d $cpan_home) {
c9869e1c 106 if (!$matcher or 'config_intro' =~ /$matcher/) {
107 $CPAN::Frontend->myprint(qq{
5f05dabc 108
109I see you already have a directory
110 $cpan_home
111Shall we use it as the general CPAN build and cache directory?
112
554a9ef5 113});
c9869e1c 114 }
9ddc4ed0 115 } else {
c9869e1c 116 # no cpan-home, must prompt and get one
9ddc4ed0 117 $CPAN::Frontend->myprint($prompts{cpan_home_where});
5f05dabc 118 }
119
120 $default = $cpan_home;
05454584 121 while ($ans = prompt("CPAN build and cache directory?",$default)) {
5fc0f0f6 122 unless (File::Spec->file_name_is_absolute($ans)) {
123 require Cwd;
124 my $cwd = Cwd::cwd();
125 my $absans = File::Spec->catdir($cwd,$ans);
126 warn "The path '$ans' is not an absolute path. Please specify an absolute path\n";
127 $default = $absans;
128 next;
129 }
36263cb3 130 eval { File::Path::mkpath($ans); }; # dies if it can't
131 if ($@) {
9ddc4ed0 132 warn "Couldn't create directory $ans.\nPlease retry.\n";
36263cb3 133 next;
134 }
135 if (-d $ans && -w _) {
136 last;
137 } else {
9ddc4ed0 138 warn "Couldn't find directory $ans\n"
139 . "or directory is not writable. Please retry.\n";
36263cb3 140 }
10b2abe6 141 }
5f05dabc 142 $CPAN::Config->{cpan_home} = $ans;
f610777f 143
9ddc4ed0 144 $CPAN::Frontend->myprint($prompts{keep_source_where});
5f05dabc 145
9ddc4ed0 146 $CPAN::Config->{keep_source_where}
147 = File::Spec->catdir($CPAN::Config->{cpan_home},"sources");
5f05dabc 148
9ddc4ed0 149 $CPAN::Config->{build_dir}
150 = File::Spec->catdir($CPAN::Config->{cpan_home},"build");
5f05dabc 151
da199366 152 #
153 # Cache size, Index expire
154 #
155
c9869e1c 156 $CPAN::Frontend->myprint($prompts{build_cache_intro})
157 if !$matcher or 'build_cache_intro' =~ /$matcher/;
5f05dabc 158
9ddc4ed0 159 # large enough to build large dists like Tk
160 my_dflt_prompt(build_cache => 100, $matcher);
5f05dabc 161
162 # XXX This the time when we refetch the index files (in days)
163 $CPAN::Config->{'index_expire'} = 1;
164
c9869e1c 165 $CPAN::Frontend->myprint($prompts{scan_cache_intro})
166 if !$matcher or 'build_cache_intro' =~ /$matcher/;
167
9ddc4ed0 168 my_prompt_loop(scan_cache => 'atstart', $matcher, 'atstart|never');
f610777f 169
9d61fa1d 170 #
171 # cache_metadata
172 #
5e05dca5 173
c9869e1c 174 if (!$matcher or 'build_cache_intro' =~ /$matcher/) {
5e05dca5 175
c9869e1c 176 $CPAN::Frontend->myprint($prompts{cache_metadata});
5e05dca5 177
c9869e1c 178 defined($default = $CPAN::Config->{cache_metadata}) or $default = 1;
179 do {
180 $ans = prompt("Cache metadata (yes/no)?", ($default ? 'yes' : 'no'));
181 } while ($ans !~ /^[yn]/i);
182 $CPAN::Config->{cache_metadata} = ($ans =~ /^y/i ? 1 : 0);
183 }
f610777f 184 #
9d61fa1d 185 # term_is_latin
186 #
9d61fa1d 187
c9869e1c 188 $CPAN::Frontend->myprint($prompts{term_is_latin})
189 if !$matcher or 'term_is_latin' =~ /$matcher/;
9d61fa1d 190
191 defined($default = $CPAN::Config->{term_is_latin}) or $default = 1;
192 do {
193 $ans = prompt("Your terminal expects ISO-8859-1 (yes/no)?",
194 ($default ? 'yes' : 'no'));
f915a99a 195 } while ($ans !~ /^[yn]/i);
196 $CPAN::Config->{term_is_latin} = ($ans =~ /^y/i ? 1 : 0);
9d61fa1d 197
198 #
c9869e1c 199 # save history in file 'histfile'
5fc0f0f6 200 #
5fc0f0f6 201
c9869e1c 202 $CPAN::Frontend->myprint($prompts{histfile_intro});
5fc0f0f6 203
204 defined($default = $CPAN::Config->{histfile}) or
205 $default = File::Spec->catfile($CPAN::Config->{cpan_home},"histfile");
206 $ans = prompt("File to save your history?", $default);
5fc0f0f6 207 $CPAN::Config->{histfile} = $ans;
208
209 if ($CPAN::Config->{histfile}) {
210 defined($default = $CPAN::Config->{histsize}) or $default = 100;
211 $ans = prompt("Number of lines to save?", $default);
212 $CPAN::Config->{histsize} = $ans;
213 }
214
215 #
554a9ef5 216 # do an ls on the m or the d command
217 #
9ddc4ed0 218 $CPAN::Frontend->myprint($prompts{show_upload_date_intro});
554a9ef5 219
220 defined($default = $CPAN::Config->{show_upload_date}) or
9ddc4ed0 221 $default = 'n';
222 $ans = prompt("Always try to show upload date with 'd' and 'm' command (yes/no)?",
223 ($default ? 'yes' : 'no'));
224 $CPAN::Config->{show_upload_date} = ($ans =~ /^[y1]/i ? 1 : 0);
225
226 #my_prompt_loop(show_upload_date => 'n', $matcher,
227 #'follow|ask|ignore');
554a9ef5 228
229 #
f610777f 230 # prerequisites_policy
231 # Do we follow PREREQ_PM?
232 #
f610777f 233
c9869e1c 234 $CPAN::Frontend->myprint($prompts{prerequisites_policy_intro})
235 if !$matcher or 'prerequisites_policy_intro' =~ /$matcher/;
f610777f 236
9ddc4ed0 237 my_prompt_loop(prerequisites_policy => 'ask', $matcher,
238 'follow|ask|ignore');
f610777f 239
f610777f 240
da199366 241 #
242 # External programs
243 #
244
c9869e1c 245 $CPAN::Frontend->myprint($prompts{external_progs})
246 if !$matcher or 'external_progs' =~ /$matcher/;
5f05dabc 247
f14b5cec 248 my $old_warn = $^W;
249 local $^W if $^O eq 'MacOS';
55e314ee 250 my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
f14b5cec 251 local $^W = $old_warn;
09d9d230 252 my $progname;
e82b9348 253 for $progname (qw/bzip2 gzip tar unzip make
554a9ef5 254 curl lynx wget ncftpget ncftp ftp
73beb80c 255 gpg/)
256 {
f14b5cec 257 if ($^O eq 'MacOS') {
258 $CPAN::Config->{$progname} = 'not_here';
259 next;
260 }
9ddc4ed0 261 next if $matcher && $progname !~ /$matcher/;
262
09d9d230 263 my $progcall = $progname;
2e2b7522 264 # we don't need ncftp if we have ncftpget
265 next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
266 my $path = $CPAN::Config->{$progname}
267 || $Config::Config{$progname}
268 || "";
5de3f0da 269 if (File::Spec->file_name_is_absolute($path)) {
2e2b7522 270 # testing existence is not good enough, some have these exe
271 # extensions
272
273 # warn "Warning: configured $path does not exist\n" unless -e $path;
274 # $path = "";
275 } else {
276 $path = '';
277 }
278 unless ($path) {
279 # e.g. make -> nmake
280 $progcall = $Config::Config{$progname} if $Config::Config{$progname};
281 }
09d9d230 282
2e2b7522 283 $path ||= find_exe($progcall,[@path]);
554a9ef5 284 $CPAN::Frontend->mywarn("Warning: $progcall not found in PATH\n") unless
2e2b7522 285 $path; # not -e $path, because find_exe already checked that
286 $ans = prompt("Where is your $progname program?",$path) || $path;
287 $CPAN::Config->{$progname} = $ans;
5f05dabc 288 }
289 my $path = $CPAN::Config->{'pager'} ||
290 $ENV{PAGER} || find_exe("less",[@path]) ||
f14b5cec 291 find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
292 || "more";
55e314ee 293 $ans = prompt("What is your favorite pager program?",$path);
5f05dabc 294 $CPAN::Config->{'pager'} = $ans;
55e314ee 295 $path = $CPAN::Config->{'shell'};
5de3f0da 296 if (File::Spec->file_name_is_absolute($path)) {
55e314ee 297 warn "Warning: configured $path does not exist\n" unless -e $path;
298 $path = "";
299 }
300 $path ||= $ENV{SHELL};
c9869e1c 301 $path ||= $ENV{COMSPEC} if $^O eq "MSWin32";
f14b5cec 302 if ($^O eq 'MacOS') {
303 $CPAN::Config->{'shell'} = 'not_here';
304 } else {
305 $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
306 $ans = prompt("What is your favorite shell?",$path);
307 $CPAN::Config->{'shell'} = $ans;
308 }
da199366 309
310 #
311 # Arguments to make etc.
312 #
313
c9869e1c 314 $CPAN::Frontend->myprint($prompts{prefer_installer_intro})
315 if !$matcher or 'prerequisites_policy_intro' =~ /$matcher/;
e82b9348 316
9ddc4ed0 317 my_prompt_loop(prefer_installer => 'EUMM', $matcher, 'MB|EUMM');
e82b9348 318
e82b9348 319
c9869e1c 320 $CPAN::Frontend->myprint($prompts{makepl_arg_intro})
321 if !$matcher or 'makepl_arg_intro' =~ /$matcher/;
e82b9348 322
9ddc4ed0 323 my_dflt_prompt(makepl_arg => "", $matcher);
e82b9348 324
9ddc4ed0 325 my_dflt_prompt(make_arg => "", $matcher);
e82b9348 326
9ddc4ed0 327 my_dflt_prompt(make_install_make_command => $CPAN::Config->{make} || "",
328 $matcher);
e82b9348 329
9ddc4ed0 330 my_dflt_prompt(make_install_arg => $CPAN::Config->{make_arg} || "",
331 $matcher);
e82b9348 332
c9869e1c 333 $CPAN::Frontend->myprint($prompts{mbuildpl_arg_intro})
334 if !$matcher or 'mbuildpl_arg_intro' =~ /$matcher/;
e82b9348 335
9ddc4ed0 336 my_dflt_prompt(mbuildpl_arg => "", $matcher);
e82b9348 337
9ddc4ed0 338 my_dflt_prompt(mbuild_arg => "", $matcher);
e82b9348 339
9ddc4ed0 340 my_dflt_prompt(mbuild_install_build_command => "./Build", $matcher);
8d97e4a1 341
9ddc4ed0 342 my_dflt_prompt(mbuild_install_arg => "", $matcher);
5f05dabc 343
da199366 344 #
345 # Alarm period
346 #
347
c9869e1c 348 $CPAN::Frontend->myprint($prompts{inactivity_timeout_intro})
349 if !$matcher or 'inactivity_timeout_intro' =~ /$matcher/;
10b2abe6 350
9ddc4ed0 351 # my_dflt_prompt(inactivity_timeout => 0);
10b2abe6 352
353 $default = $CPAN::Config->{inactivity_timeout} || 0;
354 $CPAN::Config->{inactivity_timeout} =
9ddc4ed0 355 prompt("Timeout for inactivity during {Makefile,Build}.PL?",$default);
10b2abe6 356
09d9d230 357 # Proxies
da199366 358
c9869e1c 359 $CPAN::Frontend->myprint($prompts{proxy_intro})
360 if !$matcher or 'proxy_intro' =~ /$matcher/;
09d9d230 361
362 for (qw/ftp_proxy http_proxy no_proxy/) {
c9869e1c 363 next if $matcher and $_ =~ /$matcher/;
364
09d9d230 365 $default = $CPAN::Config->{$_} || $ENV{$_};
366 $CPAN::Config->{$_} = prompt("Your $_?",$default);
5f05dabc 367 }
368
c049f953 369 if ($CPAN::Config->{ftp_proxy} ||
370 $CPAN::Config->{http_proxy}) {
9ddc4ed0 371
c049f953 372 $default = $CPAN::Config->{proxy_user} || $CPAN::LWP::UserAgent::USER;
c049f953 373
9ddc4ed0 374 $CPAN::Frontend->myprint($prompts{proxy_user});
c049f953 375
c049f953 376 if ($CPAN::Config->{proxy_user} = prompt("Your proxy user id?",$default)) {
9ddc4ed0 377 $CPAN::Frontend->myprint($prompts{proxy_pass});
c049f953 378
379 if ($CPAN::META->has_inst("Term::ReadKey")) {
380 Term::ReadKey::ReadMode("noecho");
381 } else {
9ddc4ed0 382 $CPAN::Frontend->myprint($prompts{password_warn});
c049f953 383 }
f915a99a 384 $CPAN::Config->{proxy_pass} = prompt_no_strip("Your proxy password?");
c049f953 385 if ($CPAN::META->has_inst("Term::ReadKey")) {
386 Term::ReadKey::ReadMode("restore");
387 }
388 $CPAN::Frontend->myprint("\n\n");
389 }
390 }
391
09d9d230 392 #
393 # MIRRORED.BY
394 #
395
396 conf_sites() unless $fastread;
397
e50380aa 398 # We don't ask that now, it will be noticed in time, won't it?
5f05dabc 399 $CPAN::Config->{'inhibit_startup_message'} = 0;
e50380aa 400 $CPAN::Config->{'getcwd'} = 'cwd';
5f05dabc 401
554a9ef5 402 $CPAN::Frontend->myprint("\n\n");
e82b9348 403 CPAN::HandleConfig->commit($configpm);
5f05dabc 404}
405
9ddc4ed0 406sub my_dflt_prompt {
407 my ($item, $dflt, $m) = @_;
408 my $default = $CPAN::Config->{$item} || $dflt;
409
410 $DB::single = 1;
411 if (!$m || $item =~ /$m/) {
412 $CPAN::Config->{$item} = prompt($prompts{$item}, $default);
413 } else {
414 $CPAN::Config->{$item} = $default;
415 }
416}
417
418sub my_prompt_loop {
419 my ($item, $dflt, $m, $ok) = @_;
420 my $default = $CPAN::Config->{$item} || $dflt;
421 my $ans;
422
423 $DB::single = 1;
424 if (!$m || $item =~ /$m/) {
425 do { $ans = prompt($prompts{$item}, $default);
426 } until $ans =~ /$ok/;
427 $CPAN::Config->{$item} = $ans;
428 } else {
429 $CPAN::Config->{$item} = $default;
430 }
431}
432
433
09d9d230 434sub conf_sites {
435 my $m = 'MIRRORED.BY';
5de3f0da 436 my $mby = File::Spec->catfile($CPAN::Config->{keep_source_where},$m);
09d9d230 437 File::Path::mkpath(File::Basename::dirname($mby));
438 if (-f $mby && -f $m && -M $m < -M $mby) {
439 require File::Copy;
440 File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
441 }
911a92db 442 my $loopcount = 0;
de34a54b 443 local $^T = time;
d8773709 444 my $overwrite_local = 0;
445 if ($mby && -f $mby && -M _ <= 60 && -s _ > 0) {
446 my $mtime = localtime((stat _)[9]);
447 my $prompt = qq{Found $mby as of $mtime
448
c049f953 449I\'d use that as a database of CPAN sites. If that is OK for you,
450please answer 'y', but if you want me to get a new database now,
451please answer 'n' to the following question.
d8773709 452
c049f953 453Shall I use the local database in $mby?};
d8773709 454 my $ans = prompt($prompt,"y");
455 $overwrite_local = 1 unless $ans =~ /^y/i;
456 }
de34a54b 457 while ($mby) {
d8773709 458 if ($overwrite_local) {
9ddc4ed0 459 print qq{Trying to overwrite $mby\n};
d8773709 460 $mby = CPAN::FTP->localize($m,$mby,3);
461 $overwrite_local = 0;
462 } elsif ( ! -f $mby ){
9ddc4ed0 463 print qq{You have no $mby\n I\'m trying to fetch one\n};
36263cb3 464 $mby = CPAN::FTP->localize($m,$mby,3);
911a92db 465 } elsif (-M $mby > 60 && $loopcount == 0) {
9ddc4ed0 466 print qq{Your $mby is older than 60 days,\n I\'m trying to fetch one\n};
36263cb3 467 $mby = CPAN::FTP->localize($m,$mby,3);
911a92db 468 $loopcount++;
36263cb3 469 } elsif (-s $mby == 0) {
9ddc4ed0 470 print qq{You have an empty $mby,\n I\'m trying to fetch one\n};
36263cb3 471 $mby = CPAN::FTP->localize($m,$mby,3);
472 } else {
473 last;
474 }
09d9d230 475 }
476 read_mirrored_by($mby);
de34a54b 477 bring_your_own();
09d9d230 478}
479
5f05dabc 480sub find_exe {
481 my($exe,$path) = @_;
55e314ee 482 my($dir);
483 #warn "in find_exe exe[$exe] path[@$path]";
5f05dabc 484 for $dir (@$path) {
5de3f0da 485 my $abs = File::Spec->catfile($dir,$exe);
13bc20ff 486 if (($abs = MM->maybe_command($abs))) {
5f05dabc 487 return $abs;
488 }
489 }
490}
491
f610777f 492sub picklist {
493 my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
494 $default ||= '';
495
5fc0f0f6 496 my $pos = 0;
f610777f 497
498 my @nums;
499 while (1) {
ec385757 500
5fc0f0f6 501 # display, at most, 15 items at a time
502 my $limit = $#{ $items } - $pos;
503 $limit = 15 if $limit > 15;
504
505 # show the next $limit items, get the new position
506 $pos = display_some($items, $limit, $pos);
507 $pos = 0 if $pos >= @$items;
508
509 my $num = prompt($prompt,$default);
510
511 @nums = split (' ', $num);
512 my $i = scalar @$items;
513 (warn "invalid items entered, try again\n"), next
514 if grep (/\D/ || $_ < 1 || $_ > $i, @nums);
515 if ($require_nonempty) {
516 (warn "$empty_warning\n");
517 }
518 print "\n";
519
520 # a blank line continues...
521 next unless @nums;
522 last;
f610777f 523 }
f610777f 524 for (@nums) { $_-- }
525 @{$items}[@nums];
526}
527
ec385757 528sub display_some {
529 my ($items, $limit, $pos) = @_;
530 $pos ||= 0;
531
532 my @displayable = @$items[$pos .. ($pos + $limit)];
533 for my $item (@displayable) {
534 printf "(%d) %s\n", ++$pos, $item;
535 }
5fc0f0f6 536 printf("%d more items, hit SPACE RETURN to show them\n",
537 (@$items - $pos)
538 )
539 if $pos < @$items;
ec385757 540 return $pos;
541}
542
5f05dabc 543sub read_mirrored_by {
de34a54b 544 my $local = shift or return;
9ddc4ed0 545 my(%all,$url,$expected_size,$default,$ans,$host,
546 $dst,$country,$continent,@location);
05454584 547 my $fh = FileHandle->new;
548 $fh->open($local) or die "Couldn't open $local: $!";
f14b5cec 549 local $/ = "\012";
05454584 550 while (<$fh>) {
5f05dabc 551 ($host) = /^([\w\.\-]+)/ unless defined $host;
552 next unless defined $host;
553 next unless /\s+dst_(dst|location)/;
554 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
555 ($continent, $country) = @location[-1,-2];
556 $continent =~ s/\s\(.*//;
f610777f 557 $continent =~ s/\W+$//; # if Jarkko doesn't know latitude/longitude
5f05dabc 558 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
559 next unless $host && $dst && $continent && $country;
560 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
561 undef $host;
562 $dst=$continent=$country="";
563 }
05454584 564 $fh->close;
5f05dabc 565 $CPAN::Config->{urllist} ||= [];
f610777f 566 my(@previous_urls);
567 if (@previous_urls = @{$CPAN::Config->{urllist}}) {
5f05dabc 568 $CPAN::Config->{urllist} = [];
5f05dabc 569 }
f610777f 570
9ddc4ed0 571 print $prompts{urls_intro};
5f05dabc 572
f610777f 573 my (@cont, $cont, %cont, @countries, @urls, %seen);
574 my $no_previous_warn =
575 "Sorry! since you don't have any existing picks, you must make a\n" .
576 "geographic selection.";
577 @cont = picklist([sort keys %all],
578 "Select your continent (or several nearby continents)",
579 '',
580 ! @previous_urls,
581 $no_previous_warn);
582
583
584 foreach $cont (@cont) {
585 my @c = sort keys %{$all{$cont}};
586 @cont{@c} = map ($cont, 0..$#c);
587 @c = map ("$_ ($cont)", @c) if @cont > 1;
588 push (@countries, @c);
5f05dabc 589 }
f610777f 590
591 if (@countries) {
592 @countries = picklist (\@countries,
593 "Select your country (or several nearby countries)",
594 '',
595 ! @previous_urls,
596 $no_previous_warn);
597 %seen = map (($_ => 1), @previous_urls);
598 # hmmm, should take list of defaults from CPAN::Config->{'urllist'}...
599 foreach $country (@countries) {
600 (my $bare_country = $country) =~ s/ \(.*\)//;
601 my @u = sort keys %{$all{$cont{$bare_country}}{$bare_country}};
602 @u = grep (! $seen{$_}, @u);
603 @u = map ("$_ ($bare_country)", @u)
604 if @countries > 1;
605 push (@urls, @u);
606 }
607 }
608 push (@urls, map ("$_ (previous pick)", @previous_urls));
5fc0f0f6 609 my $prompt = "Select as many URLs as you like (by number),
610put them on one line, separated by blanks, e.g. '1 4 5'";
f610777f 611 if (@previous_urls) {
612 $default = join (' ', ((scalar @urls) - (scalar @previous_urls) + 1) ..
613 (scalar @urls));
614 $prompt .= "\n(or just hit RETURN to keep your previous picks)";
615 }
616
617 @urls = picklist (\@urls, $prompt, $default);
618 foreach (@urls) { s/ \(.*\)//; }
de34a54b 619 push @{$CPAN::Config->{urllist}}, @urls;
620}
f610777f 621
de34a54b 622sub bring_your_own {
623 my %seen = map (($_ => 1), @{$CPAN::Config->{urllist}});
624 my($ans,@urls);
f610777f 625 do {
de34a54b 626 my $prompt = "Enter another URL or RETURN to quit:";
627 unless (%seen) {
628 $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
629
630Please enter your CPAN site:};
631 }
632 $ans = prompt ($prompt, "");
f610777f 633
634 if ($ans) {
de34a54b 635 $ans =~ s|/?\z|/|; # has to end with one slash
f610777f 636 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
637 if ($ans =~ /^\w+:\/./) {
8d97e4a1 638 push @urls, $ans unless $seen{$ans}++;
de34a54b 639 } else {
8d97e4a1 640 printf(qq{"%s" doesn\'t look like an URL at first sight.
641I\'ll ignore it for now.
642You can add it to your %s
643later if you\'re sure it\'s right.\n},
644 $ans,
645 $INC{'CPAN/MyConfig.pm'} || $INC{'CPAN/Config.pm'} || "configuration file",
646 );
f610777f 647 }
648 }
de34a54b 649 } while $ans || !%seen;
f610777f 650
651 push @{$CPAN::Config->{urllist}}, @urls;
652 # xxx delete or comment these out when you're happy that it works
653 print "New set of picks:\n";
654 map { print " $_\n" } @{$CPAN::Config->{urllist}};
5f05dabc 655}
656
f915a99a 657
658sub _strip_spaces {
659 $_[0] =~ s/^\s+//; # no leading spaces
660 $_[0] =~ s/\s+\z//; # no trailing spaces
661}
662
663
664sub prompt ($;$) {
665 my $ans = _real_prompt(@_);
666
667 _strip_spaces($ans);
668
669 return $ans;
670}
671
672
673sub prompt_no_strip ($;$) {
674 return _real_prompt(@_);
675}
676
677
9ddc4ed0 678BEGIN {
679
680my @prompts = (
681
682manual_config => qq[
683
684CPAN is the world-wide archive of perl resources. It consists of about
685100 sites that all replicate the same contents all around the globe.
686Many countries have at least one CPAN site already. The resources
687found on CPAN are easily accessible with the CPAN.pm module. If you
688want to use CPAN.pm, you have to configure it properly.
689
690If you do not want to enter a dialog now, you can answer 'no' to this
691question and I\'ll try to autoconfigure. (Note: you can revisit this
692dialog anytime later by typing 'o conf init' at the cpan prompt.)
693
694],
695
696config_intro => qq{
697
698The following questions are intended to help you with the
699configuration. The CPAN module needs a directory of its own to cache
700important index files and maybe keep a temporary mirror of CPAN files.
701This may be a site-wide directory or a personal directory.
702
703},
704
705# cpan_home => qq{ },
706
707cpan_home_where => qq{
708
709First of all, I\'d like to create this directory. Where?
710
711},
712
713keep_source_where => qq{
714
715If you like, I can cache the source files after I build them. Doing
716so means that, if you ever rebuild that module in the future, the
717files will be taken from the cache. The tradeoff is that it takes up
718space. How much space would you like to allocate to this cache? (If
719you don\'t want me to keep a cache, answer 0.)
720
721},
722
723build_cache_intro => qq{
724
725How big should the disk cache be for keeping the build directories
726with all the intermediate files\?
727
728},
729
730build_cache =>
731"Cache size for build directory (in MB)?",
732
733
734scan_cache_intro => qq{
735
736By default, each time the CPAN module is started, cache scanning is
737performed to keep the cache size in sync. To prevent this, answer
738'never'.
739
740},
741
742scan_cache => "Perform cache scanning (atstart or never)?",
743
744cache_metadata => qq{
745
746To considerably speed up the initial CPAN shell startup, it is
747possible to use Storable to create a cache of metadata. If Storable
748is not available, the normal index mechanism will be used.
749
750},
751
752term_is_latin => qq{
753
754The next option deals with the charset (aka character set) your
755terminal supports. In general, CPAN is English speaking territory, so
756the charset does not matter much, but some of the aliens out there who
757upload their software to CPAN bear names that are outside the ASCII
758range. If your terminal supports UTF-8, you should say no to the next
759question. If it supports ISO-8859-1 (also known as LATIN1) then you
760should say yes. If it supports neither, your answer does not matter
761because you will not be able to read the names of some authors
762anyway. If you answer no, names will be output in UTF-8.
763
764},
765
c9869e1c 766histfile_intro => qq{
9ddc4ed0 767
768If you have one of the readline packages (Term::ReadLine::Perl,
769Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
770shell will have history support. The next two questions deal with the
771filename of the history file and with its size. If you do not want to
772set this variable, please hit SPACE RETURN to the following question.
773
774},
775
c9869e1c 776histfile => qq{File to save your history?},
777
9ddc4ed0 778show_upload_date_intro => qq{
779
780The 'd' and the 'm' command normally only show you information they
781have in their in-memory database and thus will never connect to the
782internet. If you set the 'show_upload_date' variable to true, 'm' and
783'd' will additionally show you the upload date of the module or
784distribution. Per default this feature is off because it may require a
785net connection to get at the upload date.
786
787},
788
789show_upload_date =>
790"Always try to show upload date with 'd' and 'm' command (yes/no)?",
791
792prerequisites_policy_intro => qq{
793
794The CPAN module can detect when a module which you are trying to build
795depends on prerequisites. If this happens, it can build the
796prerequisites for you automatically ('follow'), ask you for
797confirmation ('ask'), or just ignore them ('ignore'). Please set your
798policy to one of the three values.
799
800},
801
802prerequisites_policy =>
c9869e1c 803"Policy on building prerequisites (follow, ask or ignore)?",
9ddc4ed0 804
805external_progs => qq{
806
807The CPAN module will need a few external programs to work properly.
808Please correct me, if I guess the wrong path for a program. Don\'t
809panic if you do not have some of them, just press ENTER for those. To
810disable the use of a download program, you can type a space followed
811by ENTER.
812
813},
814
815prefer_installer_intro => qq{
816
817When you have Module::Build installed and a module comes with both a
818Makefile.PL and a Build.PL, which shall have precedence? The two
819installer modules we have are the old and well established
820ExtUtils::MakeMaker (for short: EUMM) understands the Makefile.PL and
821the next generation installer Module::Build (MB) works with the
822Build.PL.
823
824},
825
826prefer_installer =>
827qq{In case you could choose, which installer would you prefer (EUMM or MB)?},
828
829makepl_arg_intro => qq{
830
831Every Makefile.PL is run by perl in a separate process. Likewise we
832run \'make\' and \'make install\' in separate processes. If you have
833any parameters \(e.g. PREFIX, LIB, UNINST or the like\) you want to
834pass to the calls, please specify them here.
835
836If you don\'t understand this question, just press ENTER.
837},
838
839makepl_arg => qq{
840Parameters for the 'perl Makefile.PL' command?
841Typical frequently used settings:
842
843 PREFIX=~/perl # non-root users (please see manual for more hints)
844
845Your choice: },
846
847make_arg => qq{Parameters for the 'make' command?
848Typical frequently used setting:
849
850 -j3 # dual processor system
851
852Your choice: },
853
854
855make_install_make_command => qq{Do you want to use a different make command for 'make install'?
856Cautious people will probably prefer:
857
858 su root -c make
859or
860 sudo make
861or
862 /path1/to/sudo -u admin_account /path2/to/make
863
864or some such. Your choice: },
865
866
867make_install_arg => qq{Parameters for the 'make install' command?
868Typical frequently used setting:
869
870 UNINST=1 # to always uninstall potentially conflicting files
871
872Your choice: },
873
874
875mbuildpl_arg_intro => qq{
876
877The next questions deal with Module::Build support.
878
879A Build.PL is run by perl in a separate process. Likewise we run
880'./Build' and './Build install' in separate processes. If you have any
881parameters you want to pass to the calls, please specify them here.
882
883},
884
885mbuildpl_arg => qq{Parameters for the 'perl Build.PL' command?
886Typical frequently used settings:
887
888 --install_base /home/xxx # different installation directory
889
890Your choice: },
891
892mbuild_arg => qq{Parameters for the './Build' command?
893Setting might be:
894
895 --extra_linker_flags -L/usr/foo/lib # non-standard library location
896
897Your choice: },
898
899
900mbuild_install_build_command => qq{Do you want to use a different command for './Build install'?
901Sudo users will probably prefer:
902
903 su root -c ./Build
904or
905 sudo ./Build
906or
907 /path1/to/sudo -u admin_account ./Build
908
909or some such. Your choice: },
910
911
912mbuild_install_arg => qq{Parameters for the './Build install' command?
913Typical frequently used setting:
914
915 --uninst 1 # uninstall conflicting files
916
917Your choice: },
918
919
920
921inactivity_timeout_intro => qq{
922
923Sometimes you may wish to leave the processes run by CPAN alone
924without caring about them. Because the Makefile.PL sometimes contains
925question you\'re expected to answer, you can set a timer that will
926kill a 'perl Makefile.PL' process after the specified time in seconds.
927
928If you set this value to 0, these processes will wait forever. This is
929the default and recommended setting.
930
931},
932
933inactivity_timeout =>
934qq{Timeout for inactivity during {Makefile,Build}.PL? },
935
936
c9869e1c 937proxy_intro => qq{
9ddc4ed0 938
939If you\'re accessing the net via proxies, you can specify them in the
940CPAN configuration or via environment variables. The variable in
941the \$CPAN::Config takes precedence.
942
943},
944
945proxy_user => qq{
946
947If your proxy is an authenticating proxy, you can store your username
948permanently. If you do not want that, just press RETURN. You will then
949be asked for your username in every future session.
950
951},
952
953proxy_pass => qq{
954
955Your password for the authenticating proxy can also be stored
956permanently on disk. If this violates your security policy, just press
957RETURN. You will then be asked for the password in every future
958session.
959
960},
961
962urls_intro => qq{
963
964Now we need to know where your favorite CPAN sites are located. Push
965a few sites onto the array (just in case the first on the array won\'t
966work). If you are mirroring CPAN to your local workstation, specify a
967file: URL.
968
969First, pick a nearby continent and country (you can pick several of
970each, separated by spaces, or none if you just want to keep your
971existing selections). Then, you will be presented with a list of URLs
972of CPAN mirrors in the countries you selected, along with previously
973selected URLs. Select some of those URLs, or just keep the old list.
974Finally, you will be prompted for any extra URLs -- file:, ftp:, or
975http: -- that host a CPAN mirror.
976
977},
978
979password_warn => qq{
980
981Warning: Term::ReadKey seems not to be available, your password will
982be echoed to the terminal!
983
984},
985
986);
987
988die "Coding error in \@prompts declaration. Odd number of elements, above"
989 if (@prompts % 2);
990
991%prompts = @prompts;
992
993if (scalar(keys %prompts) != scalar(@prompts)/2) {
994
995 my %already;
996
997 for my $item (0..$#prompts) {
998 next if $item % 2;
999 die "$prompts[$item] is duplicated\n"
1000 if $already{$prompts[$item]}++;
1001 }
1002
1003}
1004
1005}
1006
5f05dabc 10071;