NAME
Net::SSH::Mechanize::Session - manage a running ssh process.
VERSION
version 0.1.3
SYNOPSIS
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.
Typically you will not create one directly, but obtain one via Net::SSH::Mechanize::Session->login
, or 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).
use Net::SSH::Mechanize;
my $mech = Net::SSH::Mechanize->new(hostname => 'somewhere');
my $session = $mech->session;
# ...
CLASS METHODS
$obj = $class->new(%params)
Creates a new instance. Not intended for public use. Use Net::SSH::Mechanize->session
instead.
INSTANCE ATTRIBUTES
$params = $obj->connection_params
This is a read-only accessor for the connection_params
instance passed to the constructor by Net::SSH::Mechanize
.
$obj->login_timeout($integer)
=head2 $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.
INSTANCE METHODS
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.
It is safe to use in AnyEvent
applications or Coro
co-routines, because the implementation is asynchronous and will not block the whole process.
$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
.
$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.
AUTHOR
Nick Stokoe <wulee@cpan.org>
LICENCE AND COPYRIGHT
Copyright (c) 2011, Nick Stokoe <wulee@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.