Net-CLI-Interact
view release on metacpan or search on metacpan
lib/Net/CLI/Interact/Role/Engine.pm view on Meta::CPAN
});
$set->register_callback(sub { $self->transport->do_action(@_) });
$self->logger->log('engine', 'debug', 'dispatching to execute method');
my $timeout_bak = $self->transport->timeout;
$self->transport->timeout($options->timeout || $timeout_bak);
$set->execute;
$self->transport->timeout($timeout_bak);
$self->last_actionset($set);
$self->logger->log('prompt', 'debug',
sprintf 'setting new prompt to %s',
$self->last_actionset->last->prompt_hit || '<none>');
$self->_prompt( $self->last_actionset->last->prompt_hit );
$self->logger->log('dialogue', 'info',
"trimmed command response:\n". $self->last_response);
return $self->last_response; # context sensitive
}
1;
=pod
=for Pod::Coverage has_default_continuation set_default_continuation
=head1 NAME
Net::CLI::Interact::Role::Engine - Statement execution engine
=head1 DESCRIPTION
This module is the core of L<Net::CLI::Interact>, and serves to take entries
from your loaded L<Phrasebooks|Net::CLI::Interact::Phrasebook>, issue them to
connected devices, and gather the returned output.
=head1 INTERFACE
=head2 cmd( $command_statement, \%options? )
Execute a single command statement on the connected device, and consume output
until there is a match with the current I<prompt>. The statement is executed
verbatim on the device, with a newline appended.
The following options are supported:
=over 4
=item C<< timeout => $seconds >> (optional)
Sets a value of C<timeout> for the
Transport local to this call of C<cmd>, that
overrides whatever is set in the Transport, or the default of 10 seconds.
=item C<< no_ors => 1 >> (optional)
When passed a true value, a newline character (in fact the value of C<ors>)
will not be appended to the statement sent to the device.
=item C<< match => $name | $regexpref | \@names_and_regexprefs >> (optional)
Allows this command (only) to complete with a custom match, which must be one
or more of either the name of a loaded phrasebook Prompt or your own regular
expression reference (C<< qr// >>). The module updates the current prompt to
be the same value on a successful match.
=back
In scalar context the C<last_response> is returned (see below). In list
context the gathered response is returned as a list of lines. In both cases
your local platform's newline character will end all lines.
=head2 macro( $macro_name, \%options? )
Execute the commands contained within the named Macro, which must be loaded
from a Phrasebook. Options to control the output, including variables for
substitution into the Macro, are passed in the C<%options> hash reference.
The following options are supported:
=over 4
=item C<< params => \@values >> (optional)
If the Macro contains commands using C<sprintf> Format variables then the
corresponding parameters must be passed in this value as an array reference.
Values are consumed from the provided array reference and passed to the
C<send> commands in the Macro in order, as needed. An exception will be thrown
if there are insufficient parameters.
=item C<< timeout => $seconds >> (optional)
Sets a value of C<timeout> for the
Transport local to this call of C<macro>,
that overrides whatever is set in the Transport, or the default of 10 seconds.
=back
An exception will be thrown if the Match statements in the Macro are not
successful against the output returned from the device. This is based on the
value of C<timeout>, which controls how long the module waits for matching
output.
In scalar context the C<last_response> is returned (see below). In list
context the gathered response is returned as a list of lines. In both cases
your local platform's newline character will end all lines.
=head2 last_response
Returns the gathered output after issuing the last recent C<send> command
within the most recent C<cmd> or C<prompt>. That is, you get the output from
the last command sent to the connected device.
In scalar context all data is returned. In list context the gathered response
is returned as a list of lines. In both cases your local platform's newline
character will end all lines.
=head2 last_actionset
( run in 2.809 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )