in reply to POE::IRC, Where was that tall building again?

You need to do some reading on Event-driven programming and the Reactor pattern. POE is more like a state machine, with the flow of control not defined by the linear layout of code in your source; rather the sequence of external events drives what callbacks are triggered as they happen. Things happen, and when they do POE looks to see who asked to be told when that particular thing occurs. It then makes a callback to the registered routine (the handler for that event) which runs and returns control back to POE's main loop. If you've ever done any programming with an event-driven GUI toolkit that's the mindset you want to get into.

You're not in (direct) control of what happens when, the run loop is; you're responsible for telling POE what you're interested in and then let it call you back when it does. In your particular case you send the who request to start with (which causes POE to send an event to another object). When the results of that come back and are ready (because POE's told the IRC component there's been network traffic events and its handlers for those events have parsed out the who reply), that component asks POE to send you an event with the result of your initial event. You'd then do your processing of the returned results in the handler for the irc_352 event.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: POE::IRC, Where was that tall building again?

Replies are listed 'Best First'.
Re^2: POE::IRC, Where was that tall building again?
by novastorm0 (Beadle) on Jul 16, 2008 at 15:00 UTC
    I didn't know that I was being so unclear.

    I understand the basics of whats going on. I've even processed what I want in the irc_352 event. The question is how can I pass that back to where $irc->yield( who => '#poe') was called. I could use globals but there has to be some manageable way to pass around the results of each event. Thats more or less what I'm asking.

    I'm looking to translate my @results = $irc->yield (who => '#poe'); into the POE realm if its even possible.

      That's the thing: there isn't anything inside of POE itself to tie any random pair of events together. It's not that you're unclear; more that I'm explaining it poorly and it requires you to have an "Aha!" moment and get your head thinking the POE-y state machine way. Let's try this:

      Your sessions are what's responsible for maintaining state (most cleanly through declaring object_states which will be called as methods on an instance; see Using POE::Session With Objects; alternately you can stash things in the session's private $_[HEAP] if you don't want to make a separate class). Your session instances maintain any context or state information (maybe by doing push @{$self->{pending_who_requests}}, $channel) and then alter their state accordingly as events warrant (removing an entry from that pending list and firing off an event back to the requesting session (or the same session) with the processed who information when it receives the reply event to a given request).

      Update: Added mention of $_[HEAP] to parenthetical.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.