The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mnet::Expect - Create Expect objects with Mnet::Log support

SYNOPSIS

    # refer to SEE ALSO section for other Mnet::Expect modules
    use Mnet::Expect;

    # spawn Expect telnet process connected to specified host
    my $expect = Mnet::Expect->new({ spawn => "telnet 1.2.3.4" });

    # access underlying Expect methods, refer to perldoc Expect
    $expect->expect->send("ls\r");

    # gracefully close spawned Expect process
    $expect->close;

DESCRIPTION

Mnet::Expect can be used to spawn Expect processes, which can be used to programmatically control interactive terminal sessions, with support for Mnet options and logging.

Refer to the perl Expect module for more information. Also refer to the Mnet::Expect::Cli and Mnet::Expect::Cli::Ios modules, both of which build on this module.

METHODS

Mnet::Expect implements the methods listed below.

new

    $expect = Mnet::Expect->new(\%opts)

This method can be used to create new Mnet::Expect objects.

The following input opts may be specified:

    log_expect  default session debug, refer to log_expect method
    log_id      refer to perldoc Mnet::Log new method
    raw_pty     undef, can be set 0 or 1, refer to perldoc Expect
    spawn       command and args array ref, or space separated string
    winsize     specify session rows and columns, default 99999x999

An error is issued if there are spawn problems.

For example, the following will spawn an telnet expect session to a device:

    my $expect = Mnet::Expect->new({ spawn => "telnet 1.2.3.4" });

Note that all connected session activity is logged for debugging, refer to the Mnet::Log module for more information.

close

    $expect->close

Attempt to call hard_close for the current Mnet::Expect objects Expect session, and send a kill signal if the process still exists.

The Expect object associated with the current Mnet::Expect object will be set to undefined. Refer also to the expect method documented below.

expect

    $expect->expect

Returns the underlying expect object used by this module, for access to fetures that may not be supported directly by Mnet::Expect modules. Refer to the Expect module for more information.

log_expect

    $prior = $expect->log_expect($level)

Use this method to set a new log_expect level for data received in the expect session. The prior log_expect value will be returned.

The new log_expect level can be set to debug, info, or undefined. An undefined log_expect disables the logging of expect session traffic, which might be useful to keep sensitive data out of log outputs.

The default log level for expect session traffic is debug.

An invalid input log_expect level results in an error.

TESTING

Mnet::Expect does not include iteself include support for Mnet::Test functionality. This is a low level module that spawns expect sessions but does not know how to talk to devices. Any desired test functionality would need to be provided by the calling script.

SEE ALSO

Expect

Mnet

Mnet::Expect::Cli

Mnet::Expect::Cli::Ios

Mnet::Log

Mnet::Opts::Cli

Mnet::Test