Hi,

I am having problems getting error back from POE.

Sorry for keeping this a tad short, but in this excerpt, I have a
Server::TCP component with this ClientConnected data:

POE::Component::Server::TCP
  ->new(
        Alias              => 'server',
        Port               => $port_start,
        ClientFilter       => 'POE::Filter::Reference',

        SessionParams      => [ options => { debug => $debug,
                                             trace => $trace_poe } ],
*        ClientConnected    => \&Smed::Net::Server::client_connected,*
        ClientDisconnected => \&Smed::Net::Server::client_disconnected,
        ClientInput        => \&Smed::Net::Server::handle_message,
        ClientError        => sub {
           my ($syscall_name, $error_num, $error_str) = @_[ARG0..ARG2];
           warn "CLIENT ERROR: $syscall_name: $error_str";
         },

        ClientShutdownOnError => 1,

        InlineStates => {
                         status =>
                         sub {
                           $_[HEAP]->{client}
                             ->put( Smed::Message->new( action => 'status',
                                                        data => $_[ARG0] ))
},
                        },
       );
[...]

and important parts of Smed::Net::Server look like:

use strict;
use warnings;

#use Log::Trace;
use POE;

[...]

sub client_connected {
  warn "SESSION: ", $_[SESSION]->ID;
  TRACE( 'Client ' . $_[SESSION]->ID . ' connected' );
}

When a client connects, the "client_connected" sub is called, but is
immediately disconnected (since TRACE is undefined). "Log::Trace" is
commented out as you can see, to show that I had originally forgotten to add
it to the file. But there is no error message from POE that "TRACE" is
undefined(!) when this code is executed, it just silently disconnects the
client and shuts down the TCP server with it. If I add "use Log::Trace;"
then the application works as expected.

I tried to reproduce this in a minimalistic fashion:

*nettest.pl:*
#!/usr/bin/perl

use warnings;
use strict;

use Log::Trace;
use Net;

use POE qw(Component::Server::TCP);

POE::Component::Server::TCP
  ->new(
Port => 12345,
SessionParams => [ options => { debug => 1, trace => 1 } ],
ClientConnected => \&Net::client_connected,
ClientInput => sub {
  my $client_input = $_[ARG0];
  $client_input =~ tr[a-zA-Z][n-za-mN-ZA-M];
  $_[HEAP]{client}->put($client_input);
},
       );

POE::Kernel->run;
exit;

*Net.pm:*
package Net;

use strict;
use warnings;

use POE;

sub client_connected {
  TRACE( 'Client ' . $_[SESSION]->ID . ' connected' );
}

1;

In this case POE happily aborts and reports the error:

Undefined subroutine &Net::TRACE called at Net.pm line 9.

I am certain that I am the culprit here :-), but I have not been able to
determine what I can have done to cause this behavior. I can continue with
the prorgam now that I know what the error is, but I would really like to
avoid running into this again.

BR
Gunnar

Reply via email to