Re: [Module::Build] ask() and you will receive
Status: Beta
Brought to you by:
kwilliams
From: David W. <da...@ki...> - 2006-04-10 05:02:29
|
On Apr 8, 2006, at 03:32, Randy W. Sims wrote: > my $answer; > $answer = Prompter->ask( > prompt => "What is your favorite programming language?\n", > options => [qw(Perl Ruby Lua Python C C++)], > default => 'unknown', > show_options => 1, > show_default => 0, > ); > > print "Answer: $answer\n"; This actually looks similar to a method I wrote in my subclass. I think that you might find my "environ" and "callback" options useful additions: =head3 get_reply my $value = $build->get_reply(%params); Prompts the user with a message, and then collects a value from the user (if there is a TTY). A number of options can be specified, and the method will display a numbered list from which the user to select a value. Callbacks can also be specified to ensure the quality of a value. The supported parameters are: =over =item message A message with which to prompt the user, such as "What is your favorite color?". =item name The name of the Kinetic::Build::Base property or argument stored in the Module::Build C<args()> for which a value is sought. Optional. If the value was specified on the command-line, the user will not be prompted for a value. =item label A label for the value you're attempting to collect, such as "Favorite color". =item default A default value. This will be used if the user accepts the value (by hitting) enter or control-D), and will be returned without prompting the user if the C<accept_defaults> property is set to a true value or if there is no TTY. =item options An array reference of possible values from which the user can select. =item callback A code reference that validates a value input by a user. The value to be checked will be passed in as the first argument and will also be stored in C<$_>. For example, if you wanted to ensure that a value was an integer, you might pass a code reference like C<sub { /^\d+$/ } >. Note that if the callback sets C<$_> to a different value, the revised value is the one that will be returned. This can be useful for parsing one value from another. =item config_keys An array reference with two values that will be used to look up the value in the configuration file specified by the C<path_to_config> property. If no config file has been specified, these values will not be used. Otherwise, if no value was found in the Module::Build runtime parameters or arguments, the configuration file will be consulted. The first item in the array should be the name of the config file label, and the second item should be the key for the value for that label. For example, if you wanted to get at the store class, it might appear in the config file like so: [store] class: Kinetic::Store::DB::Pg To retrieve that value, set the array reference to ['store', 'class']. =item environ The name of an environment variable to check for a value. Checked only after the Module::Build runtime parameters and arguments and the configuration file have failed to return a value, but before prompting the user. Best, David |