📄 firsttime.pm
字号:
# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-package CPAN::Mirrored::By;sub new { my($self,@arg) = @_; bless [@arg], $self;}sub continent { shift->[0] }sub country { shift->[1] }sub url { shift->[2] }package CPAN::FirstTime;use strict;use ExtUtils::MakeMaker qw(prompt);use FileHandle ();use File::Basename ();use File::Path ();use vars qw($VERSION);$VERSION = substr q$Revision: 1.53 $, 10;=head1 NAMECPAN::FirstTime - Utility for CPAN::Config file Initialization=head1 SYNOPSISCPAN::FirstTime::init()=head1 DESCRIPTIONThe init routine asks a few questions and writes a CPAN::Configfile. Nothing special.=cutsub init { my($configpm) = @_; use Config; unless ($CPAN::VERSION) { require CPAN::Nox; } eval {require CPAN::Config;}; $CPAN::Config ||= {}; local($/) = "\n"; local($\) = ""; local($|) = 1; my($ans,$default,$local,$cont,$url,$expected_size); # # Files, directories # print qq[CPAN is the world-wide archive of perl resources. It consists of about100 sites that all replicate the same contents all around the globe.Many countries have at least one CPAN site already. The resourcesfound on CPAN are easily accessible with the CPAN.pm module. If youwant to use CPAN.pm, you have to configure it properly.If you do not want to enter a dialog now, you can answer 'no' to thisquestion and I\'ll try to autoconfigure. (Note: you can revisit thisdialog anytime later by typing 'o conf init' at the cpan prompt.)]; my $manual_conf = ExtUtils::MakeMaker::prompt("Are you ready for manual configuration?", "yes"); my $fastread; { local $^W; if ($manual_conf =~ /^\s*y/i) { $fastread = 0; *prompt = \&ExtUtils::MakeMaker::prompt; } else { $fastread = 1; $CPAN::Config->{urllist} ||= []; # prototype should match that of &MakeMaker::prompt *prompt = sub ($;$) { my($q,$a) = @_; my($ret) = defined $a ? $a : ""; printf qq{%s [%s]\n\n}, $q, $ret; $ret; }; } } print qq{The following questions are intended to help you with theconfiguration. The CPAN module needs a directory of its own to cacheimportant index files and maybe keep a temporary mirror of CPAN files.This may be a site-wide directory or a personal directory.}; my $cpan_home = $CPAN::Config->{cpan_home} || MM->catdir($ENV{HOME}, ".cpan"); if (-d $cpan_home) { print qq{I see you already have a directory $cpan_homeShall we use it as the general CPAN build and cache directory?}; } else { print qq{First of all, I\'d like to create this directory. Where?}; } $default = $cpan_home; while ($ans = prompt("CPAN build and cache directory?",$default)) { eval { File::Path::mkpath($ans); }; # dies if it can't if ($@) { warn "Couldn't create directory $ans.Please retry.\n"; next; } if (-d $ans && -w _) { last; } else { warn "Couldn't find directory $ans or directory is not writable. Please retry.\n"; } } $CPAN::Config->{cpan_home} = $ans; print qq{If you want, I can keep the source files after a build in the cpanhome directory. If you choose so then future builds will take thefiles from there. If you don\'t want to keep them, answer 0 to thenext question.}; $CPAN::Config->{keep_source_where} = MM->catdir($CPAN::Config->{cpan_home},"sources"); $CPAN::Config->{build_dir} = MM->catdir($CPAN::Config->{cpan_home},"build"); # # Cache size, Index expire # print qq{How big should the disk cache be for keeping the build directorieswith all the intermediate files\?}; $default = $CPAN::Config->{build_cache} || 10; $ans = prompt("Cache size for build directory (in MB)?", $default); $CPAN::Config->{build_cache} = $ans; # XXX This the time when we refetch the index files (in days) $CPAN::Config->{'index_expire'} = 1; print qq{By default, each time the CPAN module is started, cache scanningis performed to keep the cache size in sync. To prevent from this,disable the cache scanning with 'never'.}; $default = $CPAN::Config->{scan_cache} || 'atstart'; do { $ans = prompt("Perform cache scanning (atstart or never)?", $default); } while ($ans ne 'atstart' && $ans ne 'never'); $CPAN::Config->{scan_cache} = $ans; # # cache_metadata # print qq{To considerably speed up the initial CPAN shell startup, it ispossible to use Storable to create a cache of metadata. If Storableis not available, the normal index mechanism will be used.}; defined($default = $CPAN::Config->{cache_metadata}) or $default = 1; do { $ans = prompt("Cache metadata (yes/no)?", ($default ? 'yes' : 'no')); } while ($ans !~ /^\s*[yn]/i); $CPAN::Config->{cache_metadata} = ($ans =~ /^\s*y/i ? 1 : 0); # # term_is_latin # print qq{The next option deals with the charset your terminal supports. Ingeneral CPAN is English speaking territory, thus the charset does notmatter much, but some of the aliens out there who upload theirsoftware to CPAN bear names that are outside the ASCII range. If yourterminal supports UTF-8, you say no to the next question, if itsupports ISO-8859-1 (also known as LATIN1) then you say yes, and if itsupports neither nor, your answer does not matter, you will not beable to read the names of some authors anyway. If you answer no, nameswill be output in UTF-8.}; defined($default = $CPAN::Config->{term_is_latin}) or $default = 1; do { $ans = prompt("Your terminal expects ISO-8859-1 (yes/no)?", ($default ? 'yes' : 'no')); } while ($ans !~ /^\s*[yn]/i); $CPAN::Config->{term_is_latin} = ($ans =~ /^\s*y/i ? 1 : 0); # # prerequisites_policy # Do we follow PREREQ_PM? # print qq{The CPAN module can detect when a module that which you are trying tobuild depends on prerequisites. If this happens, it can build theprerequisites for you automatically ('follow'), ask you forconfirmation ('ask'), or just ignore them ('ignore'). Please set yourpolicy to one of the three values.}; $default = $CPAN::Config->{prerequisites_policy} || 'ask'; do { $ans = prompt("Policy on building prerequisites (follow, ask or ignore)?", $default); } while ($ans ne 'follow' && $ans ne 'ask' && $ans ne 'ignore'); $CPAN::Config->{prerequisites_policy} = $ans; # # External programs # print qq{The CPAN module will need a few external programs to work properly.Please correct me, if I guess the wrong path for a program. Don\'tpanic if you do not have some of them, just press ENTER for those. Todisable the use of a download program, you can type a space followedby ENTER.}; my $old_warn = $^W; local $^W if $^O eq 'MacOS'; my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'}; local $^W = $old_warn; my $progname; for $progname (qw/gzip tar unzip make lynx wget ncftpget ncftp ftp/){ if ($^O eq 'MacOS') { $CPAN::Config->{$progname} = 'not_here'; next; } my $progcall = $progname; # we don't need ncftp if we have ncftpget next if $progname eq "ncftp" && $CPAN::Config->{ncftpget} gt " "; my $path = $CPAN::Config->{$progname} || $Config::Config{$progname} || ""; if (MM->file_name_is_absolute($path)) { # testing existence is not good enough, some have these exe # extensions # warn "Warning: configured $path does not exist\n" unless -e $path; # $path = ""; } else { $path = ''; } unless ($path) { # e.g. make -> nmake $progcall = $Config::Config{$progname} if $Config::Config{$progname}; } $path ||= find_exe($progcall,[@path]); warn "Warning: $progcall not found in PATH\n" unless $path; # not -e $path, because find_exe already checked that $ans = prompt("Where is your $progname program?",$path) || $path; $CPAN::Config->{$progname} = $ans; } my $path = $CPAN::Config->{'pager'} || $ENV{PAGER} || find_exe("less",[@path]) || find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 ) || "more"; $ans = prompt("What is your favorite pager program?",$path); $CPAN::Config->{'pager'} = $ans; $path = $CPAN::Config->{'shell'}; if (MM->file_name_is_absolute($path)) { warn "Warning: configured $path does not exist\n" unless -e $path; $path = ""; } $path ||= $ENV{SHELL}; if ($^O eq 'MacOS') { $CPAN::Config->{'shell'} = 'not_here'; } else { $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only $ans = prompt("What is your favorite shell?",$path); $CPAN::Config->{'shell'} = $ans; } # # Arguments to make etc. # print qq{Every Makefile.PL is run by perl in a separate process. Likewise werun \'make\' and \'make install\' in processes. If you have anyparameters \(e.g. PREFIX, LIB, UNINST or the like\) you want to passto the calls, please specify them here.If you don\'t understand this question, just press ENTER.}; $default = $CPAN::Config->{makepl_arg} || ""; $CPAN::Config->{makepl_arg} = prompt("Parameters for the 'perl Makefile.PL' command?Typical frequently used settings: POLLUTE=1 increasing backwards compatibility LIB=~/perl non-root users (please see manual for more hints)Your choice: ",$default); $default = $CPAN::Config->{make_arg} || ""; $CPAN::Config->{make_arg} = prompt("Parameters for the 'make' command?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -