Changeset 2155

Show
Ignore:
Timestamp:
01/30/07 12:22:55
Author:
miyagawa
Message:

now Lingr.pm uses object_states. Add object based yield() so that you can use without aliasing. Added lingr-ircd.pl example.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • POE-Component-Client-Lingr/trunk/eg/bot.pl

    r2151 r2155  
    4747        my $nick = $occupant->{nickname} || "(anonymous)"; 
    4848        if ($occupant->{client_type} eq 'automaton') { 
    49             $nick = "($nick)"; 
     49            $nick .= "*"; 
    5050        } 
    5151        warn "  $nick\n"; 
  • POE-Component-Client-Lingr/trunk/lib/POE/Component/Client/Lingr.pm

    r2154 r2155  
    4040sub spawn { 
    4141    my($class, %args) = @_; 
    42     $args{alias} ||= 'lingr'; 
    43     POE::Session->create( 
    44         inline_states => { 
    45             _start      => \&_start, 
    46             _stop       => \&_stop, 
    47             _unregister => \&_unregister, 
    48  
    49             # API 
    50             register   => \&register, 
    51             unregister => \&unregister, 
    52             notify     => \&notify, 
    53             call       => \&call, 
    54             response   => \&http_response, 
    55         }, 
     42 
     43    my $self = bless {}, $class; 
     44 
     45    $self->{session_id} = POE::Session->create( 
     46        object_states => [ 
     47            $self => { 
     48                _start      => '_start', 
     49                _stop       => '_stop', 
     50                _unregister => '_unregister', 
     51 
     52                # API 
     53                register   => 'register', 
     54                unregister => 'unregister', 
     55                notify     => 'notify', 
     56                call       => 'call', 
     57                http_response   => 'http_response', 
     58            }, 
     59        ], 
    5660        args => [ \%args ], 
    57     )
     61    )->ID
    5862 
    5963    POE::Component::Client::HTTP->spawn( 
    6064        Agent => "POE::Component::Client::Lingr/$VERSION", 
    61         Alias => 'lingr_ua'
     65        Alias => $self->ua_alias
    6266    ); 
    6367 
    64     1; 
     68    $self; 
     69
     70 
     71sub ua_alias { 
     72    my $self = shift; 
     73    return "lingr_ua_" . $self->session_id; 
     74
     75 
     76sub session_id { $_[0]->{session_id} } 
     77 
     78sub yield { 
     79    my $self = shift; 
     80    $poe_kernel->post($self->session_id, @_); 
    6581} 
    6682 
    6783sub _start { 
    6884    my($kernel, $heap, $args) = @_[KERNEL, HEAP, ARG0]; 
    69     $kernel->alias_set($args->{alias})
     85    $kernel->alias_set($args->{alias}) if $args->{alias}
    7086} 
    7187 
     
    95111 
    96112sub call { 
    97     my($kernel, $heap, $method, $args) = @_[KERNEL, HEAP, ARG0, ARG1]; 
     113    my($kernel, $heap, $method, $args, $self) = @_[KERNEL, HEAP, ARG0, ARG1, OBJECT]; 
    98114 
    99115    my $req = create_request($heap, $method, $args); 
    100     $kernel->post(lingr_ua => request => 'response', $req); 
     116    $kernel->post($self->ua_alias => request => 'http_response', $req); 
    101117} 
    102118 
     
    277293L<http://wiki.lingr.com/dev/show/HomePage> for more details about Lingr API. 
    278294 
    279 This module is B<beta software> and its API and implementation will be 
    280 likely to be changed along with the development. 
     295This module is in its B<beta quality> and the API and implementation will be 
     296likely changed along with the further development. 
    281297 
    282298=head1 AUTHOR