NAME

Command::Interactive::Interaction - Models a result that may occur during an interactive command invoked by Command::Interactive.

SYNOPSIS

This module is used to describe a single expected result (a string or a regex) that can appear in the output of a system command invoked by Command::Interactive. Optionally this class can model the string to be sent in response to the expected string (e.g., a password in response to a password prompt).

use Command::Interactive::Interaction;
my $password_prompt = Command::Interactive->new({
    expected_string => 'password:',
    response        => 'secret',
});

my $result = Command::Interactive->new({
    interactions => [ $password_prompt ],
})-run('ssh user@somehost');

FIELDS

expected_string (REQUIRED)

The string (or regular expression) that Command::Interactive should look for in the output of the invoked command. To specify a regular expression, also set is_regex to a true value.

response

Optionally, a response that can be sent after the expected_string is found in the command output. This string will include a newline if send_newline_with_response is true.

expected_string_is_regex (DEFAULT: FALSE)

Whether the expected_string should be treated as a Perl regular expression.

send_newline_with_response (DEFAULT: TRUE)

Whether to send a newline at the end of the response string when expected_string is discovered.

is_error (DEFAULT: FALSE)

Whether expected_string should be considered the indication of an error. If is_error is set to true and Command::Interactive encounters <expected_string>, processing of the invoked command will cease and Command::Interactive will return an error result indicating the discovered value of <expected_string> that was understood to indicate an error.

is_required (DEFAULT: FALSE)

Whether the expected_string must be seen prior to the termination of the command invoked by Command::Interactive. If this field is set to true and expected_string is not encountered prior to the end of the command output, Command::Interactive will return an error result indicating that the command was not successful due to the fact that expected_string was not found.

max_allowed_occurrences (DEFAULT: 1)

The number of times that expected_string can be found before Command::Interactive returns an error. This field exists to prevent infinite loops in which (e.g.) a password is requested over and over. To disable this checking altogether, set max_allowed_occurrences to 0. You may also set it to a higher value if you actually expect the same string to appear more than once.

METHODS

actual_response_to_send

Returns the actual string to send in response to discovering expected_string, including any newlines that might be added to the end of the string.

type

Returns 'string' or 'regex' based on is_regex. Useful in routines internal to Command::Interactive ewhich create human-readable explanations of failure conditions.

AUTHOR

Binary.com, <perl@binary.com>

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.