| Store | Cart

ActiveState Docs

ActivePerl 5.10 Documentation

Loading...

ActiveState::Prompt - Interactive questions


NAME

ActiveState::Prompt - Interactive questions


SYNOPSIS

 use ActiveState::prompt qw(prompt yes enter);


DESCRIPTION

The following functions are provided:

prompt( $question )
prompt( $question, $default )
prompt( $question, %opts )

This function will ask a question on the terminal and return the answer given. The return value will always be defined.

Options can be passed in as key/value pairs. The following options are recognized:

  default
  trim_space
  must_match
  no_match_msg
  use_default
  silent

The default is returned if the user simply press return. The default value is shown in brackets. If no default is provided then no brackets are added to the question.

If trim_space is TRUE, then any leading and trailing space in the anwer is trimmed off and any internal space is collapsed to a single space.

The must_match value is used to validate answers. It can be either a function, array or regular expression. If it is a function, then the function is called with the answer given and should return TRUE if it is to be accepted. If it is an array, then the answer must be one of the values in the array. If it is an regular expression then it must match it.

The no_match_msg is printed if the given answer does not validate as specified in must_match.

If use_default is TRUE, then no answer is read from the terminal and the default is returned (or "" if there is no default). The use_default is by default TRUE if the program is not running on a terminal or if the PERL_MM_USE_DEFAULT environment variable is TRUE.

The silent option works like use_default but it also prevent the prompt text from being printed. This forces prompt() to return the default without actually prompting.

yes( $question )
yes( $question, $default )

Will use the prompt function to ask a question and then return a TRUE value if the answer was "yes" or "y".

The $default can either be a string like "yes", "y", "no" or "n", or a boolean value in which case "yes" will be the default if TRUE and "no" otherwise. If no $default is given it defaults to "no".

enter()

Ask the use to press some key before the function returns.


BUGS

None.