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