Hello POE world,I'm trying to create a package that will spawn IKC clients.
I see that on_connect, on_error and subscribe are deprecated but all docs
and cookbook programs use the deprecated examples. What would be the best
way to implement my __spawn function using the ikc responder/monitor instead
of the old deprecated functions for the client.
************ FROM IKC CLIENT DOCS **************
on_connect
DEPRECATED. Please use the IKC/monitor stuff. See
POE::Component::IKC::Responder<http://search.cpan.org/%7Egwyn/POE-Component-IKC-0.2003/IKC/Responder.pm>
.
on_error
DEPRECATED. Please use the IKC/monitor stuff. See
POE::Component::IKC::Responder<http://search.cpan.org/%7Egwyn/POE-Component-IKC-0.2003/IKC/Responder.pm>.
Note, also, that the coderef will be executed from within an IKC session,
NOT within your own session. This means that things like
$poe_kernel->delay_set() won't do what you think they should.
subscribe
Array ref of specifiers (either foreign sessions, or foreign states) that
you want to subscribe to. on_connect will only be called when IKC has
managed to subscribe to all specifiers. If it can't, it will die(). YOW that
sucks. monitor will save us all.
***********************************************************
################### CODE #################
sub __spawn {
my $class = shift;
my $addr = $class->IP || '127.0.0.1';
my $port = $class->PORT || 5667;
## spawn all the ikc client
my $server = POE::Component::IKC::Client->spawn(
ip => $addr,
port => $port,
name => "Client$$",
on_connect => sub {
POE::Session->create(
package_states =>
## extract all subroutines that don't start with "__"
## and allocate them as states:
[ (__PACKAGE__) => [ do {
no strict 'refs';
grep { !/^__/ and defined &$_ } keys %{
__PACKAGE__ . "::" };
} ] ],
## pass args into _start:
args => [...@_],
);
},
on_error => sub {
my ( $kernel ) = $_[ KERNEL];
print Dumper($kernel);
},
subscribe =>[qw(poe:/*)]
);
return $server;
}
#################################################
--J