Changeset 67

Show
Ignore:
Timestamp:
05/04/08 18:30:03 (8 months ago)
Author:
scott
Message:

Fixed IRC client example

Location:
trunk/Curses-UI-POE
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/Curses-UI-POE/MANIFEST.SKIP

    r13 r67  
    66^blib/ 
    77^Makefile$ 
    8 ^POE-Component-Client-TCPMulti- 
     8^Curses-UI-POE 
    99^MANIFEST.bak$ 
    1010^pm_to_blib$ 
     
    1919\.tar\.gz$ 
    2020\.tgz$ 
     21^reproduce.* 
     22tmp 
  • trunk/Curses-UI-POE/POE.pm

    r65 r67  
    2424BEGIN { run POE::Kernel } 
    2525 
    26 *VERSION = \0.03; 
     26*VERSION = \0.032; 
    2727our $VERSION; 
    2828 
     
    7272          object_states  => [ 
    7373            @{ $options{object_states} }, 
    74             $self, [ qw( _start keyin timer shutdown ) ] 
     74            $self, [ qw( _start init keyin timer shutdown ) ] 
    7575          ], 
    7676           
     
    8484} 
    8585 
    86 sub _start { 
     86# Wait until the kernel actually starts before we muck with things. 
     87sub _start { $_[KERNEL]->yield("init") } 
     88 
     89sub init { 
    8790    my ($self, $kernel) = @_[ OBJECT, KERNEL ]; 
    8891 
     
    138141    } 
    139142 
    140 # This was a hack to make sure to pick up the extra events when things got out 
    141 # of sync.  I'm not sure if I need it.  But let's try getting C::U::P working 
    142 # first. 
    143 #   if (my $key = $self->get_key(0)) { 
    144 #       $self->feedkey($key) unless $key eq "-1"; 
    145 #       $self->do_one_event; 
    146 #   } 
    147  
     143    # This was a hack to make sure to pick up the extra events when things got 
     144    # out of sync.  It was suggested 
     145    if (my $key = $self->get_key(0)) { 
     146        $self->feedkey($key) unless $key eq "-1"; 
     147        $self->do_one_event; 
     148    } 
     149  
    148150    # Set the root cursor mode 
    149151    unless ($self->{-no_output}) { 
     
    190192    } 
    191193 
     194 
     195 
     196    no warnings "redefine"; 
     197 
     198    my $modalfocus = \&Curses::UI::Widget::modalfocus; 
     199 
     200    # Let modalfocus() be a reentrant into the POE Kernel.  This is stackable, 
     201    # so it should not impact other behaviors, and POE keeps chugging along 
     202    # uneffected.  This is a modal focus without a callback, this method does 
     203    # not return until the modal widget get's cleared out. 
     204    # 
     205    # This is done here so that ->dailog will still work as it did previously. 
     206    # until this is run.  And just in case, we save the old modalfocus 
     207    # definition and redefine it later. 
     208    sub Curses::UI::Widget::modalfocus () { 
     209        my ($this) = @_; 
     210 
     211        # "Fake" focus for this object. 
     212        $this->{-has_modal_focus} = 1; 
     213        $this->focus; 
     214        $this->draw; 
     215 
     216        push @modal_objects, $this; 
     217        push @modal_callbacks, undef; 
     218 
     219        # This is reentrant into the POE::Kernel  
     220        while ( $this->{-has_modal_focus} ) { 
     221            $poe_kernel->loop_do_timeslice; 
     222        } 
     223 
     224        $this->{-focus} = 0; 
     225 
     226        pop @modal_callbacks; 
     227        pop @modal_objects; 
     228 
     229        return $this; 
     230    } 
     231 
    192232    POE::Kernel->run; 
     233 
     234    # Replace previously defined method into the symbol table. 
     235    *{"Curses::UI::Widget::modalfocus"} = $modalfocus; 
    193236} 
    194237 
     
    242285    } 
    243286 
    244     # Let modalfocus() be a reentrant into the POE Kernel.  This is stackable, 
    245     # so it should not impact other behaviors, and POE keeps chugging along 
    246     # uneffected.  This is a modal focus without a callback, this method does 
    247     # not return until the modal widget get's cleared out. 
    248     sub Curses::UI::Widget::modalfocus () { 
    249         my ($this) = @_; 
    250  
    251         # "Fake" focus for this object. 
    252         $this->{-has_modal_focus} = 1; 
    253         $this->focus; 
    254         $this->draw; 
    255  
    256         push @modal_objects, $this; 
    257         push @modal_callbacks, undef; 
    258  
    259         # This is reentrant into the POE::Kernel  
    260         while ( $this->{-has_modal_focus} ) { 
    261             $poe_kernel->loop_do_timeslice; 
    262         } 
    263  
    264         $this->{-focus} = 0; 
    265  
    266         pop @modal_callbacks; 
    267         pop @modal_objects; 
    268  
    269         return $this; 
    270     } 
    271287} 
    272288 
     
    360376=head1 BUGS 
    361377 
    362 None Known.  Whoohoo! 
    363  
    364 Find any?  Send them to me!  tag@cpan.org 
     378=over 2 
     379 
     380=item Dialogs before ->mainloop() 
     381 
     382Dialogs before Curses::UI::Mainloop 
     383 
     384=back 
     385 
     386Find more?  Send them to me!  tag@cpan.org 
    365387 
    366388=head1 AUTHOR 
     
    386408 
    3874091; 
    388  
    389 __END__ 
    390 This is a block of no longer needed code.  When I feel up to it, 
    391 I will remove it. 
    392  
    393 # The tempdialog does this modalfocus in Curses::UI::Widget which 
    394 # starts a secondary event loop.  I need to force use of POE.  
    395  
    396 #sub tempdialog { 
    397 #    my $this = shift; 
    398 #    my $class = shift; 
    399 #    my %args = @_; 
    400 # 
    401 #    my $id = "__window_$class"; 
    402 # 
    403 #    my $dialog = $this->add($id, $class, %args); 
    404 # 
    405 #    $dialog->{-has_modal_focus} = 1; 
    406 # 
    407 #    $dialog->focus; 
    408 #    $dialog->draw; 
    409 # 
    410 #    # We loop ourself, this is a modial dialog..but its still gotta multitask. 
    411 #    while ( $dialog->{-has_modal_focus} ) { 
    412 #        $poe_kernel->loop_do_timeslice; 
    413 #    } 
    414 # 
    415 #    my $return = $dialog->get; 
    416 # 
    417 #    $dialog->{-focus} = 0; 
    418 # 
    419 #    $this->delete($id); 
    420 #    $this->root->focus(undef, 1); 
    421 # 
    422 #    return $return; 
    423 #} 
    424  
    425 # This is null prototyped only to match the Curses::UI::Widget 
    426 # subroutine it replaces...it SHOULDN'T be prototyped at all 
    427 # since it is a method. 
    428  
  • trunk/Curses-UI-POE/examples/irc_client

    r65 r67  
    88use POE qw( Component::IRC ); 
    99use Curses::UI::POE; 
     10use Carp; 
    1011 
    1112my $Curses; 
     
    1415    _start => sub { 
    1516        $_[HEAP]->{irc} = 
    16             POE::Component::IRC->spawn(); 
     17            POE::Component::IRC->spawn( alias => "IRC" ); 
    1718 
    1819        # Even if we dont use all events, it shouldn't create an error since 
     
    2223        # efficiency *really* isn't a big issue here. 
    2324 
    24         $_[KERNEL]->yield(register => "all"); 
     25        $_[KERNEL]->post(IRC => register => "all"); 
    2526 
    2627    }, 
    2728 
    2829    irc_connected => sub { 
    29         printf "Connected to %s", $_[SENDER]->get_heap->server_name(); 
     30        my $server_name = $_[ SENDER ]->get_heap->server_name; 
     31        unless (defined $server_name) { 
     32            print "Connected..."; 
     33        } 
     34        else { 
     35            print "Connected to %s", $server_name; 
     36        } 
    3037    }, 
    3138 
     
    104111select CURWIN; 
    105112 
     113 
     114open LOG, ">>", "cuirc-debug.log"; 
     115 
     116# Try to put errors in the window... 
     117$SIG{"__DIE__"} = sub { 
     118    print LOG $_[0]; 
     119}; 
     120$SIG{"__WARN__"} = sub { 
     121    print LOG $_[0]; 
     122}; 
     123 
    106124print "Welcome to Curses::UI::POE's IRC example"; 
    107125 
     
    116134use POSIX qw( strftime cuserid ); 
    117135use Curses; 
     136use Carp qw( carp ); 
    118137 
    119138my @nicks; 
     
    164183    my $object = shift; 
    165184    my ($viewer, $curses) = @$object{qw( -viewer -curses )}; 
     185 
     186    # XXX Hack: Just ignore bunk requests for now... 
     187    if (grep !defined $_, @_) { 
     188        carp "Attempt to print undefined value"; 
     189    } 
    166190 
    167191    push @Channel, sprintf shift, @_; 
     
    272296            printf "Sending Connect EVENT for %s:%s", $server, $port; 
    273297 
    274             $_[KERNEL]->yield 
    275                 ( connect => { 
     298            $poe_kernel->post 
     299                ( IRC => connect => { 
    276300                    Nick        => cuserid, 
    277301                    Server      => $server, 
     
    291315            else { 
    292316                $Channel{$Join} = 1; 
    293                 $_[KERNEL]->yield( join => $Join ); 
     317                $poe_kernel->post( IRC => join => $Join ); 
    294318                $CurrentChannel = $Join; 
    295319            } 
    296320        }, 
    297321 
    298         nick => sub { $_[KERNEL]->yield( nick => $_[1] ) }, 
    299         kick => sub { $_[KERNEL]->yield( kick => $_[1..$#_] ) }, 
    300         msg  => sub { $_[KERNEL]->yield( privmsg => $_[1..$#_] ) }, 
     322        nick => sub { $poe_kernel->post( IRC => nick => $_[1] ) }, 
     323        kick => sub { $poe_kernel->post( IRC => kick => $_[1..$#_] ) }, 
     324        msg  => sub { $poe_kernel->post( IRC => privmsg => $_[1..$#_] ) }, 
    301325         
    302326        quote => sub { 
    303             $_[KERNEL]->yield( sl => join " ", @_[1..$#_] ); 
     327            $poe_kernel->post( IRC => sl => join " ", @_[1..$#_] ); 
    304328        }, 
    305329 
    306330        quit => sub { 
    307             $_[KERNEL]->yield( quit => join " ", @_[1..$#_] ); 
     331            $poe_kernel->post( IRC => quit => join " ", @_[1..$#_] ); 
    308332 
    309333            print "Have a nice day"; 
     
    332356        else { 
    333357            if ($CurrentChannel) { 
    334                 $_[KERNEL]->yield( privmsg => $CurrentChannel, $line ); 
     358                $poe_kernel->post( IRC => privmsg => $CurrentChannel, $line ); 
    335359                print "> $line"; 
    336360            }