Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Creating a module with POE

by dannoura (Pilgrim)
on May 13, 2005 at 20:11 UTC ( #456879=perlquestion: print w/replies, xml ) Need Help??
dannoura has asked for the wisdom of the Perl Monks concerning the following question:


I'm trying to create a module with POE. The problem is that as far as I can tell the script doesn't reach the _ready state. Relevant parts of the code are below.

package ParallelDownloader; use strict; use Carp; use POE qw(Component::Client::HTTP); sub new { my ($class, $requests)=@_; my $self={requests=>$requests}; return bless $self, $class; } sub go { my $self=shift; POE::Component::Client::HTTP->spawn(Alias => 'ua'); POE::Session->create( inline_states => { _start => \&_initialize_session, ready => \&_ready, download => \&_download, got_response => \&_got_response }, heap => {TODO => $self->{requests}} ); $poe_kernel->run(); return _finished(); } sub _initialize_session { my $kernel = $_[KERNEL]; print "at init\n"; $kernel->yield("_ready"); } sub _ready { my $kernel=$_[KERNEL]; my $heap=$_[HEAP]; print "at ready\n"; return unless (@{$heap->{TO_GET}}=splice @{$heap->{TODO}}, 0, 5 +); $kernel->yield("_download"); }


Any comments about coding style are welcome.

Replies are listed 'Best First'.
Re: Creating a module with POE
by johnnywang (Priest) on May 13, 2005 at 20:51 UTC
    I spot at least one problem, try:
    $kernel->yield("ready"); #not $kernel->yield("_ready")
    _ready is your event handler name, the event name is "ready". (There might be other problems, haven't tested.)

      Yeah, that was it. Stupid mistake, late hour, I promise not to do it again.

Re: Creating a module with POE
by rcaputo (Chaplain) on Jun 10, 2005 at 21:15 UTC

    Set POE_ASSERT_DEFAULT=1 in your shell environment before running the program. That will turn many slightly bad practices into nasty fatal errors. POE::Kernel documents it as ASSERT_DEFAULT, and it explains the specific ASSERT_* flags you can toggle individually.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://456879]
Approved by Corion
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-12-11 05:04 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (286 votes). Check out past polls.