Changeset 11546

Show
Ignore:
Timestamp:
05/14/08 03:25:19 (5 years ago)
Author:
kan
Message:

rewrite MooseX::POE based.
add ignore prop.

Location:
lang/perl/XIRCD/trunk
Files:
2 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/XIRCD/trunk

    • Property svn:ignore set to
      META.yml
      Makefile
      blib
      inc
      pm_to_blib
  • lang/perl/XIRCD/trunk/lib/XIRCD.pm

    r7015 r11546  
    44use warnings; 
    55our $VERSION = '0.01'; 
    6 use base qw/Class::Accessor::Fast/; 
    7  
    8 __PACKAGE__->mk_accessors('config'); 
    96 
    107use POE; 
     
    1916    my $config = $class->_load_conf; 
    2017 
    21     XIRCD::Server->spawn( $config->{ircd} ); 
     18    XIRCD::Server->new( config => $config->{ircd} ); 
    2219 
    23     for my $plugin ( @{$config->{plugins}} ) { 
    24         my $module = $plugin->{module}; 
     20    for my $component ( @{$config->{components}} ) { 
     21        my $module = $component->{module}; 
    2522        $module->require; 
    26         $module->spawn( $plugin ); 
     23        $module->new( config => $component ); 
    2724    } 
    2825 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Server.pm

    r7015 r11546  
    11package XIRCD::Server; 
    2 use strict; 
    3 use warnings; 
     2use MooseX::POE; 
     3 
     4with qw(MooseX::POE::Aliased); 
    45 
    56use Clone qw/clone/; 
     
    89use POE qw/Component::Server::IRC/; 
    910 
    10 sub spawn { 
    11     my $class = shift; 
    12     my $config = @_ > 1 ? {@_} : $_[0]; 
     11has 'ircd' => ( 
     12    isa => 'POE::Component::Server::IRC', 
     13    is  => 'rw', 
     14); 
    1315 
    14     $config->{servername} ||= 'xircd.ircd'; 
    15     $config->{client_encoding} ||= 'utf-8'; 
    16  
    17     my $ircd = POE::Component::Server::IRC->spawn( config => clone($config) ); 
    18     POE::Session->create( 
    19         package_states => [ 
    20             __PACKAGE__, [qw/_start ircd_daemon_public publish_message join_channel/], 
    21         ], 
    22         heap => { ircd => $ircd, config => $config }, 
    23     ); 
    24 } 
     16has 'config' => ( 
     17    isa => 'HashRef', 
     18    is  => 'rw', 
     19); 
    2520 
    2621sub debug(@) { ## no critic. 
     
    2823} 
    2924 
    30 sub _start { 
    31     my ($kernel, $heap) = @_[KERNEL, HEAP]; 
     25sub get_args(@) { ## no critic. 
     26    return @_[9..19]; 
     27} 
    3228 
    33     $kernel->alias_set('ircd'); 
     29sub START { 
     30    my $self = shift; 
    3431 
    35     my ($ircd, $config) = @$heap{qw/ircd config/}; 
     32    $self->alias('ircd'); 
    3633 
    37     $ircd->yield('register'); 
    38     $ircd->add_auth( mask => '*@*' ); 
    39     $ircd->add_listener( port => $config->{port} || 6667 ); 
     34    $self->config->{servername} ||= 'xircd.ircd'; 
     35    $self->config->{client_encoding} ||= 'utf-8'; 
     36 
     37    $self->ircd(POE::Component::Server::IRC->spawn( config => clone($self->config) )); 
     38    $self->ircd->yield('register'); 
     39    $self->ircd->add_auth( mask => '*@*' ); 
     40    $self->ircd->add_listener( port => $self->config->{port} || 6667 ); 
    4041 
    4142    debug "start irc \n\n"; 
    4243 
    43     $ircd->yield( add_spoofed_nick => { nick => $config->{server_nick} } ); 
    44  
    45     $heap->{nicknames} = {}; 
     44    $self->ircd->yield( add_spoofed_nick => { nick => $self->config->{server_nick} } ); 
    4645} 
    4746 
    48 sub ircd_daemon_public { 
    49     my ($kernel, $heap, $user, $channel, $text) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2]; 
    50     my $encoding = $heap->{config}{client_encoding}; 
     47event ircd_daemon_public => sub { 
     48    my ($self, $user, $channel, $text) = @_; 
     49    my $encoding = $self->config->{client_encoding}; 
    5150 
    52     $kernel->post( im => send_message => decode( $encoding, $text ) ); 
    53     $kernel->post( ustream => say => decode( $encoding, $text ) ); 
    54 } 
     51    POE::Kernel->post( im => send_message => decode( $encoding, $text ) ); 
     52    POE::Kernel->post( ustream => say => decode( $encoding, $text ) ); 
     53}; 
    5554 
    56 sub publish_message { 
    57     my ($kernel, $heap, $channel, $message) = @_[KERNEL, HEAP, ARG0, ARG1]; 
     55event publish_message => sub { 
     56    my $self = shift; 
     57    my ($channel, $message) = get_args(@_); 
    5858 
    5959    debug "publish to irc: [$channel] $message \n\n"; 
    6060 
    61     my ($ircd, $config) = @$heap{qw/ircd config/}; 
    62     $message = encode( $config->{client_encoding}, $message ); 
     61    $message = encode( $self->config->{client_encoding}, $message ); 
    6362 
    6463    my $say = sub { 
    6564        my ($nick, $text) = @_; 
    66         $ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ ) 
     65        $self->ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ ) 
    6766            for split /\r?\n/, $text; 
    6867    }; 
    6968 
    70     $say->($config->{server_nick}, $message); 
    71 } 
     69    $say->($self->config->{server_nick}, $message); 
     70}; 
    7271 
    73 sub join_channel { 
    74     my ($kernel, $heap, $channel) = @_[KERNEL, HEAP, ARG0]; 
    75     my ($ircd, $config) = @$heap{qw/ircd config/}; 
     72event join_channel => sub { 
     73    my $self = shift; 
     74    my ($channel,) = get_args(@_); 
    7675 
    7776    debug "join channel: $channel"; 
    7877 
    79     $ircd->yield( daemon_cmd_join => $config->{server_nick}, $channel ); 
    80 } 
     78    $self->ircd->yield( daemon_cmd_join => $self->config->{server_nick}, $channel ); 
     79}; 
    8180 
    82811;