How do I check if a user is authenticated with NickServ using POE::Component::IRC::State in Perl?

Posted by Troy on Stack Overflow See other posts from Stack Overflow or by Troy
Published on 2009-12-13T18:51:59Z Indexed on 2010/05/23 5:30 UTC
Read the original article Hit count: 370

Filed under:
|
|

I'm trying to test whether a user is registered on FreeNode. nick_info() doesn't seem to return information about this, so I want to use $irc->yield(whois => $nick); and then grab the irc_whois event's reply. The problem is that I want to wait until this event is fired, so I created a global variable $whois_result and wrote a sub like this:

sub whois {
    my $nick = $_[0];
    $whois_result = 0;
    $irc->yield(whois => $nick);
    while($whois_result == 0) { }
    return $whois_result;
}

with the irc_whois handler looking like:

sub on_whois {
    $whois_result = $_[ARG0];
    print "DEBUG: irc_whois fired.\n";
}

Unfortunately, the event can't fire while the loop is running so this hangs. I'm sure there's a better way to do this, but I'm not familiar enough with this kind of programming to know. Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about perl

Related posts about irc