You are missing a result state in your session.  add result => \&result

Cheers
David

On 3/4/07, Michael Hare <[EMAIL PROTECTED]> wrote:

Does anyone have a concise working example of POE::Component::Generic to
base some testing off of?  I don't fully understand what needs to be
done with the Net::Telnet example synopsis on CPAN to make it
functional.  At a minimum, I'm guessing I need to encapsulate the entire
thing around a POE::Session->create.

I've glanced at Generic/Net/SSH2.pm and it seems a little too abstract
for me to initially get my fingers around.  I looked in the POE cookbook
and that's empty, too.

The reason I'm getting in over my head is that I've been happily using
Component::Ping for awhile now but it lacks IPv6 functionality, and I'd
like to monitor v6 stuff in our net.  I'm trying to decide whether I
should focus on seeing if I can bring Client::Ping up to snuff or to
investigate Component::Generic.  It seems that learning
Component::Generic would be, at this point, the most fruitful thing to do.

Below is where I'm at.  It seems like 'good things' are happening [Ie,
if I tcpdump, I see a telnet conversation with the remote host
occurring], but the sub 'result' never seems to fire and the POE _stop
handler is called.  I don't think I fully understand how interaction is
supposed to occur; what causes Net::Telnet to send back results, and why
is POE exiting when the generic spawn seems like it should still be
waiting for an event?

-Michael

use POE;
use POE::Component::Generic;
use strict;
use warnings;

my $telnet = POE::Component::Generic->spawn(
        package => 'Net::Telnet',
        alias => 'telnet',
#       debug => 1,
#       verbose => 1,
#       options => { trace => 1 },
);

POE::Session->create(inline_states => { _start => \&start_telnet, _stop
=> \&stop_telnet});
$poe_kernel->run();
print "completed\n";

sub start_telnet {
   print "started\n";
   $telnet->open( { event => 'result' }, "140.189.132.16");
}

sub stop_telnet {
   print "stopped\n";
   $telnet->shutdown();
}

# result state
sub result {
   my ($kernel, $ref, $result) = @_[KERNEL, ARG0, ARG1];
   if( $ref->{error} ) { die join(' ', @{ $ref->{error}} ) . "\n"; }
   print "connected: $result\n";
}

Reply via email to