1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
19 package NDIRC::CommonStates;
27 # We registered for all events, this will produce some debug info.
29 my ($event, $args) = @_[ARG0 .. $#_];
30 my @output = ( "$event: " );
32 for my $arg (@$args) {
33 if ( ref $arg eq 'ARRAY' ) {
34 push( @output, '[' . join(', ', @$arg ) . ']' );
37 push ( @output, "'$arg'" );
40 print join ' ', @output, "\n";
45 my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION];
47 # retrieve our component's object from the heap where we stashed it
48 my $irc = $heap->{irc};
49 $kernel->sig( DIE => 'sig_DIE' );
50 $kernel->sig( USR1 => 'sig_usr1' );
51 $kernel->sig( USR2 => 'sig_usr2' );
52 $kernel->sig( INT => 'signal_handler' );
54 $heap->{connector} = POE::Component::IRC::Plugin::Connector->new();
55 $irc->plugin_add( 'Connector' => $heap->{connector} );
57 $kernel->signal($session => 'USR2');
59 $irc->yield( register => 'all' );
60 $irc->yield( connect => { } );
62 $kernel->delay( refresh => 60 );
67 my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
68 say "DIED!!!!!!!!!!!!!!";
70 # $ex is the exception hash
71 warn "$$: error in event: $ex->{error_str}";
72 $kernel->sig_handled();
74 # Send the signal to session that sent the original event.
75 #if( $ex->{source_session} ne $_[SESSION] ) {
76 #$kernel->signal( $ex->{source_session}, 'DIE', $sig, $ex );
81 my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
82 print "First session caught SIG$signal_name\n";
84 $heap->{irc}->yield(privmsg => '#testarlite', "SIGNAL $signal_name!");
88 $heap->{irc}->yield(quit => 'Bye!');
89 $kernel->sig_handled();
92 #$kernel->sig_handled();
95 sub irc_disconnected {
96 my ($sender,$heap) = @_[SENDER,HEAP];
102 my ($sender,$heap) = @_[SENDER,HEAP];
104 # Since this is an irc_* event, we can get the component's object by
105 # accessing the heap of the sender. Then we register and connect to the
107 my $irc = $sender->get_heap();
109 print "Connected to ", $irc->server_name(), "\n";
111 # we join our channels
112 $irc->yield( join => $_ ) for grep /^#/, keys %{$heap->{disp}->channels};
117 my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
118 my $irc = $sender->get_heap();
120 $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$heap->{disp}->channels}