ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-IRC3/samples/netirc3
Revision: 1.2
Committed: Sun Jul 16 11:11:17 2006 UTC (20 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.1: +5 -4 lines
Log Message:
version 0.2. added documentation and refactored code a bit.

File Contents

# Content
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 ("irc.plan9.de", 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 ("Timeout exceeded");
37 undef $t;
38 });
39
40 # lets
41 $con->reg_cb (
42 disconnect => sub {
43 warn "Oh, got a disconnect: $_[1], exiting...\n";
44 exit 0;
45 1;
46 }
47 );
48
49 $c->wait;