1 package CPAN::Mirrored::By;
11 package CPAN::FirstTime;
14 use ExtUtils::MakeMaker qw(prompt);
16 use vars qw($VERSION);
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;};
42 my($ans,$default,$local,$cont,$url,$expected_size);
46 The CPAN module needs a directory of its own to cache important
47 index files and maybe keep a temporary mirror of CPAN files. This may
48 be a site-wide directory or a personal directory.
51 my $cpan_home = $CPAN::Config->{cpan_home} || MM->catdir($ENV{HOME}, ".cpan");
55 I see you already have a directory
57 Shall we use it as the general CPAN build and cache directory?
63 First of all, I\'d like to create this directory. Where?
68 $default = $cpan_home;
69 $ans = prompt("CPAN build and cache directory?",$default);
70 File::Path::mkpath($ans); # dies if it can't
71 $CPAN::Config->{cpan_home} = $ans;
75 If you want, I can keep the source files after a build in the cpan
76 home directory. If you choose so then future builds will take the
77 files from there. If you don\'t want to keep them, answer 0 to the
82 $CPAN::Config->{keep_source_where} = MM->catdir($CPAN::Config->{cpan_home},"sources");
83 $CPAN::Config->{build_dir} = MM->catdir($CPAN::Config->{cpan_home},"build");
87 How big should the disk cache be for keeping the build directories
88 with all the intermediate files?
92 $default = $CPAN::Config->{build_cache} || 10;
93 $ans = prompt("Cache size for build directory (in MB)?", $default);
94 $CPAN::Config->{build_cache} = $ans;
96 # XXX This the time when we refetch the index files (in days)
97 $CPAN::Config->{'index_expire'} = 1;
101 The CPAN module will need a few external programs to work
102 properly. Please correct me, if I guess the wrong path for a program.
106 my(@path) = split($Config{path_sep},$ENV{PATH});
108 for $prog (qw/gzip tar unzip make/){
109 my $path = $CPAN::Config->{$prog} || find_exe($prog,[@path]) || $prog;
110 $ans = prompt("Where is your $prog program?",$path) || $path;
111 $CPAN::Config->{$prog} = $ans;
113 my $path = $CPAN::Config->{'pager'} ||
114 $ENV{PAGER} || find_exe("less",[@path]) ||
115 find_exe("more",[@path]) || "more";
116 $ans = prompt("What is your favorite pager program?",$path) || $path;
117 $CPAN::Config->{'pager'} = $ans;
120 Every Makefile.PL is run by perl in a seperate process. Likewise we
121 run \'make\' and \'make install\' in processes. If you have any parameters
122 \(e.g. PREFIX, INSTALLPRIVLIB, UNINST or the like\) you want to pass to
123 the calls, please specify them here.
127 $default = $CPAN::Config->{makepl_arg} || "";
128 $CPAN::Config->{makepl_arg} =
129 prompt("Parameters for the 'perl Makefile.PL' command?",$default);
130 $default = $CPAN::Config->{make_arg} || "";
131 $CPAN::Config->{make_arg} = prompt("Parameters for the 'make' command?",$default);
133 $default = $CPAN::Config->{make_install_arg} || $CPAN::Config->{make_arg} || "";
134 $CPAN::Config->{make_install_arg} =
135 prompt("Parameters for the 'make install' command?",$default);
137 $local = 'MIRRORED.BY';
138 if (@{$CPAN::Config->{urllist}||[]}) {
140 I found a list of URLs in CPAN::Config and will use this.
141 You can change it later with the 'o conf' command.
144 } elsif (-f $local) { # if they really have a MIRRORED.BY in the
145 # current directory, we can't help
146 read_mirrored_by($local);
148 $CPAN::Config->{urllist} ||= [];
149 while (! @{$CPAN::Config->{urllist}}) {
151 We need to know the URL of your favorite CPAN site.
152 Please enter it here: };
155 push @{$CPAN::Config->{urllist}}, $_ if $_;
159 # We don't ask that now, it will be noticed in time....
160 $CPAN::Config->{'inhibit_startup_message'} = 0;
163 CPAN::Config->commit($configpm);
172 my $abs = $MY->catfile($dir,$exe);
173 if ($MY->maybe_command($abs)) {
179 sub read_mirrored_by {
181 my(%all,$url,$expected_size,$default,$ans,$host,$dst,$country,$continent,@location);
182 open FH, $local or die "Couldn't open $local: $!";
184 ($host) = /^([\w\.\-]+)/ unless defined $host;
185 next unless defined $host;
186 next unless /\s+dst_(dst|location)/;
187 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
188 ($continent, $country) = @location[-1,-2];
189 $continent =~ s/\s\(.*//;
190 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
191 next unless $host && $dst && $continent && $country;
192 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
194 $dst=$continent=$country="";
196 $CPAN::Config->{urllist} ||= [];
197 if ($expected_size = @{$CPAN::Config->{urllist}}) {
198 for $url (@{$CPAN::Config->{urllist}}) {
199 # sanity check, scheme+colon, not "q" there:
200 next unless $url =~ /^\w+:\/./;
201 $all{"[From previous setup]"}{"found URL"}{$url}=CPAN::Mirrored::By->new('[From previous setup]','found URL',$url);
203 $CPAN::Config->{urllist} = [];
210 Now we need to know, where your favorite CPAN sites are located. Push
211 a few sites onto the array (just in case the first on the array won\'t
212 work). If you are mirroring CPAN to your local workstation, specify a
215 You can enter the number in front of the URL on the next screen, a
216 file:, ftp: or http: URL, or "q" to finish selecting.
220 $ans = prompt("Press RETURN to continue");
226 my $pipe = -t *STDIN ? "| $CPAN::Config->{'pager'}" : ">/dev/null";
227 my(@valid,$previous_best);
230 my($cont,$country,$url,$item);
231 my(@cont) = sort keys %all;
234 for $country (sort {lc $a cmp lc $b} keys %{$all{$cont}}) {
235 for $url (sort {lc $a cmp lc $b} keys %{$all{$cont}{$country}}) {
242 if ($cont =~ /^\[/) {
243 $previous_best ||= $item;
245 push @valid, $all{$cont}{$country}{$url};
252 $previous_best ||= 1;
254 @{$CPAN::Config->{urllist}} >= $expected_size ? "q" : $previous_best;
256 "\nSelect an$other ftp or file URL or a number (q to finish)",
261 my $this = $valid[$ans-1];
262 my($con,$cou,$url) = ($this->con,$this->cou,$this->url);
263 push @{$CPAN::Config->{urllist}}, $url unless $seen{$url}++;
264 delete $all{$con}{$cou}{$url};
265 # print "Was a number [$ans] con[$con] cou[$cou] url[$url]\n";
266 } elsif (@{$CPAN::Config->{urllist}} && $ans =~ /^q/i) {
269 $ans =~ s|/?$|/|; # has to end with one slash
270 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
271 if ($ans =~ /^\w+:\/./) {
272 push @{$CPAN::Config->{urllist}}, $ans unless $seen{$ans}++;
274 print qq{"$ans" doesn\'t look like an URL at first sight.
275 I\'ll ignore it for now. You can add it to lib/CPAN/Config.pm
276 later and report a bug in my Makefile.PL to me (andreas koenig).