1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 package CPAN::Mirrored::By;
9 sub continent { shift->[0] }
10 sub country { shift->[1] }
11 sub url { shift->[2] }
13 package CPAN::FirstTime;
16 use ExtUtils::MakeMaker ();
18 use File::Basename ();
21 use vars qw($VERSION $urllist);
26 CPAN::FirstTime - Utility for CPAN::Config file Initialization
30 CPAN::FirstTime::init()
34 The init routine asks a few questions and writes a CPAN/Config.pm or
35 CPAN/MyConfig.pm file (depending on what it is currently using).
37 In the following all questions and explanations regarding config
38 variables are collected.
42 # down until the next =back the manpage must be parsed by the program
43 # because the text is used in the init dialogues.
49 Normally CPAN.pm keeps config variables in memory and changes need to
50 be saved in a separate 'o conf commit' command to make them permanent
51 between sessions. If you set the 'auto_commit' option to true, changes
52 to a config variable are always automatically committed to disk.
54 Always commit changes to config variables to disk?
58 CPAN.pm can limit the size of the disk area for keeping the build
59 directories with all the intermediate files.
61 Cache size for build directory (in MB)?
65 Directory where the build process takes place?
69 Until version 1.88 CPAN.pm never trusted the contents of the build_dir
70 directory between sessions. Since 1.88_58 CPAN.pm has a YAML-based
71 mechanism that makes it possible to share the contents of the
72 build_dir/ directory between different sessions with the same version
73 of perl. People who prefer to test things several days before
74 installing will like this feature because it safes a lot of time.
76 If you say yes to the following question, CPAN will try to store
77 enough information about the build process so that it can pick up in
78 future sessions at the same state of affairs as it left a previous
81 Store and re-use state information about distributions between
84 =item build_requires_install_policy
86 When a module declares another one as a 'build_requires' prerequisite
87 this means that the other module is only needed for building or
88 testing the module but need not be installed permanently. In this case
89 you may wish to install that other module nonetheless or just keep it
90 in the 'build_dir' directory to have it available only temporarily.
91 Installing saves time on future installations but makes the perl
94 You can choose if you want to always install (yes), never install (no)
95 or be always asked. In the latter case you can set the default answer
96 for the question to yes (ask/yes) or no (ask/no).
98 Policy on installing 'build_requires' modules (yes, no, ask/yes,
103 To considerably speed up the initial CPAN shell startup, it is
104 possible to use Storable to create a cache of metadata. If Storable is
105 not available, the normal index mechanism will be used.
107 Note: this mechanism is not used when use_sqlite is on and SQLLite is
110 Cache metadata (yes/no)?
114 CPAN packages can be digitally signed by authors and thus verified
115 with the security provided by strong cryptography. The exact mechanism
116 is defined in the Module::Signature module. While this is generally
117 considered a good thing, it is not always convenient to the end user
118 to install modules that are signed incorrectly or where the key of the
119 author is not available or where some prerequisite for
120 Module::Signature has a bug and so on.
122 With the check_sigs parameter you can turn signature checking on and
123 off. The default is off for now because the whole tool chain for the
124 functionality is not yet considered mature by some. The author of
125 CPAN.pm would recommend setting it to true most of the time and
126 turning it off only if it turns out to be annoying.
128 Note that if you do not have Module::Signature installed, no signature
129 checks will be performed at all.
131 Always try to check and verify signatures if a SIGNATURE file is in
132 the package and Module::Signature is installed (yes/no)?
134 =item colorize_output
136 When you have Term::ANSIColor installed, you can turn on colorized
137 output to have some visual differences between normal CPAN.pm output,
138 warnings, debugging output, and the output of the modules being
139 installed. Set your favorite colors after some experimenting with the
140 Term::ANSIColor module.
142 Do you want to turn on colored output?
146 Color for normal output?
154 Color for debugging messages?
156 =item commandnumber_in_prompt
158 The prompt of the cpan shell can contain the current command number
159 for easier tracking of the session or be a plain string.
161 Do you want the command number in the prompt (yes/no)?
163 =item connect_to_internet_ok
165 If you have never defined your own C<urllist> in your configuration
166 then C<CPAN.pm> will be hesitant to use the built in default sites for
167 downloading. It will ask you once per session if a connection to the
168 internet is OK and only if you say yes, it will try to connect. But to
169 avoid this question, you can choose your favorite download sites once
170 and get away with it. Or, if you have no favorite download sites
171 answer yes to the following question.
173 If no urllist has been chosen yet, would you prefer CPAN.pm to connect
174 to the built-in default sites without asking? (yes/no)?
178 Shall we always set the FTP_PASSIVE environment variable when dealing
179 with ftp download (yes/no)?
181 =item ftpstats_period
183 Statistics about downloads are truncated by size and period
186 How many days shall we keep statistics about downloads?
190 Statistics about downloads are truncated by size and period
193 How many items shall we keep in the statistics about downloads?
197 CPAN.pm changes the current working directory often and needs to
198 determine its own current working directory. Per default it uses
199 Cwd::cwd but if this doesn't work on your system for some reason,
200 alternatives can be configured according to the following table:
205 backtickcwd external command cwd
207 Preferred method for determining the current working directory?
209 =item halt_on_failure
211 Normaly, CPAN.pm continues processing the full list of targets and
212 dependencies, even if one of them fails. However, you can specify
213 that CPAN should halt after the first failure.
215 Do you want to halt on failure (yes/no)?
219 If you have one of the readline packages (Term::ReadLine::Perl,
220 Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
221 shell will have history support. The next two questions deal with the
222 filename of the history file and with its size. If you do not want to
223 set this variable, please hit SPACE RETURN to the following question.
225 File to save your history?
229 Number of lines to save?
231 =item inactivity_timeout
233 Sometimes you may wish to leave the processes run by CPAN alone
234 without caring about them. Because the Makefile.PL or the Build.PL
235 sometimes contains question you're expected to answer, you can set a
236 timer that will kill a 'perl Makefile.PL' process after the specified
239 If you set this value to 0, these processes will wait forever. This is
240 the default and recommended setting.
242 Timeout for inactivity during {Makefile,Build}.PL?
246 The CPAN indexes are usually rebuilt once or twice per hour, but the
247 typical CPAN mirror mirrors only once or twice per day. Depending on
248 the quality of your mirror and your desire to be on the bleeding edge,
249 you may want to set the following value to more or less than one day
250 (which is the default). It determines after how many days CPAN.pm
251 downloads new indexes.
253 Let the index expire after how many days?
255 =item inhibit_startup_message
257 When the CPAN shell is started it normally displays a greeting message
258 that contains the running version and the status of readline support.
260 Do you want to turn this message off?
262 =item keep_source_where
264 Unless you are accessing the CPAN on your filesystem via a file: URL,
265 CPAN.pm needs to keep the source files it downloads somewhere. Please
266 supply a directory where the downloaded files are to be kept.
268 Download target directory?
270 =item load_module_verbosity
272 When CPAN.pm loads a module it needs for some optional feature, it
273 usually reports about module name and version. Choose 'v' to get this
274 message, 'none' to suppress it.
276 Verbosity level for loading modules (none or v)?
280 Every Makefile.PL is run by perl in a separate process. Likewise we
281 run 'make' and 'make install' in separate processes. If you have
282 any parameters (e.g. PREFIX, UNINST or the like) you want to
283 pass to the calls, please specify them here.
285 If you don't understand this question, just press ENTER.
287 Typical frequently used settings:
289 PREFIX=~/perl # non-root users (please see manual for more hints)
291 Parameters for the 'perl Makefile.PL' command?
295 Parameters for the 'make' command? Typical frequently used setting:
297 -j3 # dual processor system (on GNU make)
301 =item make_install_arg
303 Parameters for the 'make install' command?
304 Typical frequently used setting:
306 UNINST=1 # to always uninstall potentially conflicting files
310 =item make_install_make_command
312 Do you want to use a different make command for 'make install'?
313 Cautious people will probably prefer:
319 /path1/to/sudo -u admin_account /path2/to/make
321 or some such. Your choice:
325 A Build.PL is run by perl in a separate process. Likewise we run
326 './Build' and './Build install' in separate processes. If you have any
327 parameters you want to pass to the calls, please specify them here.
329 Typical frequently used settings:
331 --install_base /home/xxx # different installation directory
333 Parameters for the 'perl Build.PL' command?
337 Parameters for the './Build' command? Setting might be:
339 --extra_linker_flags -L/usr/foo/lib # non-standard library location
343 =item mbuild_install_arg
345 Parameters for the './Build install' command? Typical frequently used
348 --uninst 1 # uninstall conflicting files
352 =item mbuild_install_build_command
354 Do you want to use a different command for './Build install'? Sudo
355 users will probably prefer:
361 /path1/to/sudo -u admin_account ./Build
363 or some such. Your choice:
367 What is your favorite pager program?
369 =item prefer_installer
371 When you have Module::Build installed and a module comes with both a
372 Makefile.PL and a Build.PL, which shall have precedence?
374 The main two standard installer modules are the old and well
375 established ExtUtils::MakeMaker (for short: EUMM) which uses the
376 Makefile.PL. And the next generation installer Module::Build (MB)
377 which works with the Build.PL (and often comes with a Makefile.PL
378 too). If a module comes only with one of the two we will use that one
379 but if both are supplied then a decision must be made between EUMM and
380 MB. See also http://rt.cpan.org/Ticket/Display.html?id=29235 for a
381 discussion about the right default.
383 Or, as a third option you can choose RAND which will make a random
384 decision (something regular CPAN testers will enjoy).
386 In case you can choose between running a Makefile.PL or a Build.PL,
387 which installer would you prefer (EUMM or MB or RAND)?
391 CPAN.pm can store customized build environments based on regular
392 expressions for distribution names. These are YAML files where the
393 default options for CPAN.pm and the environment can be overridden and
394 dialog sequences can be stored that can later be executed by an
395 Expect.pm object. The CPAN.pm distribution comes with some prefab YAML
396 files that cover sample distributions that can be used as blueprints
397 to store one own prefs. Please check out the distroprefs/ directory of
398 the CPAN.pm distribution to get a quick start into the prefs system.
400 Directory where to store default options/environment/dialogs for
401 building modules that need some customization?
403 =item prerequisites_policy
405 The CPAN module can detect when a module which you are trying to build
406 depends on prerequisites. If this happens, it can build the
407 prerequisites for you automatically ('follow'), ask you for
408 confirmation ('ask'), or just ignore them ('ignore'). Please set your
409 policy to one of the three values.
411 Policy on building prerequisites (follow, ask or ignore)?
413 =item randomize_urllist
415 CPAN.pm can introduce some randomness when using hosts for download
416 that are configured in the urllist parameter. Enter a numeric value
417 between 0 and 1 to indicate how often you want to let CPAN.pm try a
418 random host from the urllist. A value of one specifies to always use a
419 random host as the first try. A value of zero means no randomness at
420 all. Anything in between specifies how often, on average, a random
421 host should be tried first.
427 By default, each time the CPAN module is started, cache scanning is
428 performed to keep the cache size in sync. To prevent this, answer
431 Perform cache scanning (atstart or never)?
435 What is your favorite shell?
437 =item show_unparsable_versions
439 During the 'r' command CPAN.pm finds modules without version number.
440 When the command finishes, it prints a report about this. If you
441 want this report to be very verbose, say yes to the following
444 Show all individual modules that have no $VERSION?
446 =item show_upload_date
448 The 'd' and the 'm' command normally only show you information they
449 have in their in-memory database and thus will never connect to the
450 internet. If you set the 'show_upload_date' variable to true, 'm' and
451 'd' will additionally show you the upload date of the module or
452 distribution. Per default this feature is off because it may require a
453 net connection to get at the upload date.
455 Always try to show upload date with 'd' and 'm' command (yes/no)?
457 =item show_zero_versions
459 During the 'r' command CPAN.pm finds modules with a version number of
460 zero. When the command finishes, it prints a report about this. If you
461 want this report to be very verbose, say yes to the following
464 Show all individual modules that have a $VERSION of zero?
468 When CPAN.pm uses the tar command, which switch for the verbosity
469 shall be used? Choose 'none' for quiet operation, 'v' for file
470 name listing, 'vv' for full listing.
472 Tar command verbosity level (none or v or vv)?
476 The next option deals with the charset (aka character set) your
477 terminal supports. In general, CPAN is English speaking territory, so
478 the charset does not matter much but some CPAN have names that are
479 outside the ASCII range. If your terminal supports UTF-8, you should
480 say no to the next question. If it expects ISO-8859-1 (also known as
481 LATIN1) then you should say yes. If it supports neither, your answer
482 does not matter because you will not be able to read the names of some
483 authors anyway. If you answer no, names will be output in UTF-8.
485 Your terminal expects ISO-8859-1 (yes/no)?
489 When using Term::ReadLine, you can turn ornaments on so that your
490 input stands out against the output from CPAN.pm.
492 Do you want to turn ornaments on?
496 The goal of the CPAN Testers project (http://testers.cpan.org/) is to
497 test as many CPAN packages as possible on as many platforms as
498 possible. This provides valuable feedback to module authors and
499 potential users to identify bugs or platform compatibility issues and
500 improves the overall quality and value of CPAN.
502 One way you can contribute is to send test results for each module
503 that you install. If you install the CPAN::Reporter module, you have
504 the option to automatically generate and email test reports to CPAN
505 Testers whenever you run tests on a CPAN package.
507 See the CPAN::Reporter documentation for additional details and
508 configuration settings. If your firewall blocks outgoing email,
509 you will need to configure CPAN::Reporter before sending reports.
511 Email test reports if CPAN::Reporter is installed (yes/no)?
513 =item perl5lib_verbosity
515 When CPAN.pm extends @INC via PERL5LIB, it prints a list of
516 directories added (or a summary of how many directories are
517 added). Choose 'v' to get this message, 'none' to suppress it.
519 Verbosity level for PERL5LIB changes (none or v)?
521 =item trust_test_report_history
523 When a distribution has already been tested by CPAN::Reporter on
524 this machine, CPAN can skip the test phase and just rely on the
525 test report history instead.
527 Note that this will not apply to distributions that failed tests
528 because of missing dependencies. Also, tests can be run
529 regardless of the history using "force".
531 Do you want to rely on the test report history (yes/no)?
535 CPAN::SQLite is a layer between the index files that are downloaded
536 from the CPAN and CPAN.pm that speeds up metadata queries and reduces
537 memory consumption of CPAN.pm considerably.
539 Use CPAN::SQLite if available? (yes/no)?
543 Both YAML.pm and YAML::Syck are capable of deserialising code. As this
544 requires a string eval, which might be a security risk, you can use
545 this option to enable or disable the deserialisation of code via
546 CPAN::DeferedCode. (Note: This does not work under perl 5.6)
548 Do you want to enable code deserialisation (yes/no)?
552 At the time of this writing there are two competing YAML modules,
553 YAML.pm and YAML::Syck. The latter is faster but needs a C compiler
554 installed on your system. There may be more alternative YAML
555 conforming modules but at the time of writing a potential third
556 player, YAML::Tiny, seemed not powerful enough to work with CPAN.pm.
558 Which YAML implementation would you prefer?
564 This program is free software; you can redistribute it and/or
565 modify it under the same terms as Perl itself.
569 use vars qw( %prompts );
572 my($configpm, %args) = @_;
574 # extra args after 'o conf init'
575 my $matcher = $args{args} && @{$args{args}} ? $args{args}[0] : '';
576 if ($matcher =~ /^\/(.*)\/$/) {
577 # case /regex/ => take the first, ignore the rest
579 shift @{$args{args}};
580 if (@{$args{args}}) {
582 $CPAN::Frontend->mywarn("Ignoring excessive arguments '@{$args{args}}'");
583 $CPAN::Frontend->mysleep(2);
585 } elsif (0 == length $matcher) {
586 } elsif (0 && $matcher eq "~") { # extremely buggy, but a nice idea
587 my @unconfigured = grep { not exists $CPAN::Config->{$_}
588 or not defined $CPAN::Config->{$_}
589 or not length $CPAN::Config->{$_}
590 } keys %$CPAN::Config;
591 $matcher = "\\b(".join("|", @unconfigured).")\\b";
592 $CPAN::Frontend->mywarn("matcher[$matcher]");
594 # case WORD... => all arguments must be valid
595 for my $arg (@{$args{args}}) {
596 unless (exists $CPAN::HandleConfig::keys{$arg}) {
597 $CPAN::Frontend->mywarn("'$arg' is not a valid configuration variable\n");
601 $matcher = "\\b(".join("|",@{$args{args}}).")\\b";
603 CPAN->debug("matcher[$matcher]") if $CPAN::DEBUG;
605 unless ($CPAN::VERSION) {
608 require CPAN::HandleConfig;
609 CPAN::HandleConfig::require_myconfig_or_config();
610 $CPAN::Config ||= {};
618 #= Files, directories
622 $CPAN::Frontend->myprint($prompts{manual_config});
628 if ( $args{autoconfig} ) {
631 $manual_conf = "yes";
633 my $_conf = prompt("Would you like me to configure as much as possible ".
634 "automatically?", "yes");
635 $manual_conf = ($_conf and $_conf =~ /^y/i) ? "no" : "yes";
637 CPAN->debug("manual_conf[$manual_conf]") if $CPAN::DEBUG;
640 if ($manual_conf =~ /^y/i) {
644 $CPAN::Config->{urllist} ||= [];
647 # prototype should match that of &MakeMaker::prompt
648 my $current_second = time;
649 my $current_second_count = 0;
651 *_real_prompt = sub {
653 my($ret) = defined $a ? $a : "";
654 $CPAN::Frontend->myprint(sprintf qq{%s [%s]\n\n}, $q, $ret);
655 eval { require Time::HiRes };
657 if (time == $current_second) {
658 $current_second_count++;
659 if ($current_second_count > 20) {
660 # I don't like more than 20 prompts per second
664 $current_second = time;
665 $current_second_count = 0;
666 $i_am_mad-- if $i_am_mad>0;
670 #Carp::cluck("SLEEEEEEEEPIIIIIIIIIIINGGGGGGGGGGG");
671 Time::HiRes::sleep(0.1);
686 $CPAN::Frontend->myprint($prompts{config_intro});
688 if (!$matcher or 'cpan_home' =~ /$matcher/) {
689 my $cpan_home = $CPAN::Config->{cpan_home}
690 || File::Spec->catdir(CPAN::HandleConfig::home(), ".cpan");
693 $CPAN::Frontend->myprint(qq{
695 I see you already have a directory
697 Shall we use it as the general CPAN build and cache directory?
701 # no cpan-home, must prompt and get one
702 $CPAN::Frontend->myprint($prompts{cpan_home_where});
705 $default = $cpan_home;
708 $CPAN::Frontend->myprint(" <cpan_home>\n");
709 PROMPT: while ($ans = prompt("CPAN build and cache directory?",$default)) {
711 if (File::Spec->file_name_is_absolute($ans)) {
712 my @cpan_home = split /[\/\\]/, $ans;
713 DIR: for my $dir (@cpan_home) {
714 if ($dir =~ /^~/ and (!$last_ans or $ans ne $last_ans)) {
716 ->mywarn("Warning: a tilde in the path will be ".
717 "taken as a literal tilde. Please ".
718 "confirm again if you want to keep it\n");
719 $last_ans = $default = $ans;
725 my $cwd = Cwd::cwd();
726 my $absans = File::Spec->catdir($cwd,$ans);
727 $CPAN::Frontend->mywarn("The path '$ans' is not an ".
728 "absolute path. Please specify ".
729 "an absolute path\n");
733 eval { File::Path::mkpath($ans); }; # dies if it can't
735 $CPAN::Frontend->mywarn("Couldn't create directory $ans.\n".
739 if (-d $ans && -w _) {
742 $CPAN::Frontend->mywarn("Couldn't find directory $ans\n".
743 "or directory is not writable. Please retry.\n");
745 $CPAN::Frontend->mydie("Giving up");
749 $CPAN::Config->{cpan_home} = $ans;
752 if (!$matcher or 'keep_source_where' =~ /$matcher/) {
753 my_dflt_prompt("keep_source_where",
754 File::Spec->catdir($CPAN::Config->{cpan_home},"sources"),
759 if (!$matcher or 'build_dir' =~ /$matcher/) {
760 my_dflt_prompt("build_dir",
761 File::Spec->catdir($CPAN::Config->{cpan_home},"build"),
766 if (!$matcher or 'build_dir_reuse' =~ /$matcher/) {
767 my_yn_prompt(build_dir_reuse => 0, $matcher);
770 if (!$matcher or 'prefs_dir' =~ /$matcher/) {
771 my_dflt_prompt("prefs_dir",
772 File::Spec->catdir($CPAN::Config->{cpan_home},"prefs"),
779 #= Config: auto_commit
782 my_yn_prompt(auto_commit => 0, $matcher);
785 #= Cache size, Index expire
788 if (!$matcher or 'build_cache' =~ /$matcher/) {
789 # large enough to build large dists like Tk
790 my_dflt_prompt(build_cache => 100, $matcher);
793 if (!$matcher or 'index_expire' =~ /$matcher/) {
794 my_dflt_prompt(index_expire => 1, $matcher);
797 if (!$matcher or 'scan_cache' =~ /$matcher/) {
798 my_prompt_loop(scan_cache => 'atstart', $matcher, 'atstart|never');
805 my_yn_prompt(cache_metadata => 1, $matcher);
806 my_yn_prompt(use_sqlite => 0, $matcher);
809 #= Do we follow PREREQ_PM?
812 if (!$matcher or 'prerequisites_policy' =~ /$matcher/) {
813 my_prompt_loop(prerequisites_policy => 'ask', $matcher,
814 'follow|ask|ignore');
817 if (!$matcher or 'build_requires_install_policy' =~ /$matcher/) {
818 my_prompt_loop(build_requires_install_policy => 'ask/yes', $matcher,
819 'yes|no|ask/yes|ask/no');
825 if (!$matcher or 'check_sigs' =~ /$matcher/) {
826 my_yn_prompt(check_sigs => 0, $matcher);
832 if (!$matcher or 'test_report' =~ /$matcher/) {
833 my_yn_prompt(test_report => 0, $matcher);
835 $CPAN::Config->{test_report} &&
836 $CPAN::META->has_inst("CPAN::Reporter") &&
837 CPAN::Reporter->can('configure')
839 $CPAN::Frontend->myprint("\nProceeding to configure CPAN::Reporter.\n");
840 CPAN::Reporter::configure();
841 $CPAN::Frontend->myprint("\nReturning to CPAN configuration.\n");
845 if (!$matcher or 'trust_test_report_history' =~ /$matcher/) {
846 my_yn_prompt(trust_test_report_history => 0, $matcher);
850 #= YAML vs. YAML::Syck
852 if (!$matcher or "yaml_module" =~ /$matcher/) {
853 my_dflt_prompt(yaml_module => "YAML", $matcher);
854 unless ($CPAN::META->has_inst($CPAN::Config->{yaml_module})) {
855 $CPAN::Frontend->mywarn
856 ("Warning (maybe harmless): '$CPAN::Config->{yaml_module}' not installed.\n");
857 $CPAN::Frontend->mysleep(3);
862 #= YAML code deserialisation
864 if (!$matcher or "yaml_load_code" =~ /$matcher/) {
865 my_yn_prompt(yaml_load_code => 0, $matcher);
872 my @external_progs = qw/bzip2 gzip tar unzip
876 curl lynx wget ncftpget ncftp ftp
882 my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
883 if (!$matcher or "@external_progs" =~ /$matcher/) {
884 $CPAN::Frontend->myprint($prompts{external_progs});
887 local $^W if $^O eq 'MacOS';
888 local $^W = $old_warn;
890 for $progname (@external_progs) {
891 next if $matcher && $progname !~ /$matcher/;
892 if ($^O eq 'MacOS') {
893 $CPAN::Config->{$progname} = 'not_here';
897 my $progcall = $progname;
899 # we really don't need ncftp if we have ncftpget, but
900 # if they chose this dialog via matcher, they shall have it
901 next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
903 my $path = $CPAN::Config->{$progname}
904 || $Config::Config{$progname}
906 if (File::Spec->file_name_is_absolute($path)) {
907 # testing existence is not good enough, some have these exe
910 # warn "Warning: configured $path does not exist\n" unless -e $path;
912 } elsif ($path =~ /^\s+$/) {
913 # preserve disabled programs
919 $progcall = $Config::Config{$progname} if $Config::Config{$progname};
922 $path ||= find_exe($progcall,\@path);
923 unless ($path) { # not -e $path, because find_exe already checked that
925 $CPAN::Frontend->mywarn("Warning: $progcall not found in PATH[@path]\n");
926 if ($progname eq "make") {
927 $CPAN::Frontend->mywarn("ALERT: 'make' is an essential tool for ".
928 "building perl Modules. Please make sure you ".
929 "have 'make' (or some equivalent) ".
932 if ($^O eq "MSWin32") {
933 $CPAN::Frontend->mywarn("
934 Windows users may want to follow this procedure when back in the CPAN shell:
936 look YVES/scripts/alien_nmake.pl
939 This will install nmake on your system which can be used as a 'make'
940 substitute. You can then revisit this dialog with
948 $prompts{$progname} = "Where is your $progname program?";
949 my_dflt_prompt($progname,$path,$matcher);
953 if (!$matcher or 'pager' =~ /$matcher/) {
954 my $path = $CPAN::Config->{'pager'} ||
955 $ENV{PAGER} || find_exe("less",\@path) ||
956 find_exe("more",\@path) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
958 my_dflt_prompt(pager => $path, $matcher);
961 if (!$matcher or 'shell' =~ /$matcher/) {
962 my $path = $CPAN::Config->{'shell'};
963 if ($path && File::Spec->file_name_is_absolute($path)) {
964 $CPAN::Frontend->mywarn("Warning: configured $path does not exist\n")
968 $path ||= $ENV{SHELL};
969 $path ||= $ENV{COMSPEC} if $^O eq "MSWin32";
970 if ($^O eq 'MacOS') {
971 $CPAN::Config->{'shell'} = 'not_here';
973 $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
974 my_dflt_prompt(shell => $path, $matcher);
982 if (!$matcher or 'tar_verbosity' =~ /$matcher/) {
983 my_prompt_loop(tar_verbosity => 'v', $matcher,
987 if (!$matcher or 'load_module_verbosity' =~ /$matcher/) {
988 my_prompt_loop(load_module_verbosity => 'v', $matcher,
992 if (!$matcher or 'perl5lib_verbosity' =~ /$matcher/) {
993 my_prompt_loop(perl5lib_verbosity => 'v', $matcher,
997 my_yn_prompt(inhibit_startup_message => 0, $matcher);
1000 #= Installer, arguments to make etc.
1003 if (!$matcher or 'prefer_installer' =~ /$matcher/) {
1004 my_prompt_loop(prefer_installer => 'MB', $matcher, 'MB|EUMM|RAND');
1007 if (!$matcher or 'makepl_arg make_arg' =~ /$matcher/) {
1008 my_dflt_prompt(makepl_arg => "", $matcher);
1009 my_dflt_prompt(make_arg => "", $matcher);
1010 if ( $CPAN::Config->{makepl_arg} =~ /LIBS=|INC=/ ) {
1011 $CPAN::Frontend->mywarn(
1012 "Warning: Using LIBS or INC in makepl_arg will likely break distributions\n" .
1013 "that specify their own LIBS or INC options in Makefile.PL.\n"
1019 require CPAN::HandleConfig;
1020 if (exists $CPAN::HandleConfig::keys{make_install_make_command}) {
1021 # as long as Windows needs $self->_build_command, we cannot
1022 # support sudo on windows :-)
1023 my_dflt_prompt(make_install_make_command => $CPAN::Config->{make} || "",
1027 my_dflt_prompt(make_install_arg => $CPAN::Config->{make_arg} || "",
1030 my_dflt_prompt(mbuildpl_arg => "", $matcher);
1031 my_dflt_prompt(mbuild_arg => "", $matcher);
1033 if (exists $CPAN::HandleConfig::keys{mbuild_install_build_command}
1034 and $^O ne "MSWin32") {
1035 # as long as Windows needs $self->_build_command, we cannot
1036 # support sudo on windows :-)
1037 my_dflt_prompt(mbuild_install_build_command => "./Build", $matcher);
1040 my_dflt_prompt(mbuild_install_arg => "", $matcher);
1046 my_dflt_prompt(inactivity_timeout => 0, $matcher);
1051 if (!$matcher or 'halt_on_failure' =~ /$matcher/) {
1052 my_yn_prompt(halt_on_failure => 0, $matcher);
1059 my @proxy_vars = qw/ftp_proxy http_proxy no_proxy/;
1060 my @proxy_user_vars = qw/proxy_user proxy_pass/;
1061 if (!$matcher or "@proxy_vars @proxy_user_vars" =~ /$matcher/) {
1062 $CPAN::Frontend->myprint($prompts{proxy_intro});
1065 $prompts{$_} = "Your $_?";
1066 my_dflt_prompt($_ => $ENV{$_}||"", $matcher);
1069 if ($CPAN::Config->{ftp_proxy} ||
1070 $CPAN::Config->{http_proxy}) {
1072 $default = $CPAN::Config->{proxy_user} || $CPAN::LWP::UserAgent::USER || "";
1074 $CPAN::Frontend->myprint($prompts{proxy_user});
1076 if ($CPAN::Config->{proxy_user} = prompt("Your proxy user id?",$default)) {
1077 $CPAN::Frontend->myprint($prompts{proxy_pass});
1079 if ($CPAN::META->has_inst("Term::ReadKey")) {
1080 Term::ReadKey::ReadMode("noecho");
1082 $CPAN::Frontend->myprint($prompts{password_warn});
1084 $CPAN::Config->{proxy_pass} = prompt_no_strip("Your proxy password?");
1085 if ($CPAN::META->has_inst("Term::ReadKey")) {
1086 Term::ReadKey::ReadMode("restore");
1088 $CPAN::Frontend->myprint("\n\n");
1097 my_yn_prompt(ftp_passive => 1, $matcher);
1103 if (!$matcher or 'getcwd' =~ /$matcher/) {
1104 my_prompt_loop(getcwd => 'cwd', $matcher,
1105 'cwd|getcwd|fastcwd|backtickcwd');
1109 #= the CPAN shell itself (prompt, color)
1112 my_yn_prompt(commandnumber_in_prompt => 1, $matcher);
1113 my_yn_prompt(term_ornaments => 1, $matcher);
1114 if ("colorize_output colorize_print colorize_warn colorize_debug" =~ $matcher) {
1115 my_yn_prompt(colorize_output => 0, $matcher);
1116 if ($CPAN::Config->{colorize_output}) {
1117 if ($CPAN::META->has_inst("Term::ANSIColor")) {
1121 print " on_black on_red green ellow ".
1122 "on_blue genta on_cyan white\n";
1124 for my $FG ("", "bold",
1125 map {$_,"bold $_"} "black","red","green",
1129 printf "%12s ", $FG;
1130 for my $BG ("",map {"on_$_"} qw(black red green yellow
1131 blue magenta cyan white)) {
1133 Term::ANSIColor::colored(" $T ","$FG $BG") : " $T ";
1140 ["colorize_print", "bold blue on_white"],
1141 ["colorize_warn", "bold red on_white"],
1142 ["colorize_debug", "black on_cyan"],
1144 my_dflt_prompt($tuple->[0] => $tuple->[1], $matcher);
1145 if ($CPAN::META->has_inst("Term::ANSIColor")) {
1146 eval { Term::ANSIColor::color($CPAN::Config->{$tuple->[0]})};
1148 $CPAN::Config->{$tuple->[0]} = $tuple->[1];
1149 $CPAN::Frontend->mywarn($@."setting to default '$tuple->[1]'\n");
1160 if (!$matcher or 'term_is_latin' =~ /$matcher/) {
1161 my_yn_prompt(term_is_latin => 1, $matcher);
1165 #== save history in file 'histfile'
1168 if (!$matcher or 'histfile histsize' =~ /$matcher/) {
1169 $CPAN::Frontend->myprint($prompts{histfile_intro});
1170 defined($default = $CPAN::Config->{histfile}) or
1171 $default = File::Spec->catfile($CPAN::Config->{cpan_home},"histfile");
1172 my_dflt_prompt(histfile => $default, $matcher);
1174 if ($CPAN::Config->{histfile}) {
1175 defined($default = $CPAN::Config->{histsize}) or $default = 100;
1176 my_dflt_prompt(histsize => $default, $matcher);
1181 #== do an ls on the m or the d command
1183 my_yn_prompt(show_upload_date => 0, $matcher);
1186 #== verbosity at the end of the r command
1189 or 'show_unparsable_versions' =~ /$matcher/
1190 or 'show_zero_versions' =~ /$matcher/
1192 $CPAN::Frontend->myprint($prompts{show_unparsable_or_zero_versions_intro});
1193 my_yn_prompt(show_unparsable_versions => 0, $matcher);
1194 my_yn_prompt(show_zero_versions => 0, $matcher);
1198 #= MIRRORED.BY and conf_sites()
1201 my_yn_prompt("connect_to_internet_ok" => 1, $matcher);
1203 if ("urllist" =~ $matcher) {
1204 # conf_sites would go into endless loop with the smash prompt
1205 local *_real_prompt;
1206 *_real_prompt = \&CPAN::Shell::colorable_makemaker_prompt;
1209 if ("randomize_urllist" =~ $matcher) {
1210 my_dflt_prompt(randomize_urllist => 0, $matcher);
1212 if ("ftpstats_size" =~ $matcher) {
1213 my_dflt_prompt(ftpstats_size => 99, $matcher);
1215 if ("ftpstats_period" =~ $matcher) {
1216 my_dflt_prompt(ftpstats_period => 14, $matcher);
1218 } elsif ($fastread) {
1219 $CPAN::Frontend->myprint("Autoconfigured everything but 'urllist'.\n".
1220 "Please call 'o conf init urllist' to configure ".
1221 "your CPAN server(s) now!\n\n");
1226 $CPAN::Frontend->myprint("\n\n");
1227 if ($matcher && !$CPAN::Config->{auto_commit}) {
1228 $CPAN::Frontend->myprint("Please remember to call 'o conf commit' to ".
1229 "make the config permanent!\n\n");
1231 CPAN::HandleConfig->commit($configpm);
1235 sub my_dflt_prompt {
1236 my ($item, $dflt, $m) = @_;
1237 my $default = $CPAN::Config->{$item} || $dflt;
1240 if (!$m || $item =~ /$m/) {
1241 if (my $intro = $prompts{$item . "_intro"}) {
1242 $CPAN::Frontend->myprint($intro);
1244 $CPAN::Frontend->myprint(" <$item>\n");
1245 $CPAN::Config->{$item} = prompt($prompts{$item}, $default);
1248 $CPAN::Config->{$item} = $default;
1253 my ($item, $dflt, $m) = @_;
1255 defined($default = $CPAN::Config->{$item}) or $default = $dflt;
1258 if (!$m || $item =~ /$m/) {
1259 if (my $intro = $prompts{$item . "_intro"}) {
1260 $CPAN::Frontend->myprint($intro);
1262 $CPAN::Frontend->myprint(" <$item>\n");
1263 my $ans = prompt($prompts{$item}, $default ? 'yes' : 'no');
1264 $CPAN::Config->{$item} = ($ans =~ /^[y1]/i ? 1 : 0);
1267 $CPAN::Config->{$item} = $default;
1271 sub my_prompt_loop {
1272 my ($item, $dflt, $m, $ok) = @_;
1273 my $default = $CPAN::Config->{$item} || $dflt;
1277 if (!$m || $item =~ /$m/) {
1278 $CPAN::Frontend->myprint($prompts{$item . "_intro"});
1279 $CPAN::Frontend->myprint(" <$item>\n");
1280 do { $ans = prompt($prompts{$item}, $default);
1281 } until $ans =~ /$ok/;
1282 $CPAN::Config->{$item} = $ans;
1285 $CPAN::Config->{$item} = $default;
1291 my $m = 'MIRRORED.BY';
1292 my $mby = File::Spec->catfile($CPAN::Config->{keep_source_where},$m);
1293 File::Path::mkpath(File::Basename::dirname($mby));
1294 if (-f $mby && -f $m && -M $m < -M $mby) {
1296 File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
1300 my $overwrite_local = 0;
1301 if ($mby && -f $mby && -M _ <= 60 && -s _ > 0) {
1302 my $mtime = localtime((stat _)[9]);
1303 my $prompt = qq{Found $mby as of $mtime
1305 I\'d use that as a database of CPAN sites. If that is OK for you,
1306 please answer 'y', but if you want me to get a new database now,
1307 please answer 'n' to the following question.
1309 Shall I use the local database in $mby?};
1310 my $ans = prompt($prompt,"y");
1311 $overwrite_local = 1 unless $ans =~ /^y/i;
1314 if ($overwrite_local) {
1315 $CPAN::Frontend->myprint(qq{Trying to overwrite $mby\n});
1316 $mby = CPAN::FTP->localize($m,$mby,3);
1317 $overwrite_local = 0;
1318 } elsif ( ! -f $mby ) {
1319 $CPAN::Frontend->myprint(qq{You have no $mby\n I\'m trying to fetch one\n});
1320 $mby = CPAN::FTP->localize($m,$mby,3);
1321 } elsif (-M $mby > 60 && $loopcount == 0) {
1322 $CPAN::Frontend->myprint(qq{Your $mby is older than 60 days,\n I\'m trying }.
1323 qq{to fetch one\n});
1324 $mby = CPAN::FTP->localize($m,$mby,3);
1326 } elsif (-s $mby == 0) {
1327 $CPAN::Frontend->myprint(qq{You have an empty $mby,\n I\'m trying to fetch one\n});
1328 $mby = CPAN::FTP->localize($m,$mby,3);
1333 local $urllist = [];
1334 read_mirrored_by($mby);
1336 $CPAN::Config->{urllist} = $urllist;
1340 my($exe,$path) = @_;
1342 #warn "in find_exe exe[$exe] path[@$path]";
1344 my $abs = File::Spec->catfile($dir,$exe);
1345 if (($abs = MM->maybe_command($abs))) {
1352 my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
1353 CPAN->debug("picklist('$items','$prompt','$default','$require_nonempty',".
1354 "'$empty_warning')") if $CPAN::DEBUG;
1360 SELECTION: while (1) {
1362 # display, at most, 15 items at a time
1363 my $limit = $#{ $items } - $pos;
1364 $limit = 15 if $limit > 15;
1366 # show the next $limit items, get the new position
1367 $pos = display_some($items, $limit, $pos, $default);
1368 $pos = 0 if $pos >= @$items;
1370 my $num = prompt($prompt,$default);
1372 @nums = split (' ', $num);
1375 @nums = grep { !$seen{$_}++ } @nums;
1377 my $i = scalar @$items;
1379 if (grep (/\D/ || $_ < 1 || $_ > $i, @nums)) {
1380 $CPAN::Frontend->mywarn("invalid items entered, try again\n");
1381 if ("@nums" =~ /\D/) {
1382 $CPAN::Frontend->mywarn("(we are expecting only numbers between 1 and $i)\n");
1386 if ($require_nonempty && !@nums) {
1387 $CPAN::Frontend->mywarn("$empty_warning\n");
1389 $CPAN::Frontend->myprint("\n");
1391 # a blank line continues...
1392 next SELECTION unless @nums;
1395 for (@nums) { $_-- }
1402 while (@{$nums||[]}) {
1403 my $n = shift @$nums;
1404 if ($n =~ /^(\d+)-(\d+)$/) {
1405 my @range = $1 .. $2;
1406 # warn "range[@range]";
1407 push @nums2, @range;
1412 push @$nums, @nums2;
1416 my ($items, $limit, $pos, $default) = @_;
1419 my @displayable = @$items[$pos .. ($pos + $limit)];
1420 for my $item (@displayable) {
1421 $CPAN::Frontend->myprint(sprintf "(%d) %s\n", ++$pos, $item);
1423 my $hit_what = $default ? "SPACE RETURN" : "RETURN";
1424 $CPAN::Frontend->myprint(sprintf("%d more items, hit %s to show them\n",
1432 sub read_mirrored_by {
1433 my $local = shift or return;
1434 my(%all,$url,$expected_size,$default,$ans,$host,
1435 $dst,$country,$continent,@location);
1436 my $fh = FileHandle->new;
1437 $fh->open($local) or die "Couldn't open $local: $!";
1440 ($host) = /^([\w\.\-]+)/ unless defined $host;
1441 next unless defined $host;
1442 next unless /\s+dst_(dst|location)/;
1443 /location\s+=\s+\"([^\"]+)/ and @location = (split /\s*,\s*/, $1) and
1444 ($continent, $country) = @location[-1,-2];
1445 $continent =~ s/\s\(.*//;
1446 $continent =~ s/\W+$//; # if Jarkko doesn't know latitude/longitude
1447 /dst_dst\s+=\s+\"([^\"]+)/ and $dst = $1;
1448 next unless $host && $dst && $continent && $country;
1449 $all{$continent}{$country}{$dst} = CPAN::Mirrored::By->new($continent,$country,$dst);
1451 $dst=$continent=$country="";
1454 $CPAN::Config->{urllist} ||= [];
1455 my @previous_urls = @{$CPAN::Config->{urllist}};
1457 $CPAN::Frontend->myprint($prompts{urls_intro});
1459 my (@cont, $cont, %cont, @countries, @urls, %seen);
1460 my $no_previous_warn =
1461 "Sorry! since you don't have any existing picks, you must make a\n" .
1462 "geographic selection.";
1463 my $offer_cont = [sort keys %all];
1464 if (@previous_urls) {
1465 push @$offer_cont, "(edit previous picks)";
1466 $default = @$offer_cont;
1468 @cont = picklist($offer_cont,
1469 "Select your continent (or several nearby continents)",
1475 foreach $cont (@cont) {
1476 my @c = sort keys %{$all{$cont}};
1477 @cont{@c} = map ($cont, 0..$#c);
1478 @c = map ("$_ ($cont)", @c) if @cont > 1;
1479 push (@countries, @c);
1481 if (@previous_urls && @countries) {
1482 push @countries, "(edit previous picks)";
1483 $default = @countries;
1487 @countries = picklist (\@countries,
1488 "Select your country (or several nearby countries)",
1492 %seen = map (($_ => 1), @previous_urls);
1493 # hmmm, should take list of defaults from CPAN::Config->{'urllist'}...
1494 foreach $country (@countries) {
1495 next if $country =~ /edit previous picks/;
1496 (my $bare_country = $country) =~ s/ \(.*\)//;
1497 my @u = sort keys %{$all{$cont{$bare_country}}{$bare_country}};
1498 @u = grep (! $seen{$_}, @u);
1499 @u = map ("$_ ($bare_country)", @u)
1504 push (@urls, map ("$_ (previous pick)", @previous_urls));
1505 my $prompt = "Select as many URLs as you like (by number),
1506 put them on one line, separated by blanks, hyphenated ranges allowed
1507 e.g. '1 4 5' or '7 1-4 8'";
1508 if (@previous_urls) {
1509 $default = join (' ', ((scalar @urls) - (scalar @previous_urls) + 1) ..
1511 $prompt .= "\n(or just hit RETURN to keep your previous picks)";
1514 @urls = picklist (\@urls, $prompt, $default);
1515 foreach (@urls) { s/ \(.*\)//; }
1516 push @$urllist, @urls;
1519 sub bring_your_own {
1520 my %seen = map (($_ => 1), @$urllist);
1522 my $eacnt = 0; # empty answers
1524 my $prompt = "Enter another URL or RETURN to quit:";
1526 $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
1528 Please enter your CPAN site:};
1530 $ans = prompt ($prompt, "");
1533 $ans =~ s|/?\z|/|; # has to end with one slash
1534 $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
1535 if ($ans =~ /^\w+:\/./) {
1536 push @urls, $ans unless $seen{$ans}++;
1539 myprint(sprintf(qq{"%s" doesn\'t look like an URL at first sight.
1540 I\'ll ignore it for now.
1541 You can add it to your %s
1542 later if you\'re sure it\'s right.\n},
1544 $INC{'CPAN/MyConfig.pm'}
1545 || $INC{'CPAN/Config.pm'}
1546 || "configuration file",
1550 if (++$eacnt >= 5) {
1552 mywarn("Giving up.\n");
1553 $CPAN::Frontend->mysleep(5);
1557 } while $ans || !%seen;
1559 push @$urllist, @urls;
1560 # xxx delete or comment these out when you're happy that it works
1561 $CPAN::Frontend->myprint("New set of picks:\n");
1562 map { $CPAN::Frontend->myprint(" $_\n") } @$urllist;
1567 $_[0] =~ s/^\s+//; # no leading spaces
1568 $_[0] =~ s/\s+\z//; # no trailing spaces
1572 unless (defined &_real_prompt) {
1573 *_real_prompt = \&CPAN::Shell::colorable_makemaker_prompt;
1575 my $ans = _real_prompt(@_);
1577 _strip_spaces($ans);
1583 sub prompt_no_strip ($;$) {
1584 return _real_prompt(@_);
1592 manual_config => qq[
1594 CPAN is the world-wide archive of perl resources. It consists of about
1595 300 sites that all replicate the same contents around the globe. Many
1596 countries have at least one CPAN site already. The resources found on
1597 CPAN are easily accessible with the CPAN.pm module. If you want to use
1598 CPAN.pm, lots of things have to be configured. Fortunately, most of
1599 them can be determined automatically. If you prefer the automatic
1600 configuration, answer 'yes' below.
1602 If you prefer to enter a dialog instead, you can answer 'no' to this
1603 question and I'll let you configure in small steps one thing after the
1604 other. (Note: you can revisit this dialog anytime later by typing 'o
1605 conf init' at the cpan prompt.)
1610 The following questions are intended to help you with the
1611 configuration. The CPAN module needs a directory of its own to cache
1612 important index files and maybe keep a temporary mirror of CPAN files.
1613 This may be a site-wide or a personal directory.
1617 # cpan_home => qq{ },
1619 cpan_home_where => qq{
1621 First of all, I'd like to create this directory. Where?
1625 external_progs => qq{
1627 The CPAN module will need a few external programs to work properly.
1628 Please correct me, if I guess the wrong path for a program. Don't
1629 panic if you do not have some of them, just press ENTER for those. To
1630 disable the use of a program, you can type a space followed by ENTER.
1636 If you're accessing the net via proxies, you can specify them in the
1637 CPAN configuration or via environment variables. The variable in
1638 the \$CPAN::Config takes precedence.
1644 If your proxy is an authenticating proxy, you can store your username
1645 permanently. If you do not want that, just press RETURN. You will then
1646 be asked for your username in every future session.
1652 Your password for the authenticating proxy can also be stored
1653 permanently on disk. If this violates your security policy, just press
1654 RETURN. You will then be asked for the password in every future
1661 Now we need to know where your favorite CPAN sites are located. Push
1662 a few sites onto the array (just in case the first on the array won\'t
1663 work). If you are mirroring CPAN to your local workstation, specify a
1666 First, pick a nearby continent and country by typing in the number(s)
1667 in front of the item(s) you want to select. You can pick several of
1668 each, separated by spaces. Then, you will be presented with a list of
1669 URLs of CPAN mirrors in the countries you selected, along with
1670 previously selected URLs. Select some of those URLs, or just keep the
1671 old list. Finally, you will be prompted for any extra URLs -- file:,
1672 ftp:, or http: -- that host a CPAN mirror.
1676 password_warn => qq{
1678 Warning: Term::ReadKey seems not to be available, your password will
1679 be echoed to the terminal!
1685 die "Coding error in \@prompts declaration. Odd number of elements, above"
1688 %prompts = @prompts;
1690 if (scalar(keys %prompts) != scalar(@prompts)/2) {
1692 for my $item (0..$#prompts) {
1694 die "$prompts[$item] is duplicated\n" if $already{$prompts[$item]}++;
1699 my $pmfile = __FILE__;
1700 open FH, $pmfile or die "Could not open '$pmfile': $!";
1704 next if 1 .. /^=over/;
1711 warn "Alert: cannot parse my own manpage for init dialog" unless $podpara[0] =~ s/^=item\s+//;
1712 my $name = shift @podpara;
1714 while (@podpara && $podpara[0] !~ /^=item/) {
1715 push @para, shift @podpara;
1717 $prompts{$name} = pop @para;
1719 $prompts{$name . "_intro"} = join "", map { "$_\n\n" } @para;