From: Michael G Schwern Date: Tue, 12 Jul 2005 00:00:17 +0000 (-0700) Subject: [perl #24691] leading spaces on cpan configuration causes failure X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f915a99a5a679d0552c03775d6fc6c62ff92454f;p=p5sagit%2Fp5-mst-13.2.git [perl #24691] leading spaces on cpan configuration causes failure From: "Michael G Schwern via RT" Message-ID: (with spaces trimmed from username too) p4raw-id: //depot/perl@25147 --- diff --git a/lib/CPAN/FirstTime.pm b/lib/CPAN/FirstTime.pm index 30a6c45..5f9107f 100644 --- a/lib/CPAN/FirstTime.pm +++ b/lib/CPAN/FirstTime.pm @@ -12,7 +12,7 @@ sub url { shift->[2] } package CPAN::FirstTime; use strict; -use ExtUtils::MakeMaker qw(prompt); +use ExtUtils::MakeMaker (); use FileHandle (); use File::Basename (); use File::Path (); @@ -68,23 +68,22 @@ dialog 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 $manual_conf = prompt("Are you ready for manual configuration?", "yes"); my $fastread; { - local $^W; - if ($manual_conf =~ /^\s*y/i) { + if ($manual_conf =~ /^y/i) { $fastread = 0; - *prompt = \&ExtUtils::MakeMaker::prompt; } else { $fastread = 1; $CPAN::Config->{urllist} ||= []; + + local $^W = 0; # prototype should match that of &MakeMaker::prompt - *prompt = sub ($;$) { + *_real_prompt = sub ($;$) { my($q,$a) = @_; my($ret) = defined $a ? $a : ""; printf qq{%s [%s]\n\n}, $q, $ret; + $ret; }; } @@ -198,8 +197,8 @@ is 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); + } while ($ans !~ /^[yn]/i); + $CPAN::Config->{cache_metadata} = ($ans =~ /^y/i ? 1 : 0); # # term_is_latin @@ -222,8 +221,8 @@ will be output in UTF-8. 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); + } while ($ans !~ /^[yn]/i); + $CPAN::Config->{term_is_latin} = ($ans =~ /^y/i ? 1 : 0); # # save history in file histfile @@ -241,8 +240,6 @@ set this variable, please hit SPACE RETURN to the following question. defined($default = $CPAN::Config->{histfile}) or $default = File::Spec->catfile($CPAN::Config->{cpan_home},"histfile"); $ans = prompt("File to save your history?", $default); - $ans =~ s/^\s+//; - $ans =~ s/\s+\z//; $CPAN::Config->{histfile} = $ans; if ($CPAN::Config->{histfile}) { @@ -448,7 +445,7 @@ be echoed to the terminal! }; } - $CPAN::Config->{proxy_pass} = prompt("Your proxy password?"); + $CPAN::Config->{proxy_pass} = prompt_no_strip("Your proxy password?"); if ($CPAN::META->has_inst("Term::ReadKey")) { Term::ReadKey::ReadMode("restore"); } @@ -692,8 +689,6 @@ Please enter your CPAN site:}; $ans = prompt ($prompt, ""); if ($ans) { - $ans =~ s/^\s+//; # no leading spaces - $ans =~ s/\s+\z//; # no trailing spaces $ans =~ s|/?\z|/|; # has to end with one slash $ans = "file:$ans" unless $ans =~ /:/; # without a scheme is a file: if ($ans =~ /^\w+:\/./) { @@ -716,4 +711,28 @@ later if you\'re sure it\'s right.\n}, map { print " $_\n" } @{$CPAN::Config->{urllist}}; } + +sub _strip_spaces { + $_[0] =~ s/^\s+//; # no leading spaces + $_[0] =~ s/\s+\z//; # no trailing spaces +} + + +sub prompt ($;$) { + my $ans = _real_prompt(@_); + + _strip_spaces($ans); + + return $ans; +} + + +sub prompt_no_strip ($;$) { + return _real_prompt(@_); +} + + +*_real_prompt = \*ExtUtils::MakeMaker::prompt; + + 1;