Changeset 11745 for lang/perl/XIRCD

Show
Ignore:
Timestamp:
05/17/08 16:52:21 (7 years ago)
Author:
kan
Message:

make XIRCD::Role

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

Legend:

Unmodified
Added
Removed
  • lang/perl/XIRCD/trunk/lib/XIRCD.pm

    r11669 r11745  
    1919 
    2020    for my $component ( @{$config->{components}} ) { 
    21         my $module = $component->{module}; 
     21        my $module = 'XIRCD::Component::' . $component->{module}; 
    2222        $module->require; 
    23         $module->new( config => $component ); 
     23        $module->new(  
     24            name    => lc($component->{module}), 
     25            channel => '#' . lc($component->{module}), 
     26            %{$component}  
     27        ); 
     28        warn "load $module"; 
    2429    } 
    2530 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component.pm

    r11679 r11745  
    66 
    77use Sub::Exporter -setup => { 
    8     exports => [qw(self debug get_args http_alias)], 
     8    exports => [qw(self debug get_args http_alias yield delay post publish_message publish_notice)], 
    99    groups  => {  
    1010        default => [ -all ],  
     
    2424} 
    2525 
     26sub yield (@) { ## no critic. 
     27    POE::Kernel->yield(@_); 
     28} 
     29 
     30sub delay (@) { ## no critic. 
     31    POE::Kernel->delay(@_); 
     32} 
     33 
     34sub post (@) { ## no critic. 
     35    POE::Kernel->post(@_); 
     36} 
     37 
     38sub publish_message ($$) {  ## no critic. 
     39    my $self = (caller_args(1))[0]; 
     40    my ($nick, $text) = @_; 
     41 
     42    post ircd => 'publish_message' => $nick, $self->channel, $text; 
     43} 
     44 
     45sub publish_notice ($) {  ## no critic. 
     46    my $self = (caller_args(1))[0]; 
     47    my ($text,) = @_; 
     48 
     49    post ircd => 'publish_notice' => $self->channel, $text; 
     50} 
     51 
    2652 
    27531; 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component/Time.pm

    r11679 r11745  
    33use XIRCD::Component; 
    44 
    5 with qw(MooseX::POE::Aliased); 
     5with qw(XIRCD::Role); 
     6 
     7has 'nick' => ( isa => 'Str', io => 'rw' ); 
    68 
    79use DateTime; 
    810 
    9 has 'config' => ( 
    10     isa => 'HashRef', 
    11     is  => 'rw', 
    12 ); 
    13  
    14 has 'date' => ( 
    15     isa     => 'DateTime', 
    16     is      => 'ro', 
    17     default => sub { DateTime->now( time_zone => 'Asia/Tokyo' ) }, 
    18 ); 
    19  
    20 sub START { 
    21     self->alias('time'); 
    22  
    23     debug 'start time'; 
    24  
    25     POE::Kernel->post( ircd => 'join_channel', self->config->{channel} ); 
    26     self->yield('timecall'); 
    27 } 
    28  
    29 event timecall => sub { 
    30     debug "timecall"; 
    31  
    32     POE::Kernel->post( 
    33         ircd => 'publish_message' => 'time', 
    34         self->config->{channel}, self->date->strftime("%Y/%m/%d %H:%M:%S") 
    35     ); 
    36     POE::Kernel->delay( 'timecall', 10 ); 
     11event start => sub { 
     12    my $date = DateTime->now(time_zone => 'Asia/Tokyo'); 
     13    publish_message self->nick => $date->strftime("%Y/%m/%d %H:%M:%S"); 
     14    delay 'start', 10; 
    3715}; 
    3816