Changeset 11757

Show
Ignore:
Timestamp:
05/17/08 17:56:53 (5 years ago)
Author:
kan
Message:

component config to attribute.
fix TODO

Location:
lang/perl/XIRCD/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/XIRCD/trunk/TODO

    r11679 r11757  
    1 - auto START & STOP 
    2 -- auto join channel 
    3 -- config to attribute 
    4 -- join_channel, yeild, publish_message, etc ... write DSL 
    51- support TIG like message queue 
     2- more tests 
  • lang/perl/XIRCD/trunk/lib/XIRCD.pm

    r11751 r11757  
    2626            %{$component}  
    2727        ); 
    28         warn "load $module"; 
    2928    } 
    3029 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component.pm

    r11745 r11757  
    4040    my ($nick, $text) = @_; 
    4141 
    42     post ircd => 'publish_message' => $nick, $self->channel, $text; 
     42    post ircd => '_publish_message' => $nick, $self->channel, $text; 
    4343} 
    4444 
     
    4747    my ($text,) = @_; 
    4848 
    49     post ircd => 'publish_notice' => $self->channel, $text; 
     49    post ircd => '_publish_notice' => $self->channel, $text; 
    5050} 
    5151 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component/Server.pm

    r11679 r11757  
    6060}; 
    6161 
    62 event publish_message => sub { 
     62event _publish_message => sub { 
    6363    my ($nick, $channel, $message) = get_args; 
    6464 
     
    7878}; 
    7979 
    80 event publish_notice => sub { 
     80event _publish_notice => sub { 
    8181    my ($channel, $message) = get_args; 
    8282 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component/Twitter.pm

    r11679 r11757  
    33use XIRCD::Component; 
    44 
    5 with qw(MooseX::POE::Aliased); 
     5with qw(XIRCD::Role); 
    66 
    77use Encode; 
     
    1313 
    1414 
    15 has 'config' => ( 
    16     isa => 'HashRef', 
    17     is  => 'rw', 
    18 ); 
     15has 'apiurl'   => ( isa => 'Str', is => 'rw', default => sub { 'http://twitter.com/statuses' } ); 
     16has 'apihost'  => ( isa => 'Str', is => 'rw', default => sub { 'twitter.com:80' } ); 
     17has 'apirealm' => ( isa => 'Str', is => 'rw', default => sub { 'Twitter API' } ); 
     18 
     19has 'screenname' => ( isa => 'Str', is => 'rw' ); 
     20has 'username'   => ( isa => 'Str', is => 'rw' ); 
     21has 'password'   => ( isa => 'Str', is => 'rw' ); 
     22has 'retry'      => ( isa => 'Int', is => 'rw', default => sub { 60 } ); 
    1923 
    2024has 'since' => ( 
     
    2529    my $call = shift; 
    2630 
    27     my self = $call->(@_); 
     31    my $self = $call->(@_); 
    2832 
    2933    POE::Component::Client::HTTP->spawn( 
    3034        Agent => 'xircd_component_twitter/0.1', 
    31         Alias => self->http_alias, 
     35        Alias => $self->http_alias, 
    3236    ); 
    3337 
    34     self->config->{apiurl}   ||= 'http://twitter.com/statuses'; 
    35     self->config->{apihost}  ||= 'twitter.com:80'; 
    36     self->config->{apirealm} ||= 'Twitter API'; 
    37     self->config->{alias}    ||= 'twitter'; 
    38  
    39     return self; 
     38    return $self; 
    4039}; 
    41  
    42 sub START { 
    43     self->alias('twitter'); 
    44  
    45     debug "start twitter"; 
    46  
    47     POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias ); 
    48     self->yield('read_twitter_friend_timeline'); 
    49 } 
    5040 
    5141event send_message => sub { 
     
    5343 
    5444    my $req = HTTP::Request::Common::POST( 
    55         self->config->{apiurl} . '/update.json', 
     45        self->apiurl . '/update.json', 
    5646        [ status => encode('utf-8',$status) ], 
    5747    );   
    58     $req->authorization_basic(self->config->{twitter}->{username}, self->config->{twitter}->{password}); 
     48    $req->authorization_basic(self->username, self->password); 
    5949 
    60     POE::Kernel->post(self->http_alias => request => 'http_response', $req); 
     50    post self->http_alias => request => 'http_response', $req; 
    6151}; 
    6252 
    63 event read_twitter_friend_timeline => sub { 
     53event start => sub { 
    6454    debug "read twitter"; 
    6555 
    66     my $uri = URI->new(self->config->{apiurl} . '/friends_timeline.json'); 
     56    my $uri = URI->new(self->apiurl . '/friends_timeline.json'); 
    6757    $uri->query_form(since => HTTP::Date::time2str(self->since)) if self->since; 
    6858    self->since(time); 
    6959 
    7060    my $req = HTTP::Request->new(GET => $uri); 
    71     $req->authorization_basic(self->config->{twitter}->{username}, self->config->{twitter}->{password}); 
     61    $req->authorization_basic(self->username, self->password); 
    7262 
    73     POE::Kernel->post(self->http_alias => request => 'http_response', $req); 
     63    post self->http_alias => request => 'http_response', $req; 
    7464}; 
    7565 
     
    8373    if ($uri =~ /update.json/) { 
    8474        unless ($response->is_success) { 
    85             self->yield(response_error => $response); 
     75            yield response_error => $response; 
    8676            return; 
    8777        } 
    88         self->yield(update_success => $response); 
     78        yield update_success => $response; 
    8979    } elsif ($uri =~ /friends_timeline.json/) { 
    90         self->yield(friend_timeline_success => $response); 
     80        yield friend_timeline_success => $response; 
    9181    } 
    9282}; 
     
    9989        my $ret = JSON::Any->jsonToObj($response->content); 
    10090        for my $line ( reverse @{ $ret || [] } ) { 
    101             POE::Kernel->post( 
    102                 ircd => publish_message =>  
    103                     $line->{user}->{screen_name}, 
    104                     self->config->{channel},  
    105                     $line->{text}, 
    106             ); 
     91            publish_message  $line->{user}->{screen_name} => $line->{text}; 
    10792        } 
    10893    } 
    10994 
    110     POE::Kernel->delay('read_twitter_friend_timeline', self->config->{twitter}->{retry}); 
     95    delay start => self->retry; 
    11196}; 
    11297 
     
    116101    if ( $response->is_success ) { 
    117102        my $ret = JSON::Any->jsonToObj($response->content); 
    118         POE::Kernel->post( ircd => publish_notice => self->config->{channel}, $ret->{text} ); 
     103        publish_notice $ret->{text}; 
    119104    } 
    120105}; 
  • lang/perl/XIRCD/trunk/lib/XIRCD/Component/Wassr.pm

    r11679 r11757  
    33use XIRCD::Component; 
    44 
    5 with 'MooseX::POE::Aliased'; 
     5with 'XIRCD::Role'; 
    66 
    77use POE qw( 
     
    1515use POE::Filter::XML::NS qw/:JABBER :IQ/; 
    1616 
    17 has 'config' => ( 
    18     isa => 'HashRef', 
    19     is  => 'rw', 
    20 ); 
    21  
    2217has 'jabber' => ( 
    2318    isa     => 'POE::Component::Jabber', 
    2419    is      => 'rw', 
    2520); 
     21 
     22has 'username' => ( isa => 'Str', is => 'rw' ); 
     23has 'password' => ( isa => 'Str', is => 'rw' ); 
     24has 'server'   => ( isa => 'Str', is => 'rw' ); 
     25has 'port'     => ( isa => 'Int', is => 'rw', default => sub { 5222 } ); 
    2626 
    2727has 'jid' => ( 
     
    3030); 
    3131 
    32 sub START { 
     32event start => sub { 
    3333    self->alias('wassr'); 
    3434 
    3535    debug "start wassr"; 
    36  
    37     my ($username, $hostname) = split '@', self->config->{jabber}->{username}; 
     36    warn self->channel; 
     37    my ($username, $hostname) = split '@', self->username; 
    3838 
    3939    self->jabber( 
    4040        POE::Component::Jabber->new( 
    41             IP       => self->config->{jabber}->{server}, 
    42             Port     => self->config->{jabber}->{port} || 5222, 
     41            IP       => self->server, 
     42            Port     => self->port, 
    4343            Hostname => $hostname, 
    4444            Username => $username, 
    45             Password => self->config->{jabber}->{password}, 
     45            Password => self->password, 
    4646            Alias    => 'jabber', 
    4747            States   => { 
     
    5454    ); 
    5555 
    56     POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias ); 
    57     POE::Kernel->post( jabber => 'connect' ); 
    58 } 
     56    post jabber => 'connect'; 
     57}; 
    5958 
    6059event status_handler => sub { 
     
    6564        self->jid(self->jabber->jid); 
    6665 
    67         POE::Kernel->post(jabber => 'output_handler', POE::Filter::XML::Node->new('presence')); 
    68         POE::Kernel->post(jabber => 'purge_queue'); 
     66        post jabber => 'output_handler', POE::Filter::XML::Node->new('presence'); 
     67        post jabber => 'purge_queue'; 
    6968    } 
    7069}; 
    7170 
    7271event input_handler => sub { 
    73     my self = shift; 
    7472    my ($node,) = get_args; 
    7573 
     
    8179        my ($nick, $text) = $body->data =~ /^([A-Za-z0-9_.-]+): (.*)/s; 
    8280        if ($nick && $text) { 
    83             POE::Kernel->post( ircd => 'publish_message', $nick, self->config->{channel}, $text ); 
     81            publish_message $nick => $text; 
    8482        } else { 
    85             POE::Kernel->post( ircd => 'publish_notice', self->config->{channel}, $body->data ); 
     83            publish_notice self->config->{channel} => $body->data; 
    8684        } 
    8785    } 
     
    10098    debug "send:", $node->to_str; 
    10199 
    102     POE::Kernel->post( jabber => output_handler => $node ); 
     100    post jabber => output_handler => $node; 
    103101}; 
    104102 
     
    107105 
    108106    if ( $error == +PCJ_SOCKETFAIL or $error == +PCJ_SOCKETDISCONNECT or $error == +PCJ_CONNECTFAIL ) { 
    109         print "Reconnecting!\n"; 
    110         POE::Kernel->post( jabber => 'reconnect' ); 
     107        debug "Reconnecting!"; 
     108        post jabber => 'reconnect'; 
    111109    } 
    112110    elsif ( $error == +PCJ_SSLFAIL ) { 
    113         print "TLS/SSL negotiation failed\n"; 
     111        debug "TLS/SSL negotiation failed"; 
    114112    } 
    115113    elsif ( $error == +PCJ_AUTHFAIL ) { 
    116         print "Failed to authenticate\n"; 
     114        debug "Failed to authenticate"; 
    117115    } 
    118116    elsif ( $error == +PCJ_BINDFAIL ) { 
    119         print "Failed to bind a resource\n"; 
     117        debug "Failed to bind a resource"; 
    120118    } 
    121119    elsif ( $error == +PCJ_SESSIONFAIL ) { 
    122         print "Failed to establish a session\n"; 
     120        debug "Failed to establish a session"; 
    123121    } 
    124122};