Net::SSH::Mechanize::Session - manage a running ssh process.
This class represents a sunning ssh process. It is a subclass of AnyEvent::Subprocess::Running, with methods to manage the authentication and other interaction with the sub-process.
ssh
AnyEvent::Subprocess::Running
Typically you will not create one directly, but obtain one via Net::SSH::Mechanize::Session->login, or Net::SSH::Mechanize->session
Net::SSH::Mechanize::Session->login
Net::SSH::Mechanize->session
You might invoke methods directly, or via Net::SSH::Mechanize instance's methods which delegate to the instance's session attribute (which is an instance of this class).
Net::SSH::Mechanize
session
use Net::SSH::Mechanize; my $mech = Net::SSH::Mechanize->new(hostname => 'somewhere'); my $session = $mech->session; # ...
$obj = $class->new(%params)
Creates a new instance. Not intended for public use. Use Net::SSH::Mechanize->session instead.
$params = $obj->connection_params
This is a read-only accessor for the connection_params instance passed to the constructor by Net::SSH::Mechanize.
connection_params
$obj->login_timeout($integer)
$integer = $obj->login_timeout
This is a read-write accessor to the log-in timeout parameter passed to the constructor.
If you plan to modify it, do so before ->login or ->login_async has been invoked or it will not have any effect on anything.
->login
->login_async
Note, all of these will throw an exception if used before ->login or before ->login_async has successfully completed, except of course ->login and ->login_async themselves. These latter methods do nothing after the first invocation.
$session = $obj->login
This method logs into the remote host using the defined connection parameters, and returns a Net::SSH::Mechanize::Session instance on success, or throws an exception on failure.
Net::SSH::Mechanize::Session
It is safe to use in AnyEvent applications or Coro co-routines, because the implementation is asynchronous and will not block the whole process.
AnyEvent
Coro
$condvar = $obj->login_async
This is an asynchronous method used to implement the synchronous ->login method. It returns an AnyEvent::CondVar instance immediately, which can be used to wait for completion, or register a callback to be notified when the log-in has completed.
$obj->logout
Logs out of the remote host by issuing an "exit" command.
$condvar = $obj->capture_async($command)
The returns a condvar immediately, which can be used to wait for successful completion (or otherwise) of the command(s) defined by $command.
$command
$result = $obj->capture($command)
This invokes the command(s) defined by $command on the remote host, and returns the result.
$condvar = $obj->sudo_capture_async($command)
The returns a condvar immediately, which can be used to wait for successful completion (or otherwise) in a sudo'ed sub-shell of the command(s) defined by $command.
A password is required in connection_params for this to authenticate with sudo.
$result = $obj->sudo_capture($command)
This invokes the command(s) defined by $command in a sudo'ed sub-shell on the remote host, and returns the result.
Nick Stokoe <npw@cpan.org>
<npw@cpan.org>
Copyright (c) 2011, Nick Stokoe <npw@cpan.org>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install Coro::AnyEvent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Coro::AnyEvent
CPAN shell
perl -MCPAN -e shell install Coro::AnyEvent
For more information on module installation, please visit the detailed CPAN module installation guide.