Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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:

hi,

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.

Comment on Creating a module with POE
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://456879]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2014-12-19 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (85 votes), past polls