Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: geoff.crompton [...] strategicdata.com.au
Cc:
AdminCc:

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



Subject: -require checks ignore for -default value
Date: Wed, 06 Sep 2006 16:59:31 +1000
To: bug-IO-Prompt [...] rt.cpan.org
From: Geoff Crompton <geoff.crompton [...] strategicdata.com.au>
Hi, If you supply a -default value, the -require checks are bypassed. I'm using IO-Prompt-v0.99.2. For example, the following code accepts the default, even thougth the default doesn't meet the first require about lenght, and may not meet the second require if the user already exists. prompt('Enter clients user name: ', -default => 'geoff', -require => { # Require username to be at least 6 chars long 'Username to short, enter another one:' => sub { m{ .{6,} }x; }, # Require usename does not already exist 'Username already exists, enter another one:' => sub { !getpwnam($_); }, }, ); -- Geoff Crompton Debian System Administrator Strategic Data +61 3 9340 9000
Subject: Re: [rt.cpan.org #21345] AutoReply: -require checks ignore for -default value
Date: Tue, 12 Sep 2006 09:20:34 +1000
To: bug-IO-Prompt [...] rt.cpan.org
From: Geoff Crompton <geoff.crompton [...] strategicdata.com.au>
Show quoted text
> Hi, > > If you supply a -default value, the -require checks are bypassed. > > I'm using IO-Prompt-v0.99.2. For example, the following code accepts the > default, even thougth the default doesn't meet the first require about > lenght, and may not meet the second require if the user already exists. > > prompt('Enter clients user name: ', > -default => 'geoff', > -require => { > > # Require username to be at least 6 chars long > 'Username to short, enter another one:' => sub { m{ .{6,} > }x; }, > > # Require usename does not already exist > 'Username already exists, enter another one:' => sub { !getpwnam($_); }, > }, > ); >
After some discussion with Damien, and another developer at work, it seems my idea is a bit wonky. The general consensus is that doing this is a bit out of scope for IO::Prompt, and that it isn't real smart to feed an incorrect value in as a default. If you are generating a default value based on other sources, it will be cleaner code if you create it such that it can't be an invalid answer, or you sanity check it before calling prompt(). -- Geoff Crompton Debian System Administrator Strategic Data +61 3 9340 9000