ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-IRC3/samples/netirc3
Revision: 1.3
Committed: Mon Jul 17 15:09:20 2006 UTC (20 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.2: +3 -3 lines
Log Message:
simplyfied the whole module a bit.

File Contents

# User Rev Content
1 elmex 1.1 #!/usr/bin/perl
2     use strict;
3 elmex 1.3 use Net::IRC3::Connection;
4 elmex 1.1 $Net::IRC3::Client::DEBUG = 1;
5    
6     my $c = AnyEvent->condvar;
7    
8 elmex 1.3 my $con = Net::IRC3::Connection->new;
9 elmex 1.1
10 elmex 1.3 $con->connect ("irc.plan9.de", 6667);
11 elmex 1.1
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 elmex 1.2 $con->send_msg (undef, "PRIVMSG", "Hi!!!", "elmex");
31 elmex 1.1 1;
32     });
33    
34     my $t;
35     $t = AnyEvent->timer (after => 2, cb => sub {
36 elmex 1.2 $con->disconnect ("Timeout exceeded");
37 elmex 1.1 undef $t;
38     });
39    
40     # lets
41     $con->reg_cb (
42     disconnect => sub {
43 elmex 1.2 warn "Oh, got a disconnect: $_[1], exiting...\n";
44     exit 0;
45 elmex 1.1 1;
46     }
47     );
48    
49     $c->wait;