1 package CPAN::Mirrored::By;
7 sub continent { shift->[0] }
8 sub country { shift->[1] }
11 package CPAN::FirstTime;
14 use ExtUtils::MakeMaker qw(prompt);
16 use vars qw($VERSION);
17 $VERSION = substr q$Revision: 1.13 $, 10;
21 CPAN::FirstTime - Utility for CPAN::Config file Initialization
25 CPAN::FirstTime::init()
29 The init routine asks a few questions and writes a CPAN::Config
30 file. Nothing special.
39 eval {require CPAN::Config;};
44 my($ans,$default,$local,$cont,$url,$expected_size);
52 The CPAN module needs a directory of its own to cache important
53 index files and maybe keep a temporary mirror of CPAN files. This may
54 be a site-wide directory or a personal directory.
57 my $cpan_home = $CPAN::Config->{cpan_home} || MM->catdir($ENV{HOME}, ".cpan");
61 I see you already have a directory
63 Shall we use it as the general CPAN build and cache directory?
69 First of all, I\'d like to create this directory. Where?
74 $default = $cpan_home;
75 until (-d ($ans = prompt("CPAN build and cache directory?",$default)) && -w _) {
76 print "Couldn't find directory $ans
77 or directory is not writable. Please retry.\n";
79 File::Path::mkpath($ans); # dies if it can't
80 $CPAN::Config->{cpan_home} = $ans;
84 If you want, I can keep the source files after a build in the cpan
85 home directory. If you choose so then future builds will take the
86 files from there. If you don\'t want to keep them, answer 0 to the
91 $CPAN::Config->{keep_source_where} = MM->catdir($CPAN::Config->{cpan_home},"sources");
92 $CPAN::Config->{build_dir} = MM->catdir($CPAN::Config->{cpan_home},"build");
95 # Cache size, Index expire
100 How big should the disk cache be for keeping the build directories
101 with all the intermediate files?
105 $default = $CPAN::Config->{build_cache} || 10;
106 $ans = prompt("Cache size for build directory (in MB)?", $default);
107 $CPAN::Config->{build_cache} = $ans;
109 # XXX This the time when we refetch the index files (in days)
110 $CPAN::Config->{'index_expire'} = 1;
118 The CPAN module will need a few external programs to work
119 properly. Please correct me, if I guess the wrong path for a program.
123 my(@path) = split($Config{path_sep},$ENV{PATH});
125 for $prog (qw/gzip tar unzip make lynx ftp/){
126 my $path = $CPAN::Config->{$prog} || find_exe($prog,[@path]) || $prog;
127 $ans = prompt("Where is your $prog program?",$path) || $path;
128 $CPAN::Config->{$prog} = $ans;
130 my $path = $CPAN::Config->{'pager'} ||
131 $ENV{PAGER} || find_exe("less",[@path]) ||
132 find_exe("more",[@path]) || "more";
133 $ans = prompt("What is your favorite pager program?",$path) || $path;
134 $CPAN::Config->{'pager'} = $ans;
135 $path = $CPAN::Config->{'shell'} || $ENV{SHELL} || "";
136 $ans = prompt("What is your favorite shell?",$path) || $path;
139 # Arguments to make etc.
144 Every Makefile.PL is run by perl in a separate process. Likewise we
145 run \'make\' and \'make install\' in processes. If you have any parameters
146 \(e.g. PREFIX, INSTALLPRIVLIB, UNINST or the like\) you want to pass to
147 the calls, please specify them here.
151 $default = $CPAN::Config->{makepl_arg} || "";
152 $CPAN::Config->{makepl_arg} =
153 prompt("Parameters for the 'perl Makefile.PL' command?",$default);
154 $default = $CPAN::Config->{make_arg} || "";
155 $CPAN::Config->{make_arg} = prompt("Parameters for the 'make' command?",$default);
157 $default = $CPAN::Config->{make_install_arg} || $CPAN::Config->{make_arg} || "";
158 $CPAN::Config->{make_install_arg} =
159 prompt("Parameters for the 'make install' command?",$default);
167 Sometimes you may wish to leave the processes run by CPAN alone
168 without caring about them. As sometimes the Makefile.PL contains
169 question you\'re expected to answer, you can set a timer that will
170 kill a 'perl Makefile.PL' process after the specified time in seconds.
172 If you set this value to 0, these processes will wait forever.
176 $default = $CPAN::Config->{inactivity_timeout} || 0;
177 $CPAN::Config->{inactivity_timeout} =
178 prompt("Timout for inacivity during Makefile.PL?",$default);
185 $local = 'MIRRORED.BY';
186 if (@{$CPAN::Config->{urllist}||[]}) {
188 I found a list of URLs in CPAN::Config and will use this.
189 You can change it later with the 'o conf' command.
192 } elsif (-f $local) { # if they really have a wrong MIRRORED.BY in
193 # the current directory, we can't help
194 read_mirrored_by($local);
196 $CPAN::Config->{urllist} ||= [];
197 while (! @{$CPAN::Config->{urllist}}) {
199 We need to know the URL of your favorite CPAN site.
200 Please enter it here: };
203 push @{$CPAN::Config->{urllist}}, $_ if $_;
209 If you\'re accessing the net via proxies, you can specify them in the
210 CPAN configuration or via environment variables. The variable in
211 the \$CPAN::Config takes precedence.
215 for (qw/ftp_proxy http_proxy no_proxy/) {
216 $default = $CPAN::Config->{$_} || $ENV{$_};
217 $CPAN::Config->{$_} = prompt("Your $_?",$default);
220 # We don't ask that now, it will be noticed in time....
221 $CPAN::Config->{'inhibit_startup_message'} = 0;
224 CPAN::Config->commit($configpm);
233 my $abs = $MY->catfile($dir,$exe);
234 if ($MY->maybe_command($abs)) {
240 sub read_mirrored_by {
242 my(%all,$url,$expected_size,$default,$ans,$host,$dst,$country,$continent,@location);
243 open FH, $local or die "Couldn't open $local: $!";
245 ($host) = /^([\w\.\-]+)/ unless defined $host;
246 next unless defined $host;
247 next unless /\s+dst_(dst|location)/;
248 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
249 ($continent, $country) = @location[-1,-2];
250 $continent =~ s/\s\(.*//;
251 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
252 next unless $host && $dst && $continent && $country;
253 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
255 $dst=$continent=$country="";
257 $CPAN::Config->{urllist} ||= [];
258 if ($expected_size = @{$CPAN::Config->{urllist}}) {
259 for $url (@{$CPAN::Config->{urllist}}) {
260 # sanity check, scheme+colon, not "q" there:
261 next unless $url =~ /^\w+:\/./;
262 $all{"[From previous setup]"}{"found URL"}{$url}=CPAN::Mirrored::By->new('[From previous setup]','found URL',$url);
264 $CPAN::Config->{urllist} = [];
271 Now we need to know, where your favorite CPAN sites are located. Push
272 a few sites onto the array (just in case the first on the array won\'t
273 work). If you are mirroring CPAN to your local workstation, specify a
276 You can enter the number in front of the URL on the next screen, a
277 file:, ftp: or http: URL, or "q" to finish selecting.
281 $ans = prompt("Press RETURN to continue");
287 my $pipe = -t *STDIN ? "| $CPAN::Config->{'pager'}" : ">/dev/null";
288 my(@valid,$previous_best);
291 my($cont,$country,$url,$item);
292 my(@cont) = sort keys %all;
295 for $country (sort {lc $a cmp lc $b} keys %{$all{$cont}}) {
296 for $url (sort {lc $a cmp lc $b} keys %{$all{$cont}{$country}}) {
303 if ($cont =~ /^\[/) {
304 $previous_best ||= $item;
306 push @valid, $all{$cont}{$country}{$url};
313 $previous_best ||= 1;
315 @{$CPAN::Config->{urllist}} >= $expected_size ? "q" : $previous_best;
317 "\nSelect an$other ftp or file URL or a number (q to finish)",
322 my $this = $valid[$ans-1];
323 my($con,$cou,$url) = ($this->continent,$this->country,$this->url);
324 push @{$CPAN::Config->{urllist}}, $url unless $seen{$url}++;
325 delete $all{$con}{$cou}{$url};
326 # print "Was a number [$ans] con[$con] cou[$cou] url[$url]\n";
327 } elsif (@{$CPAN::Config->{urllist}} && $ans =~ /^q/i) {
330 $ans =~ s|/?$|/|; # has to end with one slash
331 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
332 if ($ans =~ /^\w+:\/./) {
333 push @{$CPAN::Config->{urllist}}, $ans unless $seen{$ans}++;
335 print qq{"$ans" doesn\'t look like an URL at first sight.
336 I\'ll ignore it for now. You can add it to lib/CPAN/Config.pm
337 later and report a bug in my Makefile.PL to me (andreas koenig).