File Coverage

blib/lib/CPAN/FirstTime.pm
Criterion Covered Total %
statement 33 663 4.9
branch 0 388 0.0
condition 0 229 0.0
subroutine 11 42 26.1
pod 0 15 0.0
total 44 1337 3.2


line stmt bran cond sub pod time code
1             # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2             # vim: ts=4 sts=4 sw=4:
3             package CPAN::FirstTime;
4 4     4   78227 use strict;
  4         21  
  4         149  
5              
6 4     4   1548 use ExtUtils::MakeMaker ();
  4         217338  
  4         116  
7 4     4   887 use FileHandle ();
  4         19742  
  4         121  
8 4     4   25 use File::Basename ();
  4         8  
  4         61  
9 4     4   23 use File::Path ();
  4         9  
  4         64  
10 4     4   21 use File::Spec ();
  4         12  
  4         79  
11 4     4   2133 use CPAN::Mirrors ();
  4         14  
  4         118  
12 4     4   1039 use CPAN::Version ();
  4         10  
  4         95  
13 4     4   24 use vars qw($VERSION $auto_config);
  4         8  
  4         1102  
14             $VERSION = "5.5313";
15              
16             =head1 NAME
17              
18             CPAN::FirstTime - Utility for CPAN::Config file Initialization
19              
20             =head1 SYNOPSIS
21              
22             CPAN::FirstTime::init()
23              
24             =head1 DESCRIPTION
25              
26             The init routine asks a few questions and writes a CPAN/Config.pm or
27             CPAN/MyConfig.pm file (depending on what it is currently using).
28              
29             In the following all questions and explanations regarding config
30             variables are collected.
31              
32             =cut
33              
34             # down until the next =back the manpage must be parsed by the program
35             # because the text is used in the init dialogues.
36              
37             my @podpara = split /\n\n/, <<'=back';
38              
39             =over 2
40              
41             =item auto_commit
42              
43             Normally CPAN.pm keeps config variables in memory and changes need to
44             be saved in a separate 'o conf commit' command to make them permanent
45             between sessions. If you set the 'auto_commit' option to true, changes
46             to a config variable are always automatically committed to disk.
47              
48             Always commit changes to config variables to disk?
49              
50             =item build_cache
51              
52             CPAN.pm can limit the size of the disk area for keeping the build
53             directories with all the intermediate files.
54              
55             Cache size for build directory (in MB)?
56              
57             =item build_dir
58              
59             Directory where the build process takes place?
60              
61             =item build_dir_reuse
62              
63             Until version 1.88 CPAN.pm never trusted the contents of the build_dir
64             directory between sessions. Since 1.88_58 CPAN.pm has a YAML-based
65             mechanism that makes it possible to share the contents of the
66             build_dir/ directory between different sessions with the same version
67             of perl. People who prefer to test things several days before
68             installing will like this feature because it saves a lot of time.
69              
70             If you say yes to the following question, CPAN will try to store
71             enough information about the build process so that it can pick up in
72             future sessions at the same state of affairs as it left a previous
73             session.
74              
75             Store and re-use state information about distributions between
76             CPAN.pm sessions?
77              
78             =item build_requires_install_policy
79              
80             When a module declares another one as a 'build_requires' prerequisite
81             this means that the other module is only needed for building or
82             testing the module but need not be installed permanently. In this case
83             you may wish to install that other module nonetheless or just keep it
84             in the 'build_dir' directory to have it available only temporarily.
85             Installing saves time on future installations but makes the perl
86             installation bigger.
87              
88             You can choose if you want to always install (yes), never install (no)
89             or be always asked. In the latter case you can set the default answer
90             for the question to yes (ask/yes) or no (ask/no).
91              
92             Policy on installing 'build_requires' modules (yes, no, ask/yes,
93             ask/no)?
94              
95             =item cache_metadata
96              
97             To considerably speed up the initial CPAN shell startup, it is
98             possible to use Storable to create a cache of metadata. If Storable is
99             not available, the normal index mechanism will be used.
100              
101             Note: this mechanism is not used when use_sqlite is on and SQLLite is
102             running.
103              
104             Cache metadata (yes/no)?
105              
106             =item check_sigs
107              
108             CPAN packages can be digitally signed by authors and thus verified
109             with the security provided by strong cryptography. The exact mechanism
110             is defined in the Module::Signature module. While this is generally
111             considered a good thing, it is not always convenient to the end user
112             to install modules that are signed incorrectly or where the key of the
113             author is not available or where some prerequisite for
114             Module::Signature has a bug and so on.
115              
116             With the check_sigs parameter you can turn signature checking on and
117             off. The default is off for now because the whole tool chain for the
118             functionality is not yet considered mature by some. The author of
119             CPAN.pm would recommend setting it to true most of the time and
120             turning it off only if it turns out to be annoying.
121              
122             Note that if you do not have Module::Signature installed, no signature
123             checks will be performed at all.
124              
125             Always try to check and verify signatures if a SIGNATURE file is in
126             the package and Module::Signature is installed (yes/no)?
127              
128             =item cleanup_after_install
129              
130             Users who install modules and do not intend to look back, can free
131             occupied disk space quickly by letting CPAN.pm cleanup each build
132             directory immediately after a successful install.
133              
134             Remove build directory after a successful install? (yes/no)?
135              
136             =item colorize_output
137              
138             When you have Term::ANSIColor installed, you can turn on colorized
139             output to have some visual differences between normal CPAN.pm output,
140             warnings, debugging output, and the output of the modules being
141             installed. Set your favorite colors after some experimenting with the
142             Term::ANSIColor module.
143              
144             Please note that on Windows platforms colorized output also requires
145             the Win32::Console::ANSI module.
146              
147             Do you want to turn on colored output?
148              
149             =item colorize_print
150              
151             Color for normal output?
152              
153             =item colorize_warn
154              
155             Color for warnings?
156              
157             =item colorize_debug
158              
159             Color for debugging messages?
160              
161             =item commandnumber_in_prompt
162              
163             The prompt of the cpan shell can contain the current command number
164             for easier tracking of the session or be a plain string.
165              
166             Do you want the command number in the prompt (yes/no)?
167              
168             =item connect_to_internet_ok
169              
170             If you have never defined your own C in your configuration
171             then C will be hesitant to use the built in default sites for
172             downloading. It will ask you once per session if a connection to the
173             internet is OK and only if you say yes, it will try to connect. But to
174             avoid this question, you can choose your favorite download sites once
175             and get away with it. Or, if you have no favorite download sites
176             answer yes to the following question.
177              
178             If no urllist has been chosen yet, would you prefer CPAN.pm to connect
179             to the built-in default sites without asking? (yes/no)?
180              
181             =item ftp_passive
182              
183             Shall we always set the FTP_PASSIVE environment variable when dealing
184             with ftp download (yes/no)?
185              
186             =item ftpstats_period
187              
188             Statistics about downloads are truncated by size and period
189             simultaneously.
190              
191             How many days shall we keep statistics about downloads?
192              
193             =item ftpstats_size
194              
195             Statistics about downloads are truncated by size and period
196             simultaneously.
197              
198             How many items shall we keep in the statistics about downloads?
199              
200             =item getcwd
201              
202             CPAN.pm changes the current working directory often and needs to
203             determine its own current working directory. Per default it uses
204             Cwd::cwd but if this doesn't work on your system for some reason,
205             alternatives can be configured according to the following table:
206              
207             cwd Cwd::cwd
208             getcwd Cwd::getcwd
209             fastcwd Cwd::fastcwd
210             getdcwd Cwd::getdcwd
211             backtickcwd external command cwd
212              
213             Preferred method for determining the current working directory?
214              
215             =item halt_on_failure
216              
217             Normally, CPAN.pm continues processing the full list of targets and
218             dependencies, even if one of them fails. However, you can specify
219             that CPAN should halt after the first failure. (Note that optional
220             recommended or suggested modules that fail will not cause a halt.)
221              
222             Do you want to halt on failure (yes/no)?
223              
224             =item histfile
225              
226             If you have one of the readline packages (Term::ReadLine::Perl,
227             Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
228             shell will have history support. The next two questions deal with the
229             filename of the history file and with its size. If you do not want to
230             set this variable, please hit SPACE ENTER to the following question.
231              
232             File to save your history?
233              
234             =item histsize
235              
236             Number of lines to save?
237              
238             =item inactivity_timeout
239              
240             Sometimes you may wish to leave the processes run by CPAN alone
241             without caring about them. Because the Makefile.PL or the Build.PL
242             sometimes contains question you're expected to answer, you can set a
243             timer that will kill a 'perl Makefile.PL' process after the specified
244             time in seconds.
245              
246             If you set this value to 0, these processes will wait forever. This is
247             the default and recommended setting.
248              
249             Timeout for inactivity during {Makefile,Build}.PL?
250              
251             =item index_expire
252              
253             The CPAN indexes are usually rebuilt once or twice per hour, but the
254             typical CPAN mirror mirrors only once or twice per day. Depending on
255             the quality of your mirror and your desire to be on the bleeding edge,
256             you may want to set the following value to more or less than one day
257             (which is the default). It determines after how many days CPAN.pm
258             downloads new indexes.
259              
260             Let the index expire after how many days?
261              
262             =item inhibit_startup_message
263              
264             When the CPAN shell is started it normally displays a greeting message
265             that contains the running version and the status of readline support.
266              
267             Do you want to turn this message off?
268              
269             =item keep_source_where
270              
271             Unless you are accessing the CPAN on your filesystem via a file: URL,
272             CPAN.pm needs to keep the source files it downloads somewhere. Please
273             supply a directory where the downloaded files are to be kept.
274              
275             Download target directory?
276              
277             =item load_module_verbosity
278              
279             When CPAN.pm loads a module it needs for some optional feature, it
280             usually reports about module name and version. Choose 'v' to get this
281             message, 'none' to suppress it.
282              
283             Verbosity level for loading modules (none or v)?
284              
285             =item makepl_arg
286              
287             Every Makefile.PL is run by perl in a separate process. Likewise we
288             run 'make' and 'make install' in separate processes. If you have
289             any parameters (e.g. PREFIX, UNINST or the like) you want to
290             pass to the calls, please specify them here.
291              
292             If you don't understand this question, just press ENTER.
293              
294             Typical frequently used settings:
295              
296             PREFIX=~/perl # non-root users (please see manual for more hints)
297              
298             Parameters for the 'perl Makefile.PL' command?
299              
300             =item make_arg
301              
302             Parameters for the 'make' command? Typical frequently used setting:
303              
304             -j3 # dual processor system (on GNU make)
305              
306             Your choice:
307              
308             =item make_install_arg
309              
310             Parameters for the 'make install' command?
311             Typical frequently used setting:
312              
313             UNINST=1 # to always uninstall potentially conflicting files
314             # (but do NOT use with local::lib or INSTALL_BASE)
315              
316             Your choice:
317              
318             =item make_install_make_command
319              
320             Do you want to use a different make command for 'make install'?
321             Cautious people will probably prefer:
322              
323             su root -c make
324             or
325             sudo make
326             or
327             /path1/to/sudo -u admin_account /path2/to/make
328              
329             or some such. Your choice:
330              
331             =item mbuildpl_arg
332              
333             A Build.PL is run by perl in a separate process. Likewise we run
334             './Build' and './Build install' in separate processes. If you have any
335             parameters you want to pass to the calls, please specify them here.
336              
337             Typical frequently used settings:
338              
339             --install_base /home/xxx # different installation directory
340              
341             Parameters for the 'perl Build.PL' command?
342              
343             =item mbuild_arg
344              
345             Parameters for the './Build' command? Setting might be:
346              
347             --extra_linker_flags -L/usr/foo/lib # non-standard library location
348              
349             Your choice:
350              
351             =item mbuild_install_arg
352              
353             Parameters for the './Build install' command? Typical frequently used
354             setting:
355              
356             --uninst 1 # uninstall conflicting files
357             # (but do NOT use with local::lib or INSTALL_BASE)
358              
359             Your choice:
360              
361             =item mbuild_install_build_command
362              
363             Do you want to use a different command for './Build install'? Sudo
364             users will probably prefer:
365              
366             su root -c ./Build
367             or
368             sudo ./Build
369             or
370             /path1/to/sudo -u admin_account ./Build
371              
372             or some such. Your choice:
373              
374             =item pager
375              
376             What is your favorite pager program?
377              
378             =item prefer_installer
379              
380             When you have Module::Build installed and a module comes with both a
381             Makefile.PL and a Build.PL, which shall have precedence?
382              
383             The main two standard installer modules are the old and well
384             established ExtUtils::MakeMaker (for short: EUMM) which uses the
385             Makefile.PL. And the next generation installer Module::Build (MB)
386             which works with the Build.PL (and often comes with a Makefile.PL
387             too). If a module comes only with one of the two we will use that one
388             but if both are supplied then a decision must be made between EUMM and
389             MB. See also http://rt.cpan.org/Ticket/Display.html?id=29235 for a
390             discussion about the right default.
391              
392             Or, as a third option you can choose RAND which will make a random
393             decision (something regular CPAN testers will enjoy).
394              
395             In case you can choose between running a Makefile.PL or a Build.PL,
396             which installer would you prefer (EUMM or MB or RAND)?
397              
398             =item prefs_dir
399              
400             CPAN.pm can store customized build environments based on regular
401             expressions for distribution names. These are YAML files where the
402             default options for CPAN.pm and the environment can be overridden and
403             dialog sequences can be stored that can later be executed by an
404             Expect.pm object. The CPAN.pm distribution comes with some prefab YAML
405             files that cover sample distributions that can be used as blueprints
406             to store your own prefs. Please check out the distroprefs/ directory of
407             the CPAN.pm distribution to get a quick start into the prefs system.
408              
409             Directory where to store default options/environment/dialogs for
410             building modules that need some customization?
411              
412             =item prerequisites_policy
413              
414             The CPAN module can detect when a module which you are trying to build
415             depends on prerequisites. If this happens, it can build the
416             prerequisites for you automatically ('follow'), ask you for
417             confirmation ('ask'), or just ignore them ('ignore'). Choosing
418             'follow' also sets PERL_AUTOINSTALL and PERL_EXTUTILS_AUTOINSTALL for
419             "--defaultdeps" if not already set.
420              
421             Please set your policy to one of the three values.
422              
423             Policy on building prerequisites (follow, ask or ignore)?
424              
425             =item randomize_urllist
426              
427             CPAN.pm can introduce some randomness when using hosts for download
428             that are configured in the urllist parameter. Enter a numeric value
429             between 0 and 1 to indicate how often you want to let CPAN.pm try a
430             random host from the urllist. A value of one specifies to always use a
431             random host as the first try. A value of zero means no randomness at
432             all. Anything in between specifies how often, on average, a random
433             host should be tried first.
434              
435             Randomize parameter
436              
437             =item recommends_policy
438              
439             (Experimental feature!) Some CPAN modules recommend additional, optional dependencies. These should
440             generally be installed except in resource constrained environments. When this
441             policy is true, recommended modules will be included with required modules.
442              
443             Include recommended modules?
444              
445             =item scan_cache
446              
447             By default, each time the CPAN module is started, cache scanning is
448             performed to keep the cache size in sync ('atstart'). Alternatively,
449             scanning and cleanup can happen when CPAN exits ('atexit'). To prevent
450             any cache cleanup, answer 'never'.
451              
452             Perform cache scanning ('atstart', 'atexit' or 'never')?
453              
454             =item shell
455              
456             What is your favorite shell?
457              
458             =item show_unparsable_versions
459              
460             During the 'r' command CPAN.pm finds modules without version number.
461             When the command finishes, it prints a report about this. If you
462             want this report to be very verbose, say yes to the following
463             variable.
464              
465             Show all individual modules that have no $VERSION?
466              
467             =item show_upload_date
468              
469             The 'd' and the 'm' command normally only show you information they
470             have in their in-memory database and thus will never connect to the
471             internet. If you set the 'show_upload_date' variable to true, 'm' and
472             'd' will additionally show you the upload date of the module or
473             distribution. Per default this feature is off because it may require a
474             net connection to get at the upload date.
475              
476             Always try to show upload date with 'd' and 'm' command (yes/no)?
477              
478             =item show_zero_versions
479              
480             During the 'r' command CPAN.pm finds modules with a version number of
481             zero. When the command finishes, it prints a report about this. If you
482             want this report to be very verbose, say yes to the following
483             variable.
484              
485             Show all individual modules that have a $VERSION of zero?
486              
487             =item suggests_policy
488              
489             (Experimental feature!) Some CPAN modules suggest additional, optional dependencies. These 'suggest'
490             dependencies provide enhanced operation. When this policy is true, suggested
491             modules will be included with required modules.
492              
493             Include suggested modules?
494              
495             =item tar_verbosity
496              
497             When CPAN.pm uses the tar command, which switch for the verbosity
498             shall be used? Choose 'none' for quiet operation, 'v' for file
499             name listing, 'vv' for full listing.
500              
501             Tar command verbosity level (none or v or vv)?
502              
503             =item term_is_latin
504              
505             The next option deals with the charset (a.k.a. character set) your
506             terminal supports. In general, CPAN is English speaking territory, so
507             the charset does not matter much but some CPAN have names that are
508             outside the ASCII range. If your terminal supports UTF-8, you should
509             say no to the next question. If it expects ISO-8859-1 (also known as
510             LATIN1) then you should say yes. If it supports neither, your answer
511             does not matter because you will not be able to read the names of some
512             authors anyway. If you answer no, names will be output in UTF-8.
513              
514             Your terminal expects ISO-8859-1 (yes/no)?
515              
516             =item term_ornaments
517              
518             When using Term::ReadLine, you can turn ornaments on so that your
519             input stands out against the output from CPAN.pm.
520              
521             Do you want to turn ornaments on?
522              
523             =item test_report
524              
525             The goal of the CPAN Testers project (http://testers.cpan.org/) is to
526             test as many CPAN packages as possible on as many platforms as
527             possible. This provides valuable feedback to module authors and
528             potential users to identify bugs or platform compatibility issues and
529             improves the overall quality and value of CPAN.
530              
531             One way you can contribute is to send test results for each module
532             that you install. If you install the CPAN::Reporter module, you have
533             the option to automatically generate and deliver test reports to CPAN
534             Testers whenever you run tests on a CPAN package.
535              
536             See the CPAN::Reporter documentation for additional details and
537             configuration settings. If your firewall blocks outgoing traffic,
538             you may need to configure CPAN::Reporter before sending reports.
539              
540             Generate test reports if CPAN::Reporter is installed (yes/no)?
541              
542             =item perl5lib_verbosity
543              
544             When CPAN.pm extends @INC via PERL5LIB, it prints a list of
545             directories added (or a summary of how many directories are
546             added). Choose 'v' to get this message, 'none' to suppress it.
547              
548             Verbosity level for PERL5LIB changes (none or v)?
549              
550             =item prefer_external_tar
551              
552             Per default all untar operations are done with the perl module
553             Archive::Tar; by setting this variable to true the external tar
554             command is used if available; on Unix this is usually preferred
555             because they have a reliable and fast gnutar implementation.
556              
557             Use the external tar program instead of Archive::Tar?
558              
559             =item trust_test_report_history
560              
561             When a distribution has already been tested by CPAN::Reporter on
562             this machine, CPAN can skip the test phase and just rely on the
563             test report history instead.
564              
565             Note that this will not apply to distributions that failed tests
566             because of missing dependencies. Also, tests can be run
567             regardless of the history using "force".
568              
569             Do you want to rely on the test report history (yes/no)?
570              
571             =item use_prompt_default
572              
573             When this is true, CPAN will set PERL_MM_USE_DEFAULT to a true
574             value. This causes ExtUtils::MakeMaker (and compatible) prompts
575             to use default values instead of stopping to prompt you to answer
576             questions. It also sets NONINTERACTIVE_TESTING to a true value to
577             signal more generally that distributions should not try to
578             interact with you.
579              
580             Do you want to use prompt defaults (yes/no)?
581              
582             =item use_sqlite
583              
584             CPAN::SQLite is a layer between the index files that are downloaded
585             from the CPAN and CPAN.pm that speeds up metadata queries and reduces
586             memory consumption of CPAN.pm considerably.
587              
588             Use CPAN::SQLite if available? (yes/no)?
589              
590             =item version_timeout
591              
592             This timeout prevents CPAN from hanging when trying to parse a
593             pathologically coded $VERSION from a module.
594              
595             The default is 15 seconds. If you set this value to 0, no timeout
596             will occur, but this is not recommended.
597              
598             Timeout for parsing module versions?
599              
600             =item yaml_load_code
601              
602             Both YAML.pm and YAML::Syck are capable of deserialising code. As this
603             requires a string eval, which might be a security risk, you can use
604             this option to enable or disable the deserialisation of code via
605             CPAN::DeferredCode. (Note: This does not work under perl 5.6)
606              
607             Do you want to enable code deserialisation (yes/no)?
608              
609             =item yaml_module
610              
611             At the time of this writing (2009-03) there are three YAML
612             implementations working: YAML, YAML::Syck, and YAML::XS. The latter
613             two are faster but need a C compiler installed on your system. There
614             may be more alternative YAML conforming modules. When I tried two
615             other players, YAML::Tiny and YAML::Perl, they seemed not powerful
616             enough to work with CPAN.pm. This may have changed in the meantime.
617              
618             Which YAML implementation would you prefer?
619              
620             =back
621              
622             =head1 LICENSE
623              
624             This program is free software; you can redistribute it and/or
625             modify it under the same terms as Perl itself.
626              
627             =cut
628              
629 4     4   39 use vars qw( %prompts );
  4         14  
  4         1540  
630              
631             {
632              
633             my @prompts = (
634              
635             auto_config => qq{
636             CPAN.pm requires configuration, but most of it can be done automatically.
637             If you answer 'no' below, you will enter an interactive dialog for each
638             configuration option instead.
639              
640             Would you like to configure as much as possible automatically?},
641              
642             auto_pick => qq{
643             Would you like me to automatically choose some CPAN mirror
644             sites for you? (This means connecting to the Internet)},
645              
646             config_intro => qq{
647              
648             The following questions are intended to help you with the
649             configuration. The CPAN module needs a directory of its own to cache
650             important index files and maybe keep a temporary mirror of CPAN files.
651             This may be a site-wide or a personal directory.
652              
653             },
654              
655             # cpan_home => qq{ },
656              
657             cpan_home_where => qq{
658              
659             First of all, I'd like to create this directory. Where?
660              
661             },
662              
663             external_progs => qq{
664              
665             The CPAN module will need a few external programs to work properly.
666             Please correct me, if I guess the wrong path for a program. Don't
667             panic if you do not have some of them, just press ENTER for those. To
668             disable the use of a program, you can type a space followed by ENTER.
669              
670             },
671              
672             proxy_intro => qq{
673              
674             If you're accessing the net via proxies, you can specify them in the
675             CPAN configuration or via environment variables. The variable in
676             the \$CPAN::Config takes precedence.
677              
678             },
679              
680             proxy_user => qq{
681              
682             If your proxy is an authenticating proxy, you can store your username
683             permanently. If you do not want that, just press ENTER. You will then
684             be asked for your username in every future session.
685              
686             },
687              
688             proxy_pass => qq{
689              
690             Your password for the authenticating proxy can also be stored
691             permanently on disk. If this violates your security policy, just press
692             ENTER. You will then be asked for the password in every future
693             session.
694              
695             },
696              
697             urls_intro => qq{
698             Now you need to choose your CPAN mirror sites. You can let me
699             pick mirrors for you, you can select them from a list or you
700             can enter them by hand.
701             },
702              
703             urls_picker_intro => qq{First, pick a nearby continent and country by typing in the number(s)
704             in front of the item(s) you want to select. You can pick several of
705             each, separated by spaces. Then, you will be presented with a list of
706             URLs of CPAN mirrors in the countries you selected, along with
707             previously selected URLs. Select some of those URLs, or just keep the
708             old list. Finally, you will be prompted for any extra URLs -- file:,
709             ftp:, or http: -- that host a CPAN mirror.
710              
711             You should select more than one (just in case the first isn't available).
712              
713             },
714              
715             password_warn => qq{
716              
717             Warning: Term::ReadKey seems not to be available, your password will
718             be echoed to the terminal!
719              
720             },
721              
722             install_help => qq{
723             Warning: You do not have write permission for Perl library directories.
724              
725             To install modules, you need to configure a local Perl library directory or
726             escalate your privileges. CPAN can help you by bootstrapping the local::lib
727             module or by configuring itself to use 'sudo' (if available). You may also
728             resolve this problem manually if you need to customize your setup.
729              
730             What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
731             },
732              
733             local_lib_installed => qq{
734             local::lib is installed. You must now add the following environment variables
735             to your shell configuration files (or registry, if you are on Windows) and
736             then restart your command line shell and CPAN before installing modules:
737              
738             },
739              
740             );
741              
742             die "Coding error in \@prompts declaration. Odd number of elements, above"
743             if (@prompts % 2);
744              
745             %prompts = @prompts;
746              
747             if (scalar(keys %prompts) != scalar(@prompts)/2) {
748             my %already;
749             for my $item (0..$#prompts) {
750             next if $item % 2;
751             die "$prompts[$item] is duplicated\n" if $already{$prompts[$item]}++;
752             }
753             }
754              
755             shift @podpara;
756             while (@podpara) {
757             warn "Alert: cannot parse my own manpage for init dialog" unless $podpara[0] =~ s/^=item\s+//;
758             my $name = shift @podpara;
759             my @para;
760             while (@podpara && $podpara[0] !~ /^=item/) {
761             push @para, shift @podpara;
762             }
763             $prompts{$name} = pop @para;
764             if (@para) {
765             $prompts{$name . "_intro"} = join "", map { "$_\n\n" } @para;
766             }
767             }
768              
769             }
770              
771             sub init {
772 0     0 0   my($configpm, %args) = @_;
773 4     4   31 use Config;
  4         21  
  4         35395  
774             # extra args after 'o conf init'
775 0 0 0       my $matcher = $args{args} && @{$args{args}} ? $args{args}[0] : '';
776 0 0         if ($matcher =~ /^\/(.*)\/$/) {
    0          
777             # case /regex/ => take the first, ignore the rest
778 0           $matcher = $1;
779 0           shift @{$args{args}};
  0            
780 0 0         if (@{$args{args}}) {
  0            
781 0           local $" = " ";
782 0           $CPAN::Frontend->mywarn("Ignoring excessive arguments '@{$args{args}}'");
  0            
783 0           $CPAN::Frontend->mysleep(2);
784             }
785             } elsif (0 == length $matcher) {
786             } elsif (0 && $matcher eq "~") { # extremely buggy, but a nice idea
787             my @unconfigured = sort grep { not exists $CPAN::Config->{$_}
788             or not defined $CPAN::Config->{$_}
789             or not length $CPAN::Config->{$_}
790             } keys %$CPAN::Config;
791             $matcher = "\\b(".join("|", @unconfigured).")\\b";
792             $CPAN::Frontend->mywarn("matcher[$matcher]");
793             } else {
794             # case WORD... => all arguments must be valid
795 0           for my $arg (@{$args{args}}) {
  0            
796 0 0         unless (exists $CPAN::HandleConfig::keys{$arg}) {
797 0           $CPAN::Frontend->mywarn("'$arg' is not a valid configuration variable\n");
798 0           return;
799             }
800             }
801 0           $matcher = "\\b(".join("|",@{$args{args}}).")\\b";
  0            
802             }
803 0 0         CPAN->debug("matcher[$matcher]") if $CPAN::DEBUG;
804              
805 0 0         unless ($CPAN::VERSION) {
806 0           require CPAN::Nox;
807             }
808 0           require CPAN::HandleConfig;
809 0           CPAN::HandleConfig::require_myconfig_or_config();
810 0   0       $CPAN::Config ||= {};
811 0           local($/) = "\n";
812 0           local($\) = "";
813 0           local($|) = 1;
814              
815 0           my($ans,$default); # why so half global?
816              
817             #
818             #= Files, directories
819             #
820              
821 0           local *_real_prompt;
822 0 0         if ( $args{autoconfig} ) {
    0          
823 0           $auto_config = 1;
824             } elsif ($matcher) {
825 0           $auto_config = 0;
826             } else {
827 0           my $_conf = prompt($prompts{auto_config}, "yes");
828 0 0 0       $auto_config = ($_conf and $_conf =~ /^y/i) ? 1 : 0;
829             }
830 0 0         CPAN->debug("auto_config[$auto_config]") if $CPAN::DEBUG;
831 0 0         if ( $auto_config ) {
832 0           local $^W = 0;
833             # prototype should match that of &MakeMaker::prompt
834 0           my $current_second = time;
835 0           my $current_second_count = 0;
836 0           my $i_am_mad = 0;
837             # silent prompting -- just quietly use default
838 0     0     *_real_prompt = sub { return $_[1] };
  0            
839             }
840              
841             #
842             # bootstrap local::lib or sudo
843             #
844 0 0 0       unless ( $matcher
      0        
      0        
845             || _can_write_to_libdirs() || _using_installbase() || _using_sudo()
846             ) {
847 0           local $auto_config = 0; # We *must* ask, even under autoconfig
848 0           local *_real_prompt; # We *must* show prompt
849 0           my_prompt_loop(install_help => 'local::lib', $matcher,
850             'local::lib|sudo|manual');
851             }
852 0   0       $CPAN::Config->{install_help} ||= ''; # Temporary to suppress warnings
853              
854 0 0 0       if (!$matcher or q{
855             build_dir
856             build_dir_reuse
857             cpan_home
858             keep_source_where
859             prefs_dir
860             } =~ /$matcher/) {
861 0 0         $CPAN::Frontend->myprint($prompts{config_intro}) unless $auto_config;
862              
863 0           init_cpan_home($matcher);
864              
865             my_dflt_prompt("keep_source_where",
866 0           File::Spec->catdir($CPAN::Config->{cpan_home},"sources"),
867             $matcher,
868             );
869             my_dflt_prompt("build_dir",
870 0           File::Spec->catdir($CPAN::Config->{cpan_home},"build"),
871             $matcher
872             );
873 0           my_yn_prompt(build_dir_reuse => 0, $matcher);
874             my_dflt_prompt("prefs_dir",
875 0           File::Spec->catdir($CPAN::Config->{cpan_home},"prefs"),
876             $matcher
877             );
878             }
879              
880             #
881             #= Config: auto_commit
882             #
883              
884 0           my_yn_prompt(auto_commit => 0, $matcher);
885              
886             #
887             #= Cache size, Index expire
888             #
889 0           my_dflt_prompt(build_cache => 100, $matcher);
890              
891 0           my_dflt_prompt(index_expire => 1, $matcher);
892 0           my_prompt_loop(scan_cache => 'atstart', $matcher, 'atstart|atexit|never');
893 0           my_yn_prompt(cleanup_after_install => 0, $matcher);
894              
895             #
896             #= cache_metadata
897             #
898              
899 0           my_yn_prompt(cache_metadata => 1, $matcher);
900 0           my_yn_prompt(use_sqlite => 0, $matcher);
901              
902             #
903             #= Do we follow PREREQ_PM?
904             #
905              
906 0           my_prompt_loop(prerequisites_policy => 'follow', $matcher,
907             'follow|ask|ignore');
908 0           my_prompt_loop(build_requires_install_policy => 'yes', $matcher,
909             'yes|no|ask/yes|ask/no');
910 0           my_yn_prompt(recommends_policy => 1, $matcher);
911 0           my_yn_prompt(suggests_policy => 0, $matcher);
912              
913             #
914             #= Module::Signature
915             #
916 0           my_yn_prompt(check_sigs => 0, $matcher);
917              
918             #
919             #= CPAN::Reporter
920             #
921 0 0 0       if (!$matcher or 'test_report' =~ /$matcher/) {
922 0           my_yn_prompt(test_report => 0, $matcher);
923 0 0 0       if (
      0        
      0        
924             $matcher &&
925             $CPAN::Config->{test_report} &&
926             $CPAN::META->has_inst("CPAN::Reporter") &&
927             CPAN::Reporter->can('configure')
928             ) {
929 0           my $_conf = prompt("Would you like me configure CPAN::Reporter now?", "yes");
930 0 0         if ($_conf =~ /^y/i) {
931 0           $CPAN::Frontend->myprint("\nProceeding to configure CPAN::Reporter.\n");
932 0           CPAN::Reporter::configure();
933 0           $CPAN::Frontend->myprint("\nReturning to CPAN configuration.\n");
934             }
935             }
936             }
937              
938 0           my_yn_prompt(trust_test_report_history => 0, $matcher);
939              
940             #
941             #= YAML vs. YAML::Syck
942             #
943 0 0 0       if (!$matcher or "yaml_module" =~ /$matcher/) {
944 0           my_dflt_prompt(yaml_module => "YAML", $matcher);
945 0           my $old_v = $CPAN::Config->{load_module_verbosity};
946 0           $CPAN::Config->{load_module_verbosity} = q[none];
947 0 0 0       if (!$auto_config && !$CPAN::META->has_inst($CPAN::Config->{yaml_module})) {
948 0           $CPAN::Frontend->mywarn
949             ("Warning (maybe harmless): '$CPAN::Config->{yaml_module}' not installed.\n");
950 0           $CPAN::Frontend->mysleep(3);
951             }
952 0           $CPAN::Config->{load_module_verbosity} = $old_v;
953             }
954              
955             #
956             #= YAML code deserialisation
957             #
958 0           my_yn_prompt(yaml_load_code => 0, $matcher);
959              
960             #
961             #= External programs
962             #
963 0           my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
964             $CPAN::Frontend->myprint($prompts{external_progs})
965 0 0 0       if !$matcher && !$auto_config;
966 0           _init_external_progs($matcher, {
967             path => \@path,
968             progs => [ qw/make bzip2 gzip tar unzip gpg patch applypatch/ ],
969             shortcut => 0
970             });
971 0           _init_external_progs($matcher, {
972             path => \@path,
973             progs => [ qw/wget curl lynx ncftpget ncftp ftp/ ],
974             shortcut => 1
975             });
976              
977             {
978             my $path = $CPAN::Config->{'pager'} ||
979             $ENV{PAGER} || find_exe("less",\@path) ||
980 0   0       find_exe("more",\@path) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
981             || "more";
982 0           my_dflt_prompt(pager => $path, $matcher);
983             }
984              
985             {
986 0           my $path = $CPAN::Config->{'shell'};
  0            
987 0 0 0       if ($path && File::Spec->file_name_is_absolute($path)) {
988 0 0         $CPAN::Frontend->mywarn("Warning: configured $path does not exist\n")
989             unless -e $path;
990 0           $path = "";
991             }
992 0   0       $path ||= $ENV{SHELL};
993 0 0 0       $path ||= $ENV{COMSPEC} if $^O eq "MSWin32";
994 0 0         if ($^O eq 'MacOS') {
995 0           $CPAN::Config->{'shell'} = 'not_here';
996             } else {
997 0 0 0       $path ||= 'sh', $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
998 0           my_dflt_prompt(shell => $path, $matcher);
999             }
1000             }
1001              
1002             {
1003 0           my $tar = $CPAN::Config->{tar};
  0            
  0            
1004 0           my $prefer_external_tar = $CPAN::Config->{prefer_external_tar}; # XXX not yet supported
1005 0 0         unless (defined $prefer_external_tar) {
1006 0 0         if ($^O =~ /(MSWin32|solaris)/) {
    0          
1007             # both have a record of broken tars
1008 0           $prefer_external_tar = 0;
1009             } elsif ($tar) {
1010 0           $prefer_external_tar = 1;
1011             } else {
1012 0           $prefer_external_tar = 0;
1013             }
1014             }
1015 0           my_yn_prompt(prefer_external_tar => $prefer_external_tar, $matcher);
1016             }
1017              
1018             #
1019             # verbosity
1020             #
1021              
1022 0           my_prompt_loop(tar_verbosity => 'none', $matcher,
1023             'none|v|vv');
1024 0           my_prompt_loop(load_module_verbosity => 'none', $matcher,
1025             'none|v');
1026 0           my_prompt_loop(perl5lib_verbosity => 'none', $matcher,
1027             'none|v');
1028 0           my_yn_prompt(inhibit_startup_message => 0, $matcher);
1029              
1030             #
1031             #= Installer, arguments to make etc.
1032             #
1033              
1034 0           my_prompt_loop(prefer_installer => 'MB', $matcher, 'MB|EUMM|RAND');
1035              
1036 0 0 0       if (!$matcher or 'makepl_arg make_arg' =~ /$matcher/) {
1037 0           my_dflt_prompt(makepl_arg => "", $matcher);
1038 0           my_dflt_prompt(make_arg => "", $matcher);
1039 0 0         if ( $CPAN::Config->{makepl_arg} =~ /LIBS=|INC=/ ) {
1040 0           $CPAN::Frontend->mywarn(
1041             "Warning: Using LIBS or INC in makepl_arg will likely break distributions\n" .
1042             "that specify their own LIBS or INC options in Makefile.PL.\n"
1043             );
1044             }
1045              
1046             }
1047              
1048 0           require CPAN::HandleConfig;
1049 0 0         if (exists $CPAN::HandleConfig::keys{make_install_make_command}) {
1050             # as long as Windows needs $self->_build_command, we cannot
1051             # support sudo on windows :-)
1052 0   0       my $default = $CPAN::Config->{make} || "";
1053 0 0 0       if ( $default && $CPAN::Config->{install_help} eq 'sudo' ) {
1054 0 0         if ( find_exe('sudo') ) {
1055 0           $default = "sudo $default";
1056             delete $CPAN::Config->{make_install_make_command}
1057 0 0         unless $CPAN::Config->{make_install_make_command} =~ /sudo/;
1058             }
1059             else {
1060 0           $CPAN::Frontend->mywarnonce("Could not find 'sudo' in PATH\n");
1061             }
1062             }
1063 0           my_dflt_prompt(make_install_make_command => $default, $matcher);
1064             }
1065              
1066 0   0       my_dflt_prompt(make_install_arg => $CPAN::Config->{make_arg} || "",
1067             $matcher);
1068              
1069 0           my_dflt_prompt(mbuildpl_arg => "", $matcher);
1070 0           my_dflt_prompt(mbuild_arg => "", $matcher);
1071              
1072 0 0 0       if (exists $CPAN::HandleConfig::keys{mbuild_install_build_command}
1073             and $^O ne "MSWin32") {
1074             # as long as Windows needs $self->_build_command, we cannot
1075             # support sudo on windows :-)
1076 0 0         my $default = $^O eq 'VMS' ? '@Build.com' : "./Build";
1077 0 0         if ( $CPAN::Config->{install_help} eq 'sudo' ) {
1078 0 0         if ( find_exe('sudo') ) {
1079 0           $default = "sudo $default";
1080             delete $CPAN::Config->{mbuild_install_build_command}
1081 0 0         unless $CPAN::Config->{mbuild_install_build_command} =~ /sudo/;
1082             }
1083             else {
1084 0           $CPAN::Frontend->mywarnonce("Could not find 'sudo' in PATH\n");
1085             }
1086             }
1087 0           my_dflt_prompt(mbuild_install_build_command => $default, $matcher);
1088             }
1089              
1090 0           my_dflt_prompt(mbuild_install_arg => "", $matcher);
1091              
1092             #
1093             #== use_prompt_default
1094             #
1095 0           my_yn_prompt(use_prompt_default => 0, $matcher);
1096              
1097             #
1098             #= Alarm period
1099             #
1100              
1101 0           my_dflt_prompt(inactivity_timeout => 0, $matcher);
1102 0           my_dflt_prompt(version_timeout => 15, $matcher);
1103              
1104             #
1105             #== halt_on_failure
1106             #
1107 0           my_yn_prompt(halt_on_failure => 0, $matcher);
1108              
1109             #
1110             #= Proxies
1111             #
1112              
1113 0           my @proxy_vars = qw/ftp_proxy http_proxy no_proxy/;
1114 0           my @proxy_user_vars = qw/proxy_user proxy_pass/;
1115 0 0 0       if (!$matcher or "@proxy_vars @proxy_user_vars" =~ /$matcher/) {
1116 0 0         $CPAN::Frontend->myprint($prompts{proxy_intro}) unless $auto_config;
1117              
1118 0           for (@proxy_vars) {
1119 0           $prompts{$_} = "Your $_?";
1120 0   0       my_dflt_prompt($_ => $ENV{$_}||"", $matcher);
1121             }
1122              
1123 0 0 0       if ($CPAN::Config->{ftp_proxy} ||
1124             $CPAN::Config->{http_proxy}) {
1125              
1126 0   0       $default = $CPAN::Config->{proxy_user} || $CPAN::LWP::UserAgent::USER || "";
1127              
1128 0 0         $CPAN::Frontend->myprint($prompts{proxy_user}) unless $auto_config;
1129              
1130 0 0         if ($CPAN::Config->{proxy_user} = prompt("Your proxy user id?",$default)) {
1131 0 0         $CPAN::Frontend->myprint($prompts{proxy_pass}) unless $auto_config;
1132              
1133 0 0         if ($CPAN::META->has_inst("Term::ReadKey")) {
1134 0           Term::ReadKey::ReadMode("noecho");
1135             } else {
1136 0 0         $CPAN::Frontend->myprint($prompts{password_warn}) unless $auto_config;
1137             }
1138 0           $CPAN::Config->{proxy_pass} = prompt_no_strip("Your proxy password?");
1139 0 0         if ($CPAN::META->has_inst("Term::ReadKey")) {
1140 0           Term::ReadKey::ReadMode("restore");
1141             }
1142 0 0         $CPAN::Frontend->myprint("\n\n") unless $auto_config;
1143             }
1144             }
1145             }
1146              
1147             #
1148             #= how plugins work
1149             #
1150              
1151             # XXX MISSING: my_array_prompt to be used with plugins. We did something like this near
1152             # git log -p fd68f8f5e33f4cecea4fdb7abc5ee19c12f138f0..test-notest-test-dependency
1153             # Need to do similar steps for plugin_list. As long as we do not support it here, people
1154             # must use the cpan shell prompt to write something like
1155             # o conf plugin_list push CPAN::Plugin::Specfile=dir,/tmp/foo-20141013,...
1156             # o conf commit
1157              
1158             #
1159             #= how FTP works
1160             #
1161              
1162 0           my_yn_prompt(ftp_passive => 1, $matcher);
1163              
1164             #
1165             #= how cwd works
1166             #
1167              
1168 0           my_prompt_loop(getcwd => 'cwd', $matcher,
1169             'cwd|getcwd|fastcwd|getdcwd|backtickcwd');
1170              
1171             #
1172             #= the CPAN shell itself (prompt, color)
1173             #
1174              
1175 0           my_yn_prompt(commandnumber_in_prompt => 1, $matcher);
1176 0           my_yn_prompt(term_ornaments => 1, $matcher);
1177 0 0         if ("colorize_output colorize_print colorize_warn colorize_debug" =~ $matcher) {
1178 0           my_yn_prompt(colorize_output => 0, $matcher);
1179 0 0         if ($CPAN::Config->{colorize_output}) {
1180 0 0         if ($CPAN::META->has_inst("Term::ANSIColor")) {
1181 0           my $T="gYw";
1182 0 0         $CPAN::Frontend->myprint( " on_ on_y ".
1183             " on_ma on_\n") unless $auto_config;
1184 0 0         $CPAN::Frontend->myprint( " on_black on_red green ellow ".
1185             "on_blue genta on_cyan white\n") unless $auto_config;
1186              
1187 0           for my $FG ("", "bold",
1188 0           map {$_,"bold $_"} "black","red","green",
1189             "yellow","blue",
1190             "magenta",
1191             "cyan","white") {
1192 0 0         $CPAN::Frontend->myprint(sprintf( "%12s ", $FG)) unless $auto_config;
1193 0           for my $BG ("",map {"on_$_"} qw(black red green yellow
  0            
1194             blue magenta cyan white)) {
1195 0 0 0       $CPAN::Frontend->myprint( $FG||$BG ?
    0          
1196             Term::ANSIColor::colored(" $T ","$FG $BG") : " $T ") unless $auto_config;
1197             }
1198 0 0         $CPAN::Frontend->myprint( "\n" ) unless $auto_config;
1199             }
1200 0 0         $CPAN::Frontend->myprint( "\n" ) unless $auto_config;
1201             }
1202 0           for my $tuple (
1203             ["colorize_print", "bold blue on_white"],
1204             ["colorize_warn", "bold red on_white"],
1205             ["colorize_debug", "black on_cyan"],
1206             ) {
1207 0           my_dflt_prompt($tuple->[0] => $tuple->[1], $matcher);
1208 0 0         if ($CPAN::META->has_inst("Term::ANSIColor")) {
1209 0           eval { Term::ANSIColor::color($CPAN::Config->{$tuple->[0]})};
  0            
1210 0 0         if ($@) {
1211 0           $CPAN::Config->{$tuple->[0]} = $tuple->[1];
1212 0           $CPAN::Frontend->mywarn($@."setting to default '$tuple->[1]'\n");
1213             }
1214             }
1215             }
1216             }
1217             }
1218              
1219             #
1220             #== term_is_latin
1221             #
1222              
1223 0           my_yn_prompt(term_is_latin => 1, $matcher);
1224              
1225             #
1226             #== save history in file 'histfile'
1227             #
1228              
1229 0 0 0       if (!$matcher or 'histfile histsize' =~ /$matcher/) {
1230 0 0         $CPAN::Frontend->myprint($prompts{histfile_intro}) unless $auto_config;
1231             defined($default = $CPAN::Config->{histfile}) or
1232 0 0         $default = File::Spec->catfile($CPAN::Config->{cpan_home},"histfile");
1233 0           my_dflt_prompt(histfile => $default, $matcher);
1234              
1235 0 0         if ($CPAN::Config->{histfile}) {
1236 0 0         defined($default = $CPAN::Config->{histsize}) or $default = 100;
1237 0           my_dflt_prompt(histsize => $default, $matcher);
1238             }
1239             }
1240              
1241             #
1242             #== do an ls on the m or the d command
1243             #
1244 0           my_yn_prompt(show_upload_date => 0, $matcher);
1245              
1246             #
1247             #== verbosity at the end of the r command
1248             #
1249 0 0 0       if (!$matcher
      0        
1250             or 'show_unparsable_versions' =~ /$matcher/
1251             or 'show_zero_versions' =~ /$matcher/
1252             ) {
1253 0           my_yn_prompt(show_unparsable_versions => 0, $matcher);
1254 0           my_yn_prompt(show_zero_versions => 0, $matcher);
1255             }
1256              
1257             #
1258             #= MIRRORED.BY and conf_sites()
1259             #
1260              
1261             # Let's assume they want to use the internet and make them turn it
1262             # off if they really don't.
1263 0           my_yn_prompt("connect_to_internet_ok" => 1, $matcher);
1264              
1265             # Allow matching but don't show during manual config
1266 0 0         if ($matcher) {
1267 0 0         if ("randomize_urllist" =~ $matcher) {
1268 0           my_dflt_prompt(randomize_urllist => 0, $matcher);
1269             }
1270 0 0         if ("ftpstats_size" =~ $matcher) {
1271 0           my_dflt_prompt(ftpstats_size => 99, $matcher);
1272             }
1273 0 0         if ("ftpstats_period" =~ $matcher) {
1274 0           my_dflt_prompt(ftpstats_period => 14, $matcher);
1275             }
1276             }
1277              
1278 0   0       $CPAN::Config->{urllist} ||= [];
1279              
1280 0 0 0       if ($auto_config) {
    0          
1281 0 0         if(@{ $CPAN::Config->{urllist} }) {
  0            
1282 0           $CPAN::Frontend->myprint(
1283             "Your 'urllist' is already configured. Type 'o conf init urllist' to change it.\n"
1284             );
1285             }
1286             else {
1287 0           $CPAN::Config->{urllist} = [ 'http://www.cpan.org/' ];
1288             }
1289             }
1290             elsif (!$matcher || "urllist" =~ $matcher) {
1291 0           _do_pick_mirrors();
1292             }
1293              
1294 0 0         if ($auto_config) {
1295 0           $CPAN::Frontend->myprint(
1296             "\nAutoconfiguration complete.\n"
1297             );
1298 0           $auto_config = 0; # reset
1299             }
1300              
1301             # bootstrap local::lib now if requested
1302 0 0         if ( $CPAN::Config->{install_help} eq 'local::lib' ) {
1303 0 0         if ( ! @{ $CPAN::Config->{urllist} } ) {
  0            
1304 0           $CPAN::Frontend->myprint(
1305             "Skipping local::lib bootstrap because 'urllist' is not configured.\n"
1306             );
1307             }
1308             else {
1309 0           $CPAN::Frontend->myprint("\nAttempting to bootstrap local::lib...\n");
1310 0           $CPAN::Frontend->myprint("\nWriting $configpm for bootstrap...\n");
1311 0           delete $CPAN::Config->{install_help}; # temporary only
1312 0           CPAN::HandleConfig->commit;
1313 0           my($dist, $locallib);
1314 0           $locallib = CPAN::Shell->expand('Module', 'local::lib');
1315 0 0 0       if ( $locallib and $dist = $locallib->distribution ) {
1316             # this is a hack to force bootstrapping
1317 0           $dist->{prefs}{pl}{commandline} = "$^X Makefile.PL --bootstrap";
1318             # Set @INC for this process so we find things as they bootstrap
1319 0           require lib;
1320 0           lib->import(_local_lib_inc_path());
1321 0           eval { $dist->install };
  0            
1322             }
1323 0 0 0       if ( ! $dist || (my $err = $@) ) {
1324 0   0       $err ||= 'Could not locate local::lib in the CPAN index';
1325 0           $CPAN::Frontend->mywarn("Error bootstrapping local::lib: $@\n");
1326 0           $CPAN::Frontend->myprint("From the CPAN Shell, you might try 'look local::lib' and \n"
1327             . "run 'perl Makefile --bootstrap' and see if that is successful. Then\n"
1328             . "restart your CPAN client\n"
1329             );
1330             }
1331             else {
1332 0           _local_lib_config();
1333             }
1334             }
1335             }
1336              
1337             # install_help is temporary for configuration and not saved
1338 0           delete $CPAN::Config->{install_help};
1339              
1340 0           $CPAN::Frontend->myprint("\n");
1341 0 0 0       if ($matcher && !$CPAN::Config->{auto_commit}) {
1342 0           $CPAN::Frontend->myprint("Please remember to call 'o conf commit' to ".
1343             "make the config permanent!\n");
1344             } else {
1345 0           CPAN::HandleConfig->commit;
1346             }
1347              
1348 0 0         if (! $matcher) {
1349 0           $CPAN::Frontend->myprint(
1350             "\nYou can re-run configuration any time with 'o conf init' in the CPAN shell\n"
1351             );
1352             }
1353              
1354             }
1355              
1356             sub _local_lib_config {
1357             # Set environment stuff for this process
1358 0     0     require local::lib;
1359              
1360             # Tell user about environment vars to set
1361 0           $CPAN::Frontend->myprint($prompts{local_lib_installed});
1362 0   0       local $ENV{SHELL} = $CPAN::Config->{shell} || $ENV{SHELL};
1363 0           my $shellvars = local::lib->environment_vars_string_for(_local_lib_path());
1364 0           $CPAN::Frontend->myprint($shellvars);
1365              
1366             # Set %ENV after getting string above
1367 0           my %env = local::lib->build_environment_vars_for(_local_lib_path(), 1);
1368 0           while ( my ($k, $v) = each %env ) {
1369 0           $ENV{$k} = $v;
1370             }
1371              
1372             # Offer to mangle the shell config
1373 0           my $munged_rc;
1374 0 0         if ( my $rc = _find_shell_config() ) {
1375 0           local $auto_config = 0; # We *must* ask, even under autoconfig
1376 0           local *_real_prompt; # We *must* show prompt
1377 0           my $_conf = prompt(
1378             "\nWould you like me to append that to $rc now?", "yes"
1379             );
1380 0 0         if ($_conf =~ /^y/i) {
1381 0           open my $fh, ">>", $rc;
1382 0           print {$fh} "\n$shellvars";
  0            
1383 0           close $fh;
1384 0           $munged_rc++;
1385             }
1386             }
1387              
1388             # Warn at exit time
1389 0 0         if ($munged_rc) {
1390 0           push @{$CPAN::META->_exit_messages}, << "HERE";
  0            
1391              
1392             *** Remember to restart your shell before running cpan again ***
1393             HERE
1394             }
1395             else {
1396 0           push @{$CPAN::META->_exit_messages}, << "HERE";
  0            
1397              
1398             *** Remember to add these environment variables to your shell config
1399             and restart your shell before running cpan again ***
1400              
1401             $shellvars
1402             HERE
1403             }
1404             }
1405              
1406             {
1407             my %shell_rc_map = (
1408             map { $_ => ".${_}rc" } qw/ bash tcsh csh /,
1409             map { $_ => ".profile" } qw/dash ash sh/,
1410             zsh => ".zshenv",
1411             );
1412              
1413             sub _find_shell_config {
1414 0     0     my $shell = File::Basename::basename($CPAN::Config->{shell});
1415 0 0         if ( my $rc = $shell_rc_map{$shell} ) {
1416 0           my $path = File::Spec->catfile($ENV{HOME}, $rc);
1417 0 0         return $path if -w $path;
1418             }
1419             }
1420             }
1421              
1422              
1423             sub _local_lib_inc_path {
1424 0     0     return File::Spec->catdir(_local_lib_path(), qw/lib perl5/);
1425             }
1426              
1427             sub _local_lib_path {
1428 0     0     return File::Spec->catdir(_local_lib_home(), 'perl5');
1429             }
1430              
1431             # Adapted from resolve_home_path() in local::lib -- this is where
1432             # local::lib thinks the user's home is
1433             {
1434             my $local_lib_home;
1435             sub _local_lib_home {
1436 0   0 0     $local_lib_home ||= File::Spec->rel2abs( do {
1437 0 0 0       if ($CPAN::META->has_usable("File::HomeDir") && File::HomeDir->VERSION >= 0.65) {
    0          
1438 0           File::HomeDir->my_home;
1439             } elsif (defined $ENV{HOME}) {
1440 0           $ENV{HOME};
1441             } else {
1442 0 0         (getpwuid $<)[7] || "~";
1443             }
1444             });
1445             }
1446             }
1447              
1448             sub _do_pick_mirrors {
1449 0     0     local *_real_prompt;
1450 0           *_real_prompt = \&CPAN::Shell::colorable_makemaker_prompt;
1451 0           $CPAN::Frontend->myprint($prompts{urls_intro});
1452             # Only prompt for auto-pick if Net::Ping is new enough to do timings
1453 0           my $_conf = 'n';
1454 0 0 0       if ( $CPAN::META->has_usable("Net::Ping") && CPAN::Version->vgt(Net::Ping->VERSION, '2.13')) {
1455 0           $_conf = prompt($prompts{auto_pick}, "yes");
1456             } else {
1457 0           prompt("Autoselection disabled due to Net::Ping missing or insufficient. Please press ENTER");
1458             }
1459 0           my @old_list = @{ $CPAN::Config->{urllist} };
  0            
1460 0 0         if ( $_conf =~ /^y/i ) {
1461 0 0         conf_sites( auto_pick => 1 ) or bring_your_own();
1462             }
1463             else {
1464 0 0         _print_urllist('Current') if @old_list;
1465 0 0         my $msg = scalar @old_list
1466             ? "\nWould you like to edit the urllist or pick new mirrors from a list?"
1467             : "\nWould you like to pick from the CPAN mirror list?" ;
1468 0           my $_conf = prompt($msg, "yes");
1469 0 0         if ( $_conf =~ /^y/i ) {
1470 0           conf_sites();
1471             }
1472 0           bring_your_own();
1473             }
1474 0           _print_urllist('New');
1475             }
1476              
1477             sub _init_external_progs {
1478 0     0     my($matcher,$args) = @_;
1479 0           my $PATH = $args->{path};
1480 0           my @external_progs = @{ $args->{progs} };
  0            
1481 0           my $shortcut = $args->{shortcut};
1482 0           my $showed_make_warning;
1483              
1484 0 0 0       if (!$matcher or "@external_progs" =~ /$matcher/) {
1485 0           my $old_warn = $^W;
1486 0 0         local $^W if $^O eq 'MacOS';
1487 0           local $^W = $old_warn;
1488 0           my $progname;
1489 0           for $progname (@external_progs) {
1490 0 0 0       next if $matcher && $progname !~ /$matcher/;
1491 0 0         if ($^O eq 'MacOS') {
1492 0           $CPAN::Config->{$progname} = 'not_here';
1493 0           next;
1494             }
1495              
1496 0           my $progcall = $progname;
1497 0 0         unless ($matcher) {
1498             # we really don't need ncftp if we have ncftpget, but
1499             # if they chose this dialog via matcher, they shall have it
1500 0 0 0       next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " ";
1501             }
1502             my $path = $CPAN::Config->{$progname}
1503 0   0       || $Config::Config{$progname}
1504             || "";
1505 0 0         if (File::Spec->file_name_is_absolute($path)) {
    0          
1506             # testing existence is not good enough, some have these exe
1507             # extensions
1508              
1509             # warn "Warning: configured $path does not exist\n" unless -e $path;
1510             # $path = "";
1511             } elsif ($path =~ /^\s+$/) {
1512             # preserve disabled programs
1513             } else {
1514 0           $path = '';
1515             }
1516 0 0         unless ($path) {
1517             # e.g. make -> nmake
1518 0 0         $progcall = $Config::Config{$progname} if $Config::Config{$progname};
1519             }
1520              
1521 0   0       $path ||= find_exe($progcall,$PATH);
1522 0 0         unless ($path) { # not -e $path, because find_exe already checked that
1523 0           local $"=";";
1524 0 0         $CPAN::Frontend->mywarn("Warning: $progcall not found in PATH[@$PATH]\n") unless $auto_config;
1525 0 0         _beg_for_make(), $showed_make_warning++ if $progname eq "make";
1526             }
1527 0           $prompts{$progname} = "Where is your $progname program?";
1528 0           $path = my_dflt_prompt($progname,$path,$matcher,1); # 1 => no strip spaces
1529 0           my $disabling = $path =~ m/^\s*$/;
1530              
1531             # don't let them disable or misconfigure make without warning
1532 0 0 0       if ( $progname eq "make" && ( $disabling || ! _check_found($path) ) ) {
    0 0        
    0          
1533 0 0 0       if ( $disabling && $showed_make_warning ) {
1534 0           next;
1535             }
1536             else {
1537 0 0         _beg_for_make() unless $showed_make_warning++;
1538 0           undef $CPAN::Config->{$progname};
1539 0           $CPAN::Frontend->mywarn("Press SPACE and ENTER to disable make (NOT RECOMMENDED)\n");
1540 0           redo;
1541             }
1542             }
1543             elsif ( $disabling ) {
1544 0           next;
1545             }
1546             elsif ( _check_found( $CPAN::Config->{$progname} ) ) {
1547 0 0 0       last if $shortcut && !$matcher;
1548             }
1549             else {
1550 0           undef $CPAN::Config->{$progname};
1551 0           $CPAN::Frontend->mywarn("Press SPACE and ENTER to disable $progname\n");
1552 0           redo;
1553             }
1554             }
1555             }
1556             }
1557              
1558             sub _check_found {
1559 0     0     my ($prog) = @_;
1560 0 0         if ( ! -f $prog ) {
    0          
1561 0 0         $CPAN::Frontend->mywarn("Warning: '$prog' does not exist\n")
1562             unless $auto_config;
1563 0           return;
1564             }
1565             elsif ( ! -x $prog ) {
1566 0 0         $CPAN::Frontend->mywarn("Warning: '$prog' is not executable\n")
1567             unless $auto_config;
1568 0           return;
1569             }
1570 0           return 1;
1571             }
1572              
1573             sub _beg_for_make {
1574 0     0     $CPAN::Frontend->mywarn(<<"HERE");
1575              
1576             ALERT: 'make' is an essential tool for building perl Modules.
1577             Please make sure you have 'make' (or some equivalent) working.
1578              
1579             HERE
1580 0 0         if ($^O eq "MSWin32") {
1581 0           $CPAN::Frontend->mywarn(<<"HERE");
1582             Windows users may want to follow this procedure when back in the CPAN shell:
1583              
1584             look YVES/scripts/alien_nmake.pl
1585             perl alien_nmake.pl
1586              
1587             This will install nmake on your system which can be used as a 'make'
1588             substitute. You can then revisit this dialog with
1589              
1590             o conf init make
1591              
1592             HERE
1593             }
1594             }
1595              
1596             sub init_cpan_home {
1597 0     0 0   my($matcher) = @_;
1598 0 0 0       if (!$matcher or 'cpan_home' =~ /$matcher/) {
1599             my $cpan_home =
1600 0   0       $CPAN::Config->{cpan_home} || CPAN::HandleConfig::cpan_home();
1601 0 0         if (-d $cpan_home) {
1602 0 0         $CPAN::Frontend->myprint(
1603             "\nI see you already have a directory\n" .
1604             "\n$cpan_home\n" .
1605             "Shall we use it as the general CPAN build and cache directory?\n\n"
1606             ) unless $auto_config;
1607             } else {
1608             # no cpan-home, must prompt and get one
1609 0 0         $CPAN::Frontend->myprint($prompts{cpan_home_where}) unless $auto_config;
1610             }
1611              
1612 0           my $default = $cpan_home;
1613 0           my $loop = 0;
1614 0           my($last_ans,$ans);
1615 0 0         $CPAN::Frontend->myprint(" \n") unless $auto_config;
1616 0           PROMPT: while ($ans = prompt("CPAN build and cache directory?",$default)) {
1617 0 0         if (File::Spec->file_name_is_absolute($ans)) {
1618 0           my @cpan_home = split /[\/\\]/, $ans;
1619 0           DIR: for my $dir (@cpan_home) {
1620 0 0 0       if ($dir =~ /^~/ and (!$last_ans or $ans ne $last_ans)) {
      0        
1621 0           $CPAN::Frontend
1622             ->mywarn("Warning: a tilde in the path will be ".
1623             "taken as a literal tilde. Please ".
1624             "confirm again if you want to keep it\n");
1625 0           $last_ans = $default = $ans;
1626 0           next PROMPT;
1627             }
1628             }
1629             } else {
1630 0           require Cwd;
1631 0           my $cwd = Cwd::cwd();
1632 0           my $absans = File::Spec->catdir($cwd,$ans);
1633 0           $CPAN::Frontend->mywarn("The path '$ans' is not an ".
1634             "absolute path. Please specify ".
1635             "an absolute path\n");
1636 0           $default = $absans;
1637 0           next PROMPT;
1638             }
1639 0           eval { File::Path::mkpath($ans); }; # dies if it can't
  0            
1640 0 0         if ($@) {
1641 0           $CPAN::Frontend->mywarn("Couldn't create directory $ans.\n".
1642             "Please retry.\n");
1643 0           next PROMPT;
1644             }
1645 0 0 0       if (-d $ans && -w _) {
1646 0           last PROMPT;
1647             } else {
1648 0           $CPAN::Frontend->mywarn("Couldn't find directory $ans\n".
1649             "or directory is not writable. Please retry.\n");
1650 0 0         if (++$loop > 5) {
1651 0           $CPAN::Frontend->mydie("Giving up");
1652             }
1653             }
1654             }
1655 0           $CPAN::Config->{cpan_home} = $ans;
1656             }
1657             }
1658              
1659             sub my_dflt_prompt {
1660 0     0 0   my ($item, $dflt, $m, $no_strip) = @_;
1661 0   0       my $default = $CPAN::Config->{$item} || $dflt;
1662              
1663 0 0 0       if (!$auto_config && (!$m || $item =~ /$m/)) {
      0        
1664 0 0         if (my $intro = $prompts{$item . "_intro"}) {
1665 0           $CPAN::Frontend->myprint($intro);
1666             }
1667 0           $CPAN::Frontend->myprint(" <$item>\n");
1668             $CPAN::Config->{$item} =
1669             $no_strip ? prompt_no_strip($prompts{$item}, $default)
1670 0 0         : prompt( $prompts{$item}, $default);
1671             } else {
1672 0           $CPAN::Config->{$item} = $default;
1673             }
1674 0           return $CPAN::Config->{$item};
1675             }
1676              
1677             sub my_yn_prompt {
1678 0     0 0   my ($item, $dflt, $m) = @_;
1679 0           my $default;
1680 0 0         defined($default = $CPAN::Config->{$item}) or $default = $dflt;
1681              
1682             # $DB::single = 1;
1683 0 0 0       if (!$auto_config && (!$m || $item =~ /$m/)) {
      0        
1684 0 0         if (my $intro = $prompts{$item . "_intro"}) {
1685 0           $CPAN::Frontend->myprint($intro);
1686             }
1687 0           $CPAN::Frontend->myprint(" <$item>\n");
1688 0 0         my $ans = prompt($prompts{$item}, $default ? 'yes' : 'no');
1689 0 0         $CPAN::Config->{$item} = ($ans =~ /^[y1]/i ? 1 : 0);
1690             } else {
1691 0           $CPAN::Config->{$item} = $default;
1692             }
1693             }
1694              
1695             sub my_prompt_loop {
1696 0     0 0   my ($item, $dflt, $m, $ok) = @_;
1697 0   0       my $default = $CPAN::Config->{$item} || $dflt;
1698 0           my $ans;
1699              
1700 0 0 0       if (!$auto_config && (!$m || $item =~ /$m/)) {
      0        
1701 0           my $intro = $prompts{$item . "_intro"};
1702 0 0         $CPAN::Frontend->myprint($intro) if defined $intro;
1703 0           $CPAN::Frontend->myprint(" <$item>\n");
1704 0           do { $ans = prompt($prompts{$item}, $default);
  0            
1705             } until $ans =~ /$ok/;
1706 0           $CPAN::Config->{$item} = $ans;
1707             } else {
1708 0           $CPAN::Config->{$item} = $default;
1709             }
1710             }
1711              
1712              
1713             # Here's the logic about the MIRRORED.BY file. There are a number of scenarios:
1714             # (1) We have a cached MIRRORED.BY file
1715             # (1a) We're auto-picking
1716             # - Refresh it automatically if it's old
1717             # (1b) Otherwise, ask if using cached is ok. If old, default to no.
1718             # - If cached is not ok, get it from the Internet. If it succeeds we use
1719             # the new file. Otherwise, we use the old file.
1720             # (2) We don't have a copy at all
1721             # (2a) If we are allowed to connect, we try to get a new copy. If it succeeds,
1722             # we use it, otherwise, we warn about failure
1723             # (2b) If we aren't allowed to connect,
1724              
1725             sub conf_sites {
1726 0     0 0   my %args = @_;
1727             # auto pick implies using the internet
1728 0 0         $CPAN::Config->{connect_to_internet_ok} = 1 if $args{auto_pick};
1729              
1730 0           my $m = 'MIRRORED.BY';
1731 0           my $mby = File::Spec->catfile($CPAN::Config->{keep_source_where},$m);
1732 0           File::Path::mkpath(File::Basename::dirname($mby));
1733             # Why are we using MIRRORED.BY from the current directory?
1734             # Is this for testing? -- dagolden, 2009-11-05
1735 0 0 0       if (-f $mby && -f $m && -M $m < -M $mby) {
      0        
1736 0           require File::Copy;
1737 0 0         File::Copy::copy($m,$mby) or die "Could not update $mby: $!";
1738             }
1739 0           local $^T = time;
1740             # if we have a cached copy is not older than 60 days, we either
1741             # use it or refresh it or fall back to it if the refresh failed.
1742 0 0 0       if ($mby && -f $mby && -s _ > 0 ) {
      0        
1743 0           my $very_old = (-M $mby > 60);
1744 0           my $mtime = localtime((stat _)[9]);
1745             # if auto_pick, refresh anything old automatically
1746 0 0         if ( $args{auto_pick} ) {
1747 0 0         if ( $very_old ) {
1748 0           $CPAN::Frontend->myprint(qq{Trying to refresh your mirror list\n});
1749 0 0         eval { CPAN::FTP->localize($m,$mby,3,1) }
  0            
1750             or $CPAN::Frontend->myprint(qq{Refresh failed. Using the old cached copy instead.\n});
1751 0           $CPAN::Frontend->myprint("\n");
1752             }
1753             }
1754             else {
1755 0           my $prompt = qq{Found a cached mirror list as of $mtime
1756              
1757             If you'd like to just use the cached copy, answer 'yes', below.
1758             If you'd like an updated copy of the mirror list, answer 'no' and
1759             I'll get a fresh one from the Internet.
1760              
1761             Shall I use the cached mirror list?};
1762 0 0         my $ans = prompt($prompt, $very_old ? "no" : "yes");
1763 0 0         if ($ans =~ /^n/i) {
1764 0           $CPAN::Frontend->myprint(qq{Trying to refresh your mirror list\n});
1765             # you asked for it from the Internet
1766 0           $CPAN::Config->{connect_to_internet_ok} = 1;
1767 0 0         eval { CPAN::FTP->localize($m,$mby,3,1) }
  0            
1768             or $CPAN::Frontend->myprint(qq{Refresh failed. Using the old cached copy instead.\n});
1769 0           $CPAN::Frontend->myprint("\n");
1770             }
1771             }
1772             }
1773             # else there is no cached copy and we must fetch or fail
1774             else {
1775             # If they haven't agree to connect to the internet, ask again
1776 0 0         if ( ! $CPAN::Config->{connect_to_internet_ok} ) {
1777 0           my $prompt = q{You are missing a copy of the CPAN mirror list.
1778              
1779             May I connect to the Internet to get it?};
1780 0           my $ans = prompt($prompt, "yes");
1781 0 0         if ($ans =~ /^y/i) {
1782 0           $CPAN::Config->{connect_to_internet_ok} = 1;
1783             }
1784             }
1785              
1786             # Now get it from the Internet or complain
1787 0 0         if ( $CPAN::Config->{connect_to_internet_ok} ) {
1788 0           $CPAN::Frontend->myprint(qq{Trying to fetch a mirror list from the Internet\n});
1789 0 0         eval { CPAN::FTP->localize($m,$mby,3,1) }
  0            
1790             or $CPAN::Frontend->mywarn(<<'HERE');
1791             We failed to get a copy of the mirror list from the Internet.
1792             You will need to provide CPAN mirror URLs yourself.
1793             HERE
1794 0           $CPAN::Frontend->myprint("\n");
1795             }
1796             else {
1797 0           $CPAN::Frontend->mywarn(<<'HERE');
1798             You will need to provide CPAN mirror URLs yourself or set
1799             'o conf connect_to_internet_ok 1' and try again.
1800             HERE
1801             }
1802             }
1803              
1804             # if we finally have a good local MIRRORED.BY, get on with picking
1805 0 0 0       if (-f $mby && -s _ > 0){
1806             $CPAN::Config->{urllist} =
1807 0 0         $args{auto_pick} ? auto_mirrored_by($mby) : choose_mirrored_by($mby);
1808 0           return 1;
1809             }
1810              
1811 0           return;
1812             }
1813              
1814             sub find_exe {
1815 0     0 0   my($exe,$path) = @_;
1816 0   0       $path ||= [split /$Config{'path_sep'}/, $ENV{'PATH'}];
1817 0           my($dir);
1818             #warn "in find_exe exe[$exe] path[@$path]";
1819 0           for $dir (@$path) {
1820 0           my $abs = File::Spec->catfile($dir,$exe);
1821 0 0         if (($abs = MM->maybe_command($abs))) {
1822 0           return $abs;
1823             }
1824             }
1825             }
1826              
1827             sub picklist {
1828 0     0 0   my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
1829 0 0         CPAN->debug("picklist('$items','$prompt','$default','$require_nonempty',".
1830             "'$empty_warning')") if $CPAN::DEBUG;
1831 0   0       $default ||= '';
1832              
1833 0           my $pos = 0;
1834              
1835 0           my @nums;
1836 0           SELECTION: while (1) {
1837              
1838             # display, at most, 15 items at a time
1839 0           my $limit = $#{ $items } - $pos;
  0            
1840 0 0         $limit = 15 if $limit > 15;
1841              
1842             # show the next $limit items, get the new position
1843 0           $pos = display_some($items, $limit, $pos, $default);
1844 0 0         $pos = 0 if $pos >= @$items;
1845              
1846 0           my $num = prompt($prompt,$default);
1847              
1848 0           @nums = split (' ', $num);
1849             {
1850 0           my %seen;
  0            
1851 0           @nums = grep { !$seen{$_}++ } @nums;
  0            
1852             }
1853 0           my $i = scalar @$items;
1854 0           unrangify(\@nums);
1855 0 0 0       if (0 == @nums) {
    0          
1856             # cannot allow nothing because nothing means paging!
1857             # return;
1858             } elsif (grep (/\D/ || $_ < 1 || $_ > $i, @nums)) {
1859 0           $CPAN::Frontend->mywarn("invalid items entered, try again\n");
1860 0 0         if ("@nums" =~ /\D/) {
1861 0           $CPAN::Frontend->mywarn("(we are expecting only numbers between 1 and $i)\n");
1862             }
1863 0           next SELECTION;
1864             }
1865 0 0 0       if ($require_nonempty && !@nums) {
1866 0           $CPAN::Frontend->mywarn("$empty_warning\n");
1867             }
1868              
1869             # a blank line continues...
1870 0 0         unless (@nums){
1871 0           $CPAN::Frontend->mysleep(0.1); # prevent hot spinning process on the next bug
1872 0           next SELECTION;
1873             }
1874 0           last;
1875             }
1876 0           for (@nums) { $_-- }
  0            
1877 0           @{$items}[@nums];
  0            
1878             }
1879              
1880             sub unrangify ($) {
1881 0     0 0   my($nums) = $_[0];
1882 0           my @nums2 = ();
1883 0 0         while (@{$nums||[]}) {
  0            
1884 0           my $n = shift @$nums;
1885 0 0         if ($n =~ /^(\d+)-(\d+)$/) {
1886 0           my @range = $1 .. $2;
1887             # warn "range[@range]";
1888 0           push @nums2, @range;
1889             } else {
1890 0           push @nums2, $n;
1891             }
1892             }
1893 0           push @$nums, @nums2;
1894             }
1895              
1896             sub display_some {
1897 0     0 0   my ($items, $limit, $pos, $default) = @_;
1898 0   0       $pos ||= 0;
1899              
1900 0           my @displayable = @$items[$pos .. ($pos + $limit)];
1901 0           for my $item (@displayable) {
1902 0           $CPAN::Frontend->myprint(sprintf "(%d) %s\n", ++$pos, $item);
1903             }
1904 0 0         my $hit_what = $default ? "SPACE ENTER" : "ENTER";
1905 0 0         $CPAN::Frontend->myprint(sprintf("%d more items, hit %s to show them\n",
1906             (@$items - $pos),
1907             $hit_what,
1908             ))
1909             if $pos < @$items;
1910 0           return $pos;
1911             }
1912              
1913             sub auto_mirrored_by {
1914 0 0   0 0   my $local = shift or return;
1915 0           local $|=1;
1916 0           $CPAN::Frontend->myprint("Looking for CPAN mirrors near you (please be patient)\n");
1917 0           my $mirrors = CPAN::Mirrors->new($local);
1918              
1919 0           my $cnt = 0;
1920             my @best = $mirrors->best_mirrors(
1921             how_many => 3,
1922             callback => sub {
1923 0     0     $CPAN::Frontend->myprint(".");
1924 0 0         if ($cnt++>60) { $cnt=0; $CPAN::Frontend->myprint("\n"); }
  0            
  0            
1925             },
1926 0           );
1927              
1928 0           my $urllist = [ map { $_->http } @best ];
  0            
1929 0           push @$urllist, grep { /^file:/ } @{$CPAN::Config->{urllist}};
  0            
  0            
1930 0           $CPAN::Frontend->myprint(" done!\n\n");
1931              
1932 0           return $urllist
1933             }
1934              
1935             sub choose_mirrored_by {
1936 0 0   0 0   my $local = shift or return;
1937 0           my ($default);
1938 0           my $mirrors = CPAN::Mirrors->new($local);
1939 0           my @previous_urls = @{$CPAN::Config->{urllist}};
  0            
1940              
1941 0           $CPAN::Frontend->myprint($prompts{urls_picker_intro});
1942              
1943 0           my (@cont, $cont, %cont, @countries, @urls, %seen);
1944 0           my $no_previous_warn =
1945             "Sorry! since you don't have any existing picks, you must make a\n" .
1946             "geographic selection.";
1947 0           my $offer_cont = [sort $mirrors->continents];
1948 0 0         if (@previous_urls) {
1949 0           push @$offer_cont, "(edit previous picks)";
1950 0           $default = @$offer_cont;
1951             } else {
1952             # cannot allow nothing because nothing means paging!
1953             # push @$offer_cont, "(none of the above)";
1954             }
1955 0           @cont = picklist($offer_cont,
1956             "Select your continent (or several nearby continents)",
1957             $default,
1958             ! @previous_urls,
1959             $no_previous_warn);
1960             # cannot allow nothing because nothing means paging!
1961             # return unless @cont;
1962              
1963 0           foreach $cont (@cont) {
1964 0           my @c = sort $mirrors->countries($cont);
1965 0           @cont{@c} = map ($cont, 0..$#c);
1966 0 0         @c = map ("$_ ($cont)", @c) if @cont > 1;
1967 0           push (@countries, @c);
1968             }
1969 0 0 0       if (@previous_urls && @countries) {
1970 0           push @countries, "(edit previous picks)";
1971 0           $default = @countries;
1972             }
1973              
1974 0 0         if (@countries) {
1975 0           @countries = picklist (\@countries,
1976             "Select your country (or several nearby countries)",
1977             $default,
1978             ! @previous_urls,
1979             $no_previous_warn);
1980 0           %seen = map (($_ => 1), @previous_urls);
1981             # hmmm, should take list of defaults from CPAN::Config->{'urllist'}...
1982 0           foreach my $country (@countries) {
1983 0 0         next if $country =~ /edit previous picks/;
1984 0           (my $bare_country = $country) =~ s/ \(.*\)//;
1985 0           my @u;
1986 0           for my $m ( $mirrors->mirrors($bare_country) ) {
1987 0 0         push @u, $m->ftp if $m->ftp;
1988 0 0         push @u, $m->http if $m->http;
1989             }
1990 0           @u = grep (! $seen{$_}, @u);
1991 0 0         @u = map ("$_ ($bare_country)", @u)
1992             if @countries > 1;
1993 0           push (@urls, sort @u);
1994             }
1995             }
1996 0           push (@urls, map ("$_ (previous pick)", @previous_urls));
1997 0           my $prompt = "Select as many URLs as you like (by number),
1998             put them on one line, separated by blanks, hyphenated ranges allowed
1999             e.g. '1 4 5' or '7 1-4 8'";
2000 0 0         if (@previous_urls) {
2001 0           $default = join (' ', ((scalar @urls) - (scalar @previous_urls) + 1) ..
2002             (scalar @urls));
2003 0           $prompt .= "\n(or just hit ENTER to keep your previous picks)";
2004             }
2005              
2006 0           @urls = picklist (\@urls, $prompt, $default);
2007 0           foreach (@urls) { s/ \(.*\)//; }
  0            
2008 0           return [ @urls ];
2009             }
2010              
2011             sub bring_your_own {
2012 0     0 0   my $urllist = [ @{$CPAN::Config->{urllist}} ];
  0            
2013 0           my %seen = map (($_ => 1), @$urllist);
2014 0           my($ans,@urls);
2015 0           my $eacnt = 0; # empty answers
2016 0           $CPAN::Frontend->myprint(<<'HERE');
2017             Now you can enter your own CPAN URLs by hand. A local CPAN mirror can be
2018             listed using a 'file:' URL like 'file:///path/to/cpan/'
2019              
2020             HERE
2021 0   0       do {
2022 0           my $prompt = "Enter another URL or ENTER to quit:";
2023 0 0         unless (%seen) {
2024 0           $prompt = qq{CPAN.pm needs at least one URL where it can fetch CPAN files from.
2025              
2026             Please enter your CPAN site:};
2027             }
2028 0           $ans = prompt ($prompt, "");
2029              
2030 0 0         if ($ans) {
2031 0           $ans =~ s|/?\z|/|; # has to end with one slash
2032             # XXX This manipulation is odd. Shouldn't we check that $ans is
2033             # a directory before converting to file:///? And we need /// below,
2034             # too, don't we? -- dagolden, 2009-11-05
2035 0 0         $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file:
2036 0 0         if ($ans =~ /^\w+:\/./) {
2037 0 0         push @urls, $ans unless $seen{$ans}++;
2038             } else {
2039             $CPAN::Frontend->
2040             myprint(sprintf(qq{"%s" doesn\'t look like an URL at first sight.
2041             I\'ll ignore it for now.
2042             You can add it to your %s
2043             later if you\'re sure it\'s right.\n},
2044             $ans,
2045             $INC{'CPAN/MyConfig.pm'}
2046 0   0       || $INC{'CPAN/Config.pm'}
2047             || "configuration file",
2048             ));
2049             }
2050             } else {
2051 0 0         if (++$eacnt >= 5) {
2052 0           $CPAN::Frontend->
2053             mywarn("Giving up.\n");
2054 0           $CPAN::Frontend->mysleep(5);
2055 0           return;
2056             }
2057             }
2058             } while $ans || !%seen;
2059              
2060 0           @$urllist = CPAN::_uniq(@$urllist, @urls);
2061 0           $CPAN::Config->{urllist} = $urllist;
2062             }
2063              
2064             sub _print_urllist {
2065 0     0     my ($which) = @_;
2066 0           $CPAN::Frontend->myprint("$which urllist\n");
2067 0 0         for ( @{$CPAN::Config->{urllist} || []} ) {
  0            
2068 0           $CPAN::Frontend->myprint(" $_\n")
2069             };
2070             }
2071              
2072             sub _can_write_to_libdirs {
2073             return -w $Config{installprivlib}
2074             && -w $Config{installarchlib}
2075             && -w $Config{installsitelib}
2076             && -w $Config{installsitearch}
2077 0   0 0     }
2078              
2079             sub _using_installbase {
2080 0 0 0 0     return 1 if $ENV{PERL_MM_OPT} && $ENV{PERL_MM_OPT} =~ /install_base/i;
2081 0 0 0       return 1 if grep { ($CPAN::Config->{$_}||q{}) =~ /install_base/i }
  0            
2082             qw(makepl_arg make_install_arg mbuildpl_arg mbuild_install_arg);
2083 0           return;
2084             }
2085              
2086             sub _using_sudo {
2087 0 0 0 0     return 1 if grep { ($CPAN::Config->{$_}||q{}) =~ /sudo/ }
  0            
2088             qw(make_install_make_command mbuild_install_build_command);
2089 0           return;
2090             }
2091              
2092             sub _strip_spaces {
2093 0     0     $_[0] =~ s/^\s+//; # no leading spaces
2094 0           $_[0] =~ s/\s+\z//; # no trailing spaces
2095             }
2096              
2097             sub prompt ($;$) {
2098 0 0   0 0   unless (defined &_real_prompt) {
2099 0           *_real_prompt = \&CPAN::Shell::colorable_makemaker_prompt;
2100             }
2101 0           my $ans = _real_prompt(@_);
2102              
2103 0           _strip_spaces($ans);
2104 0 0         $CPAN::Frontend->myprint("\n") unless $auto_config;
2105              
2106 0           return $ans;
2107             }
2108              
2109              
2110             sub prompt_no_strip ($;$) {
2111 0 0   0 0   unless (defined &_real_prompt) {
2112 0           *_real_prompt = \&CPAN::Shell::colorable_makemaker_prompt;
2113             }
2114 0           return _real_prompt(@_);
2115             }
2116              
2117              
2118              
2119             1;