On Sun, Mar 13, 2005 at 06:28:24AM -0500, Ciro The Spider-Man wrote: > The project at hand is an IRC bot with web connectivity. The desired > end at this point is to visit http://hostname:port/whois/username, and > have the web browser output the data from the irc_whois event. I tried > throwing the event from within the ContentHandler, and when that > didn't work, I moved it all the way up to the transhandler, but it > still doesn't seem to want to cooperate. It seems to insist on going > ALL the way through the ContentHandler, THEN processing the > $irc->yield('whois', $nick); command, so effectively the web browser > is always 1 query behind. Is there any way I can make > POE::Component::Server::HTTP branch immediately and wait for the > result? > > Here's the relevant (I think) code. > > my $session = POE::Session->create(...); > my ($irc) = POE::Component::IRC->spawn('alias' => 'irc_client'); > #Standard IRC events here. > > sub irc_whois > { > my $info=parseWhois($_[ARG0]); > print "DEBUG: Whois Event Triggered\n"; > $_[HEAP]->{'whoisinfo'} = $info; > if ($info ne '') {return 0;} > }
The problem I see with irc_whois() is that it can only handle one request at a time. > #more junk > > my $httpd = POE::Component::Server::HTTP->new( > Port => 8080, > ContentHandler=> { > '/' => \&defaultHandler, # Just prints a generic message > '/whois/' => \&whoisHandler, > }, > TransHandler => [ \&trans ], > ); > > sub trans > { > my ($request, $response) = @_; > my $nick = (split('/', $request->uri))[4]; > $irc->yield('whois'=>nick); > } You're always whois'ing "nick" (or is it the result of evaluating sub nick() ?) Either way, it's probably not what you intended. > sub whoisHandler > { > my ($request, $response) = @_; > my $heap= $session->get_heap(); > my $output=$heap->{'whoisinfo'}; > print "DEBUG: Outputting Page\n"; > $response->content("$Output"); > } I think a better idea is to have whoisHandler return RC_WAIT (see perldoc POE::Component::Client::HTTP) and pass $nick and $response to the IRC part. The IRC part can send its whois request to IRC, build the content for $response, then call $response->continue() to pass the response back to the browser. To be sure, you could have the IRC bot deposit data for Apache or some other web server to pick up. The responses won't be realtime, but that may not be an issue. -- Rocco Caputo - http://poe.perl.org/