ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-IRC3/samples/netirc3
Revision: 1.1
Committed: Sun Jul 16 02:41:37 2006 UTC (20 years, 2 months ago) by elmex
Branch: MAIN
Log Message:
some major change on the module layout

File Contents

# User Rev Content
1 elmex 1.1 #!/usr/bin/perl
2     use strict;
3     use Net::IRC3;
4     $Net::IRC3::Client::DEBUG = 1;
5    
6     my $c = AnyEvent->condvar;
7    
8     my $irc = Net::IRC3->new;
9    
10     my $con = $irc->connect_server ("localhost", 6667);
11    
12     my ($nick, $user, $real) = qw/BinDepp BinDepp depp/;
13    
14     # send IRC registration
15     $con->send_msg (undef, "NICK", undef, $nick);
16     $con->send_msg (undef, "USER", $real || $nick, $user || $nick, "*", "0");
17    
18     $con->reg_cb (irc_001 => sub {
19     my ($con) = @_;
20     $con->event ('welcome'); # emit a self defined event
21     1;
22     });
23    
24     # display all irc messages for debugging
25     $con->reg_cb ('irc_*' => sub { warn "DEBUG: " . join ('|', %{$_[1]}) . "\n"; 1; });
26    
27     # we register now a callback on our self defined event
28     $con->reg_cb (welcome => sub {
29     my ($con) = @_;
30     $con->send_msg (undef, "PRIVMSG", "Hi!!!", "elmex_");
31     1;
32     });
33    
34     my $t;
35     $t = AnyEvent->timer (after => 2, cb => sub {
36     $con->disconnect_server ("Timeout exceeded");
37     undef $t;
38     });
39    
40     # lets
41     $con->reg_cb (
42     disconnect => sub {
43     warn "Oh, got a disconnect: $_[1]\n";
44     1;
45     }
46     );
47    
48     $c->wait;