NAME
Net::CLI::Interact::Transport - Wrapper for IPC::Run for a CLI
VERSION
version 1.111150
DESCRIPTION
This module provides a wrapped interface to IPC::Run for the purpose of interacting with a command line interface. Given an application path, the program will be started and an interface is provided to send commands and slurp the response output.
You should not use this role directly, but instead consume it within a specific Transport that will set the application command line name, and marshall any runtime options.
INTERFACE
connect
This method must be called before any other, to establish the IPC::Run infrastructure. However via Net::CLI::Interact's cmd
, match
or find_prompt
it will be called for you automatically.
Two attributes of the specific loaded Transport are used. First the Application set in app
is of course required, plus the options in the Transport's runtime_options
are retrieved, if set, and passed as command line arguments to the Application.
done_connect
Returns True if connect
has been called successfully, otherwise returns False.
disconnect
Undefines the IPC::Run harness and flushes any output data buffer such that the next call to cmd
or macro
will cause a new connection to be made. Useful if you intentionally timeout a command and end up with junk in the output buffer.
do_action
When passed a Net::CLI::Interact::Action instance, will execute the contained instruction on the connected CLI. This might be a command to send
, or a regular expression to match
in the output.
Features of the commands and prompts are supported, such as Continuation matching (and slurping), and sending without an output record separator.
On failing to succeed with a Match, the module will time-out (see timeout
, below) and raise an exception.
Output returned after issueing a command is stored within the Match Action's response
and response_stash
slots by this method, with the latter then marshalled into the correct send
Action by the ActionSet.
send( @data )
Buffer for @data
which is to be sent to the connected CLI. Items in the list are joined together by an empty string.
out
Buffer for response data returned from the connected CLI. You can check the content of the buffer without emptying it.
flush
Empties the buffer used for response data returned from the connected CLI, and returns that data as a single text string (possibly with embedded newlines).
timeout( $seconds? )
When do_action
is polling out
for response data matching a regular expression Action, it will eventually time-out and throw an exception if nothing matches and no more data arrives.
The number of seconds to wait is set via this method, which will also return the current value of timeout
.
irs
Line separator character(s) used when interpreting the data returned from the connected CLI. This defaults to a newline on the application's platform.
irs_re
Returns a Regular Expression reference comprising the content of irs
. With the default value, this will be qr/\n/
. This is useful if you need to split
the content of your Action's response
into lines.
ors
Line separator character(s) appended to a command sent to the connected CLI. This defaults to a newline on the application's platform.
harness
Slot for storing the IPC::Run instance for the connected transport session. Do not mess with this unless you know what you are doing.
connect_options
Slot for storing a set of options for the specific loaded Transport, passed by the user of Net::CLI::Interact as a hash ref. Do not access this directly, but instead use runtime_options
from the specific Transport class.
logger
Slot for storing a reference to the application's Logger object.
AUTHOR
Oliver Gorwits <oliver@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Oliver Gorwits.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.