Skip Menu |

This queue is for tickets about the IO-Prompt CPAN distribution.

Report information
The Basics
Id: 15290
Status: new
Priority: 0/
Queue: IO-Prompt

People
Owner: Nobody in particular
Requestors: japh [...] tirwhan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.99.2
Fixed in: (no value)



Subject: -wipe flag has no effect (patch included)
Hi Damian, specifying the -wipe flag does not have any effect, the -w flag without an argument results in an error message "Missing argument for -w option at -e line 1". I've attached three patches against 0.99.2 (to be applied on top of each other, I wasn't sure whether you'd consider all of them appropriate), patch 1 enables the long form -wipe, patch 2 enables -w as wipe if no further arguments are given (if an argument is given, it is parsed as -while, as per the docs). Patch 3 adds some more DWIMery and also enables correct cuddling of argument-requiring flags (e.g. 'prompt -ei,"*"' now does the correct thing instead of ignoring the -i option).
Patch 1: Index: lib/IO/Prompt.pm =================================================================== --- lib/IO/Prompt.pm (Revision 1) +++ lib/IO/Prompt.pm (Revision 2) @@ -63,6 +63,7 @@ $flags_noarg{$_} = $_ for values %flags_noarg; my $flag_with_arg = join '|', reverse sort keys %flags_arg; +$flag_with_arg =~ s{\|w\|}{\|w(?!ipe)\|}; my $flag_no_arg = join '|', reverse sort keys %flags_noarg; my %yespat = ( @@ -187,7 +188,7 @@ $flags{-set_underscore} ||= want('BOOL'); $clearfirst = 1 if !defined($clearfirst) && $flags{-clearfirst}; - _clear($flags{ -clear } || $clearfirst); + _clear($flags{ -wipe } || $clearfirst); my $input; if (-t $IN and defined $input{$caller}) { $input = _fake_from_DATA($caller, $IN, $OUT, \%flags, @prompt); Patch 2: Index: lib/IO/Prompt.pm =================================================================== --- lib/IO/Prompt.pm (Revision 2) +++ lib/IO/Prompt.pm (Revision 3) @@ -117,10 +117,18 @@ $flags->{-yesno}{noprompt} = substr $1, 0, 1; } elsif (m/^-($flag_with_arg)/) { - croak "Missing argument for $_ option" if @data < $i+2; - s/^-($flag_with_arg)/-/; - $flags->{ -$flags_arg{$1} } = $data[ $i + 1 ]; - undef $data[ $i++ ]; + if (@data < $i+2) { + if (s/^-(w)/-/) { + $flags->{ -$flags_noarg{$1} } = 1; + } + else { + croak "Missing argument for $_ option"; + } + } else { + s/^-($flag_with_arg)/-/; + $flags->{ -$flags_arg{$1} } = $data[ $i + 1 ]; + undef $data[ $i++ ]; + } } elsif (s/^-($flag_no_arg)/-/) { $flags->{ -$flags_noarg{$1} } = 1; Patch 3: Index: lib/IO/Prompt.pm =================================================================== --- lib/IO/Prompt.pm (Revision 3) +++ lib/IO/Prompt.pm (Revision 4) @@ -116,25 +116,20 @@ $flags->{-yesno}{no} = $nopat{ substr $1, 0, 1 }; $flags->{-yesno}{noprompt} = substr $1, 0, 1; } - elsif (m/^-($flag_with_arg)/) { - if (@data < $i+2) { - if (s/^-(w)/-/) { - $flags->{ -$flags_noarg{$1} } = 1; - } - else { - croak "Missing argument for $_ option"; - } - } else { - s/^-($flag_with_arg)/-/; - $flags->{ -$flags_arg{$1} } = $data[ $i + 1 ]; - undef $data[ $i++ ]; - } + elsif (!m/^-($flag_with_arg)/ && !m/^-($flag_no_arg)/) { + croak "Unknown flag ($_) in prompt" } - elsif (s/^-($flag_no_arg)/-/) { + elsif ((@data < $i+2) && !m/^-($flag_no_arg)/) { + croak "Missing argument for $_ option"; + } + elsif ((@data >= $i+2) && s/^-($flag_with_arg)/-/) { + $flags->{ -$flags_arg{$1} } = $data[ $i + 1 ]; + splice(@data,$i+1,1); + } + else { + s/^-($flag_no_arg)/-/; $flags->{ -$flags_noarg{$1} } = 1; } - else { croak "Unknown flag ($_) in prompt" } - redo if defined $_ && /^-./; } else { next }
Date: Sat, 05 Nov 2005 12:28:44 -0800
To: bug-IO-Prompt [...] rt.cpan.org
Subject: Re: [cpan #15290] -wipe flag has no effect (patch included)
From: Damian Conway <thoughtstream [...] gmail.com>
RT-Send-Cc:
Show quoted text
> specifying the -wipe flag does not have any effect, the -w flag > without an argument results in an error message "Missing argument for > -w option at -e line 1". > > I've attached three patches against 0.99.2 (to be applied on top of > each other, I wasn't sure whether you'd consider all of them > appropriate), patch 1 enables the long form -wipe, patch 2 enables -w > as wipe if no further arguments are given (if an argument is given, it > is parsed as -while, as per the docs). Patch 3 adds some more DWIMery > and also enables correct cuddling of argument-requiring flags (e.g. > 'prompt -ei,"*"' now does the correct thing instead of ignoring the -i > option).
It was actually a mistake to have -wipe and -wipefirst options. They were supposed to be -clear and -clearfirst (and the actual implementation expected them to be). I've now corrected the docs and the code, so that you get: -w -while <cond> Return true while condition holds -c -clear Clear screen before prompt -f -clearfirst Clear screen before first prompt Thanks for the bug reports and especially for the associated patches. All the best, Damian