Re: [Module::Build] ask() and you will receive
Status: Beta
Brought to you by:
kwilliams
From: Randy W. S. <ml...@th...> - 2006-04-11 09:24:19
|
Randy W. Sims wrote: > Ken Williams wrote: > >> I think this is a decent direction. I only have a couple of >> concerns: one, I do think that the default needs to be one of the >> options in an option list, or else people are just going to make too >> many mistakes. > > > I debated that decision for a while. The reason I allowed it was that > when running an unattended build, none of the choices may be a > reasonable default. In that case the default can be set to an empty > string or something that make sense to indicate that no choice was made. > > Note also that 'default' may be set to an empty string or to any value, > including undef as long as something is passed in. > > One alternative I can think of: > > $answer = Prompter->ask( > prompt => "What is your favorite programming language?\n", > options => [qw(Perl Ruby Lua Python C C++ /unknown/)], > default => 'unknown', > ); > > Another element is added to 'options' enclosed between slashes (or > something). Such elements would not be show when options are displayed. > Then default can be set to the "invisible" option. The only bad thing is open ended questions get a little more verbose. Instead of: $answer = Prompter->ask( prompt => "What is your user name?\n", default => 'guest', ); You would have to say: $answer = Prompter->ask( prompt => "What is your user name?\n", options => ['/guest/'], default => 'guest', ); Another options would be to require the user to flag the default if it is not in the options list. In effect, the user must declare she knows the string entered is not in the options and that she knows exactly what she's doing. $answer = Prompter->ask( prompt => "What is your user name?\n", default => '!guest', ); (The first character of the default string is an exclamation mark.) Opinions? Randy. |