[Module-build-checkins] Module-Build/lib/Module/Build Base.pm,1.340.2.13,1.340.2.14
Status: Beta
Brought to you by:
kwilliams
From: Ken W. <kwi...@us...> - 2005-01-24 03:40:41
|
Update of /cvsroot/module-build/Module-Build/lib/Module/Build In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9327/lib/Module/Build Modified Files: Tag: release-0_26_branch Base.pm Log Message: Fix potential infinite loop in y_n() Index: Base.pm =================================================================== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v retrieving revision 1.340.2.13 retrieving revision 1.340.2.14 diff -u -d -r1.340.2.13 -r1.340.2.14 --- Base.pm 10 Jan 2005 03:04:36 -0000 1.340.2.13 +++ Base.pm 24 Jan 2005 03:40:30 -0000 1.340.2.14 @@ -200,12 +200,14 @@ sub base_dir { shift()->{properties}{base_dir} } sub installdirs { shift()->{properties}{installdirs} } +sub _is_interactive { + return -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe? +} + sub prompt { my $self = shift; my ($mess, $def) = @_; die "prompt() called without a prompt message" unless @_; - - my $INTERACTIVE = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe? ($def, my $dispdef) = defined $def ? ($def, "[$def] ") : ('', ' '); @@ -214,7 +216,7 @@ print "$mess $dispdef"; } my $ans; - if ($INTERACTIVE) { + if ($self->_is_interactive) { $ans = <STDIN>; if ( defined $ans ) { chomp $ans; @@ -234,12 +236,14 @@ sub y_n { my $self = shift; die "y_n() called without a prompt message" unless @_; - + + my $interactive = $self->_is_interactive; my $answer; while (1) { $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"; } } |