NAME
VCP::UI::Text - A textual user interface for VCP.
SYNOPSIS
$ vcp ## VCP::UI::Text is the current default
DESCRIPTION
This is a text-only user interface for VCP. It prints out descriptions, prompts the user, reads the responses, and validates input.
This class is designed to be refactored and/or inherited from for alternative user interfaces, like GUIs.
METHODS
new_source
$ui->new_source( "vss", @_ );
Creates a new source if the current source is not of the indicated class.
Emits a warning when the source is changed from one type to another and clears in_edit_mode().
source_repo_id
Sets/gets the source id. This is needed because we prompt for the source name before knowing what type of source to create in case we can read the source settings from a file in the future.
source
Gets (does not set) the source.
dest
Gets (does not set) the dest.
dest_repo_id
Sets/gets the dest repo_id. This is needed because we prompt for the dest name before knowing what type of dest to create in case we can read the dest settings from a file in the future.
new_dest
$ui->new_dest( "vss", @_ );
Creates a new dest if the current dest is not of the indicated class.
Sets the repo_id to be dest_repo_id if necessary.
Emits a warning when the source is changed from one type to another and clears in_edit_mode().
in_edit_mode
Returns true if the machine is editing an existing set of settings.
ask
$text_ui->ask(
$is_error,
$description,
$always_verbose,
$name,
$prompt,
$default,
$answer_key
);
Prompts the user, giving them the possibly lengthy description, a blank line and a prompt. Reads a single line of input and returns it and a reference to the matching answer key.
The answer key looks like:
[
[ $suggested_answer_1, $validator_1, ... ],
[ $suggested_answer_2, $validator_2, ... ],
[ $suggested_answer_3, $validator_3, ... ],
...
]
The suggested answers are like "yes", "No", etc. Leave this as undef or "" to run a validator without an answer.
The validators are one of:
undef Entry is compared to the suggested answer, if defined
'foo' Answer must equal 'foo' (case sensitive)
qr// Answer must match the indicated regexp
sub {...}, \&foo The subroutine will validate.
If all validators are strings that are equal to the suggested answer, a multiple choice prompt/response is generated instead of free text entry.
Validation subroutines must return TRUE for valid input, FALSE for invalid input but without a message, or die "...\n" with an error message for the user if the input is not valid. If no validators pass, an error message will be printed and the user will be reprompted. If multiple code reference validators fail with different error messages, then these will all be printed.
The answer to be validated is placed in $_ when calling a code ref.
input
my $line = $text_ui->input;
Gets the user's input with or without surrounding whitespace and newline.
output
$text_ui->output(
$terseness,
$description,
$choices,
$default,
$is_current_value,
$prompt,
);
Outputs the parameters to the user; defaults to print()ing it with stdout buffering off.
$description will be undef after the first call until ask() decides that the user needs to see it again.
emit_hrule
Prints a separator line. Used between prompts and at exit.
emit_blank_line
Prints a blank line. Used at exit.
emit_error
Prints a message. Defaults to warn()ing.
emit_note
Prints a message. Defaults to warn()ing.
build_prompt
$text_ui->build_prompt( $prompt, \@suggested_answers );
Assembed $prompt and possibly the strings in \@suggested_answers in to a single string fit for a user.
validate
$text_ui->validate( $answer, $answer_key, $is_multiple_choice );
Returns a two element list ( $answer, $matching_answer_key_entry ) or dies with an error message. If $is_multiple_choice, then the answer will be matched case-insensitively for literal string validators.
COPYRIGHT
Copyright 2000, Perforce Software, Inc. All Rights Reserved.
This module and the VCP::UI::Text package are licensed according to the terms given in the file LICENSE accompanying this distribution, a copy of which is included in vcp.
AUTHOR
Barrie Slaymaker <barries@slaysys.com>
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 21:
You can't have =items (as at line 50) unless the first thing after the =over is an =item