AnyEvent-IRC
view release on metacpan or search on metacpan
lib/AnyEvent/IRC/Connection.pm view on Meta::CPAN
Returns the hash reference stored in the C<heap> member, that is local to this
connection object that lets you store any information you want.
=cut
sub heap {
my ($self) = @_;
return $self->{heap};
}
=item $con->send_raw ($ircline)
This method sends C<$ircline> straight to the server without any
further processing done.
=cut
sub send_raw {
my ($self, $ircline) = @_;
return unless $self->{socket};
$self->{socket}->push_write ($ircline . "\015\012");
}
=item $con->send_msg ($command, @params)
This function sends a message to the server. C<@ircmsg> is the argument list
for C<AnyEvent::IRC::Util::mk_msg (undef, $command, @params)>.
=cut
sub send_msg {
my ($self, @msg) = @_;
$self->event (send => [undef, @msg]);
$self->event (sent => undef, @msg);
}
sub _feed_irc_data {
my ($self, $line) = @_;
#d# warn "LINE:[" . $line . "][".length ($line)."]";
my $m = parse_irc_msg ($line);
#d# warn "MESSAGE{$m->{params}->[-1]}[".(length $m->{params}->[-1])."]\n";
#d# warn "HEX:" . join ('', map { sprintf "%2.2x", ord ($_) } split //, $line)
#d# . "\n";
$self->event (read => $m);
$self->event ('irc_*' => $m);
$self->event ('irc_' . (lc $m->{command}), $m);
}
=back
=head2 EVENTS
Following events are emitted by this module and shouldn't be emitted
from a module user call to C<event>. See also the documents L<Object::Event> about
registering event callbacks.
=over 4
=item connect => $error
This event is generated when the socket was successfully connected
or an error occurred while connecting. The error is given as second
argument (C<$error>) to the callback then.
=item disconnect => $reason
This event will be generated if the connection is somehow terminated.
It will also be emitted when C<disconnect> is called.
The second argument to the callback is C<$reason>, a string that contains
a clue about why the connection terminated.
If you want to reestablish a connection, call C<connect> again.
=item send => $ircmsg
Emitted when a message is about to be sent. C<$ircmsg> is an array reference
to the arguments of C<mk_msg> (see L<AnyEvent::IRC::Util>). You
may modify the array reference to change the message or even intercept it
completely by calling C<stop_event> (see L<Object::Event> API):
$con->reg_cb (
send => sub {
my ($con, $ircmsg) = @_;
if ($ircmsg->[1] eq 'NOTICE') {
$con->stop_event; # prevent any notices from being sent.
} elsif ($ircmsg->[1] eq 'PRIVMSG') {
$ircmsg->[-1] =~ s/sex/XXX/i; # censor any outgoing private messages.
}
}
);
=item sent => @ircmsg
Emitted when a message (C<@ircmsg>) was sent to the server.
C<@ircmsg> are the arguments to C<AnyEvent::IRC::Util::mk_msg>.
=item irc_* => $msg
=item irc_<lowercase command> => $msg
=item read => $msg
Emitted when a message (C<$msg>) was read from the server.
C<$msg> is the hash reference returned by C<AnyEvent::IRC::Util::parse_irc_msg>;
Note: '<lowercase command>' stands for the command of the message in
(ASCII) lower case.
=item buffer_empty
This event is emitted when the write buffer of the underlying connection
is empty and all data has been given to the kernel. See also C<samples/notify>
about a usage example.
( run in 0.945 second using v1.01-cache-2.11-cpan-39bf76dae61 )