AnyEvent-IRC
view release on metacpan or search on metacpan
$c->wait;
Using the more sophisticated AnyEvent::IRC::Client:
use AnyEvent;
use AnyEvent::IRC::Client;
my $c = AnyEvent->condvar;
my $timer;
my $con = new AnyEvent::IRC::Client;
$con->reg_cb (registered => sub { print "I'm in!\n"; });
$con->reg_cb (disconnect => sub { print "I'm out!\n"; $c->broadcast });
$con->reg_cb (
sent => sub {
my ($con) = @_;
if ($_[2] eq 'PRIVMSG') {
print "Sent message!\n";
$timer = AnyEvent->timer (
after => 1,
cb => sub {
undef $timer;
$con->disconnect ('done')
}
);
}
}
);
$con->send_srv (
PRIVMSG => 'elmex',
"Hello there I'm the cool AnyEvent::IRC test script!"
lib/AnyEvent/IRC.pm view on Meta::CPAN
$c->wait;
Using the more sophisticated L<AnyEvent::IRC::Client>:
use AnyEvent;
use AnyEvent::IRC::Client;
my $c = AnyEvent->condvar;
my $timer;
my $con = new AnyEvent::IRC::Client;
$con->reg_cb (registered => sub { print "I'm in!\n"; });
$con->reg_cb (disconnect => sub { print "I'm out!\n"; $c->broadcast });
$con->reg_cb (
sent => sub {
my ($con) = @_;
if ($_[2] eq 'PRIVMSG') {
print "Sent message!\n";
$timer = AnyEvent->timer (
after => 1,
cb => sub {
undef $timer;
$con->disconnect ('done')
}
);
}
}
);
$con->send_srv (
PRIVMSG => 'elmex',
"Hello there I'm the cool AnyEvent::IRC test script!"
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
AnyEvent::IRC::Client - A highlevel IRC connection
=head1 SYNOPSIS
use AnyEvent;
use AnyEvent::IRC::Client;
my $c = AnyEvent->condvar;
my $timer;
my $con = new AnyEvent::IRC::Client;
$con->reg_cb (connect => sub {
my ($con, $err) = @_;
if (defined $err) {
warn "connect error: $err\n";
return;
}
});
$con->reg_cb (registered => sub { print "I'm in!\n"; });
$con->reg_cb (disconnect => sub { print "I'm out!\n"; $c->broadcast });
$con->reg_cb (
sent => sub {
my ($con) = @_;
if ($_[2] eq 'PRIVMSG') {
print "Sent message!\n";
$timer = AnyEvent->timer (
after => 1,
cb => sub {
undef $timer;
$con->disconnect ('done')
}
);
}
}
);
$con->send_srv (
PRIVMSG => 'elmex',
"Hello there I'm the cool AnyEvent::IRC test script!"
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
=over 4
=item $cl = AnyEvent::IRC::Client->new (%args)
This is the constructor of a L<AnyEvent::IRC::Client> object,
which stands logically for a client connected to ONE IRC server.
You can reuse it and call C<connect> once it disconnected.
B<NOTE:> You are free to use the hash member C<heap> to store any associated
data with this object. For example retry timers or anything else.
C<%args> may contain these options:
=over 4
=item send_initial_whois => $bool
If this option is enabled an initial C<WHOIS> command is sent to your own
NICKNAME to determine your own I<ident>. See also the method C<nick_ident>.
This is necessary to ensure that the information about your own nickname
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
irc_437 => \&change_nick_login_cb,
irc_433 => \&change_nick_login_cb,
);
delete $self->{away_status};
delete $self->{dcc};
delete $self->{dcc_id};
delete $self->{_tmp_namereply};
delete $self->{last_pong_recv};
delete $self->{last_ping_sent};
delete $self->{_ping_timer};
delete $self->{con_queue};
delete $self->{chan_queue};
delete $self->{registered};
delete $self->{idents};
delete $self->{nick};
delete $self->{user};
delete $self->{real};
delete $self->{server_pass};
delete $self->{register_cb_guard};
}
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
=cut
sub enable_ping {
my ($self, $int, $cb) = @_;
$self->{last_pong_recv} = 0;
$self->{last_ping_sent} = time;
$self->send_srv (PING => "AnyEvent::IRC");
$self->{_ping_timer} =
AE::timer $int, 0, sub {
if ($self->{last_pong_recv} < $self->{last_ping_sent}) {
delete $self->{_ping_timer};
if ($cb) {
$cb->($self);
} else {
$self->disconnect ("Server timeout");
}
} else {
$self->enable_ping ($int, $cb);
}
};
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
$dest = $self->lower_case ($dest);
$type = lc $type;
my $id = ++$self->{dcc_id};
my $dcc = $self->{dcc}->{$id} = { id => $id, type => $type, dest => $dest };
weaken $dcc;
weaken $self;
$dcc->{timeout} = AnyEvent->timer (after => $timeout || 5 * 60, cb => sub {
$self->dcc_disconnect ($id, "TIMEOUT") if $self;
});
$dcc->{listener} = tcp_server undef, $local_port, sub {
my ($fh, $h, $p) = @_;
return unless $dcc && $self;
$dcc->{handle} = AnyEvent::Handle->new (
fh => $fh,
on_eof => sub {
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
sub dcc_accept {
my ($self, $id, $timeout) = @_;
my $dcc = $self->{dcc}->{$id}
or return;
weaken $dcc;
weaken $self;
$dcc->{timeout} = AnyEvent->timer (after => $timeout || 5 * 60, cb => sub {
$self->dcc_disconnect ($id, "CONNECT TIMEOUT") if $self;
});
$dcc->{connect} = tcp_connect $dcc->{ip}, $dcc->{port}, sub {
my ($fh) = @_;
return unless $dcc && $self;
delete $dcc->{timeout};
delete $dcc->{connect};
lib/AnyEvent/IRC/Connection.pm view on Meta::CPAN
=head2 METHODS
=over 4
=item $con = AnyEvent::IRC::Connection->new ()
This constructor doesn't take any arguments.
B<NOTE:> You are free to use the hash member C<heap> (which contains a hash) to
store any associated data with this object. For example retry timers or
anything else.
You can also access that member via the C<heap> method.
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
samples/anyeventirc view on Meta::CPAN
});
# we register now a callback on our self defined event
$con->reg_cb (welcome => sub {
my ($con) = @_;
$con->send_msg ("PRIVMSG", "elmex", "Hi!!!");
});
# Disconnect after 10 seconds:
my $t;
$t = AnyEvent->timer (after => 10, cb => sub {
$con->disconnect ("Timeout exceeded");
undef $t;
});
# lets register connect and disconnect handlers.
$con->reg_cb (
connect => sub {
my ($con, $err) = @_;
if (defined $err) {
( run in 1.126 second using v1.01-cache-2.11-cpan-49f99fa48dc )