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