NAME
POE::Component::Client::Telnet - A POE component that provides non-blocking access to Net::Telnet and other subclasses of Net::Telnet.
SYNOPSIS
use POE::Component::Client::Telnet;
my $poco = POE::Component::Client::Telnet->new(
alias => 'telnet', # optional; You can use $poco->session_id() instead
debug => 1, # optional; 1 to turn on debugging
options => { trace => 1 }, # optional; Options passed to the internal session
package => 'Net::Telnet::Cisco', # optional; Allows use of other Net::Telnet
telnet_options => [ ], # optional; Options passed to Net::Telnet->new()
);
# Start your POE session, then...
$kernel->post('telnet' => open => { event => 'result' },"rainmaker.wunderground.com");
sub result {
my ($kernel,$ref) = @_[KERNEL,ARG0];
if ( $ref->{result} ) {
print "connected: $ref->{result}\n";
} else {
print STDERR join(' ', @{ $ref->{error} ) . "\n";
}
}
DESCRIPTION
POE::Component::Client::Telnet is a POE component that provides a non-blocking wrapper around Net::Telnet, or any other module based on Net::Telnet.
Consult the Net::Telnet documentation for more details.
METHODS
- new
-
Takes a number of arguments, all of which are optional. 'alias', the kernel alias to bless the component with; 'debug', set this to 1 to see component debug information; 'options', a hashref of POE::Session options that are passed to the component's session creator; 'telnet_options', an optional array ref of options that will be passed to Net::Telnet->new(); 'package', an optional package name that is a base of Net::Telnet, like Net::Telnet::Cisco.
- session_id
-
Takes no arguments, returns the POE::Session ID of the component. Useful if you don't want to use aliases.
- yield
-
This method provides an alternative object based means of posting events to the component. First argument is the event to post, following arguments are sent as arguments to the resultant post.
$poco->yield( open => { event => 'result' }, "localhost" );
- call
-
This method provides an alternative object based means of calling events to the component. First argument is the event to call, following arguments are sent as arguments to the resultant call.
$poco->call( open => { event => 'result' }, "localhost" );
- (all other Net::Telnet methods
-
All Net::Telnet methods can be called, but the first param must be the options hash as noted below in the INPUT section below.
For example:
$poco->open( { event => 'opened' },"localhost" );
One exception, the 'option_callback' method accepts an event name instead of a code ref. If called with no params, 'result' will be the event currently set. Also, when the callback is fired, 'result' will be an array ref of $option, $is_remote, $is_enabled, $was_enabled, $buf_position. See the 'option_callback' method of Net::Telnet for details.
INPUT
These are the events that the component will accept. Each event requires a hashref as an argument with the following keys: 'event', the name of the event handler in *your* session that you want the result of the requested operation to go to. 'event' is needed for all requests that you want a response to.
It is possible to pass arbitary data in the request hashref that could be used in the resultant event handler. Simply define additional key/value pairs of your own. It is recommended that one prefixes keys with '_' to avoid future clashes.
OUTPUT
For each requested operation an event handler is required. ARG0 of this event handler contains a hashref.
The hashref will contain keys for 'state', and 'result'. 'state' is the operation that was requested, 'result' is what the function returned.
- result
-
This is data returned from the function you called. Usually a scalar, but can be an array ref when using 'option_callback'.
- error
-
In the event of an error occurring this will be defined. It is an scalar which contains the error.
AUTHOR
David Davis <xantus@cpan.org>
SEE ALSO
POE, Net::Telnet, Net::Telnet::Cisco, Net::Telnet::Netscreen, Net::Telnet::Options
RATING
Please rate this module. http://cpanratings.perl.org/rate/?distribution=POE-Component-Client-Telnet
BUGS
Probably. Report them here: http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE%3A%3AComponent%3A%3AClient%3A%3ATelnet
CREDITS
BinGOs for POE::Component::Win32::Service that helped me get started.
COPYRIGHT AND LICENSE
Copyright 2005 by David Davis and Teknikill Software
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.