Hi,
I'm trying to trap a ConnectError, and return if it occurs. I want to
return out of my ->new method with an undef if my
POE::Component::Client::TCP fails to connect to the server. I'm doing it
with flags, but I'm wondering if there is some POE built in device for
accomplishing this. Below is the code. I'm not sure of a better way to
explain it.
Thanks
Jay
# I'm leaving stuff out for brevity
package TradeStudy::TWS_Client;
use POE qw(Component::Client::TCP Filter::Reference);
my $connected = 0;
my $connectError = 0;
sub new {
my $class = shift;
my %arg = @_;
$arg{port} ||= 12001;
my $self = $class->SUPER::new(\%arg);
$poe_kernel->run;
POE::Component::Client::TCP->new(
RemoteAddress => "localhost",
Filter => "POE::Filter::Reference",
RemotePort => $self->port,
Alias => "client_connection",
Connected => \&connected,
ConnectError => \&connectError,
);
while (!$connected and !$connectError) {
$poe_kernel->run_one_timeslice();
}
return $connectError ? undef : $self;
}
...
sub connectError { $connectError = 1; }
sub connected { $connected = 1; };