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