AnyEvent-IRC
view release on metacpan or search on metacpan
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
use common::sense;
use Scalar::Util qw/weaken/;
use Encode;
use AnyEvent::Socket;
use AnyEvent::Handle;
use AnyEvent::IRC::Util
qw/prefix_nick decode_ctcp split_prefix
is_nick_prefix join_prefix encode_ctcp
split_unicode_string mk_msg/;
use base AnyEvent::IRC::Connection::;
=head1 NAME
AnyEvent::IRC::Client - A highlevel IRC connection
=head1 SYNOPSIS
use AnyEvent;
lib/AnyEvent/IRC/Client.pm view on Meta::CPAN
my $max_len = 500; # give 10 bytes extra margin
my $line_len = $max_len - $init_len;
# split up the multiple lines in the message:
my @lines = split /\n/, $msg;
# splitup long lines into multiple ones:
@lines =
map split_unicode_string ($encoding, $_, $line_len), @lines;
# send lines line-by-line:
for my $line (@lines) {
my $smsg = encode ($encoding, $line);
if ($ctcp ne '') {
$smsg = encode_ctcp ([$ctcp, $smsg])
}
$self->send_srv ($cmd => @params, $smsg);
lib/AnyEvent/IRC/Util.pm view on Meta::CPAN
package AnyEvent::IRC::Util;
use common::sense;
use Exporter;
use Encode;
our @ISA = qw/Exporter/;
our @EXPORT_OK =
qw(mk_msg parse_irc_msg split_prefix prefix_nick
decode_ctcp encode_ctcp filter_ctcp_text_attr prefix_user prefix_host
rfc_code_to_name filter_colors is_nick_prefix join_prefix
split_unicode_string);
=head1 NAME
AnyEvent::IRC::Util - Common utilities that help with IRC protocol handling
=head1 SYNOPSIS
use AnyEvent::IRC::Util qw/parse_irc_msg mk_msg/;
my $msgdata = mk_msg (undef, PRIVMSG => "mcmanus", "my hands glow!");
lib/AnyEvent/IRC/Util.pm view on Meta::CPAN
'492' => 'ERR_NOSERVICEHOST',
'501' => 'ERR_UMODEUNKNOWNFLAG',
'502' => 'ERR_USERSDONTMATCH',
);
sub rfc_code_to_name {
my ($code) = @_;
return $RFC_NUMCODE_MAP{$code} || $code;
}
=item my (@lines) = split_unicode_string ($encoding, $string, $maxlinebytes)
This function splits up C<$string> into multiple C<@lines> which are
not longer than C<$maxlinebytes> bytes. Encoding can be given in C<$encoding>.
(eg. 'utf-8'). But the output will not be encoded.
This function takes care that your characters are not garbled.
=cut
sub split_unicode_string {
my ($enc, $str, $maxlen) = @_;
return $str unless length (encode ($enc, $str)) > $maxlen;
my $cur_out = '';
my @lines;
while (length ($str) > 0) {
while (length (encode ($enc, $cur_out)) <= $maxlen
( run in 0.443 second using v1.01-cache-2.11-cpan-88abd93f124 )