Update of /cvsroot/module-build/Module-Build/lib/Module/Build
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32324/lib/Module/Build
Modified Files:
Authoring.pod Base.pm
Log Message:
Improve the behavior of prompt() and y_n() when there's no user
Index: Base.pm
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v
retrieving revision 1.541
retrieving revision 1.542
diff -u -d -r1.541 -r1.542
--- Base.pm 20 Jan 2006 14:29:14 -0000 1.541
+++ Base.pm 22 Jan 2006 02:30:44 -0000 1.542
@@ -358,7 +358,8 @@
print "$mess $dispdef";
}
my $ans;
- if ($self->_is_interactive) {
+ if ( ! $ENV{PERL_MM_USE_DEFAULT} &&
+ ( $self->_is_interactive || ! eof STDIN ) ) {
$ans = <STDIN>;
if ( defined $ans ) {
chomp $ans;
@@ -378,6 +379,7 @@
sub y_n {
my $self = shift;
die "y_n() called without a prompt message" unless @_;
+ die "y_n() called without y or n default" unless ($_[1]||"")=~/^[yn]/i;
my $interactive = $self->_is_interactive;
my $answer;
@@ -385,7 +387,6 @@
$answer = $self->prompt(@_);
return 1 if $answer =~ /^y/i;
return 0 if $answer =~ /^n/i;
- die "No y/n answer given, no default supplied, and no user to ask again" unless $interactive;
print "Please answer 'y' or 'n'.\n";
}
}
Index: Authoring.pod
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Authoring.pod,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- Authoring.pod 4 Dec 2005 03:48:06 -0000 1.28
+++ Authoring.pod 22 Jan 2006 02:30:44 -0000 1.29
@@ -1229,10 +1229,12 @@
which is optional, specifies a default answer (for example,
C<"wallet">). The user will be asked the question once.
-If the current session doesn't seem to be interactive (i.e. if
-C<STDIN> and C<STDOUT> look like they're attached to files or
-something, not terminals), we'll just use the default without
-letting the user provide an answer.
+If C<prompt()> detects that it is not running interactively and there
+is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable
+is set to true, the $default will be used without prompting. This
+prevents automated processes from blocking on user input.
+
+If no $default is provided an empty string will be used instead.
This method may be called as a class or object method.
|