2011-09-09 54 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

相關問題