2011-09-09 31 views

回答

4

是的,你可以。阅读this article,它应该帮助你很多。 而且,这里的的IRC和HTTP一起运行的代码示例: 记住,你需要设置你的一切运行主循环之前:POE::Kernel->run()

#!/usr/bin/env perl 
use warnings; 
use strict; 
use POE; 

# Simple HTTP server 

use POE::Component::Server::HTTP; 

POE::Component::Server::HTTP->new(
    Port   => 32090, 
    ContentHandler => { 
    '/'  => \&http_handler 
    } 
); 

sub http_handler { 
    my ($request, $response) = @_; 
    $response->code(RC_OK); 
    $response->content("<html><body>Hello World</body></html>"); 
    return RC_OK; 
} 

# Dummy IRC bot on #bottest at irc.perl.org 

use POE::Component::IRC; 

my ($irc) = POE::Component::IRC->spawn(); 

POE::Session->create(
    inline_states => { 
    _start  => \&bot_start, 
    irc_001 => \&on_connect, 
    }, 
); 

sub bot_start { 
    $irc->yield(register => "all"); 
    my $nick = 'poetest' . $$ % 1000; 
    $irc->yield(
    connect => { 
     Nick  => $nick, 
     Username => 'cookbot', 
     Ircname => 'POE::Component::IRC cookbook bot', 
     Server => 'irc.perl.org', 
     Port  => '6667', 
    } 
); 
} 

sub on_connect { $irc->yield(join => '#bottest'); } 


# Run main loop 

POE::Kernel->run(); 

并且您可以在任务之间broadcast events

+0

完美,谢谢! – Jashank

相关问题