(Perl/POE) In POE::Component::IRC, How do you return/get data from a package_state in an external subroutine?

205 views Asked by At

I am trying to get the output data from a package_state in my IRC bot, which uses POE::Component::IRC as a base. But I just cannot seem to do it.

Basically, in a subroutine outside of the POE session, I wish to get the data from an event subroutine fired by POE when it receives the data from the server. I've tried saving the data in a global array and even external file, but the outer subroutine will read the old data from it before that data gets updated.

More specifically, I am trying to get this bot to check if someone is 'ison' and if they are, return true (or get all data ( @_ ) from irc_303).

Something like this:

sub check_ison {
    my $who = "someguy";
    $irc->yield(ison => $who);
    $data = (somehow retrieve data from irc_303);
    return $data; #or true if $data
}
1

There are 1 answers

3
Jon Portnoy On

It sounds like you want a synchronous solution to an asynchronous problem. Due to the asynchronous nature of IRC (and POE, for that matter ...), you'll need to issue your ISON query and handle the numeric response as it comes in.

As far as I know, most client NOTIFY implementations issue an ISON periodically (POE::Component::IRC provides timer sugar via POE::Component::Syndicator), update their state, and tell the user if something changes.

You have options...

You could issue ISONs on a timer, save state appropriately in your numeric response handler, and provide a method to query the state. If your application looks more like a client (the user/something needs to be notified when something changes, that is) your numeric response handler could do some basic list comparison and issue appropriate events for users appearing/disappearing.

Otherwise, you could simply have a 'check_ison' that issues the ISON and yields some sort of 'response received' event from the numeric response handler, letting you know fresh data is available.