Net::IRC3::Util - Common utilities that help with IRC protocol handling


   use Net::IRC3 qw/parse_irc_msg mk_msg/;

   my $msgdata = mk_msg (undef, PRIVMSG => "my hands glow!", "mcmanus");


These are some utility functions that might come in handy when handling the IRC protocol.

You can export these with eg.:

   use Net::IRC3 qw/parse_irc_msg/;
parse_irc_msg ($ircline)

This method parses the $ircline, which is one line of the IRC protocol without the trailing "\015\012".

It returns a hash which has the following entrys:


The message prefix.


The IRC command.


The parameters to the IRC command in a array reference, this includes the trailing parameter (the one after the ':' or the 14th parameter).


This is set if there was a trailing parameter (the one after the ':' or the 14th parameter).

mk_msg ($prefix, $command, $trailing, @params)

This function assembles a IRC message. The generated message will look like (pseudo code!)

   :<prefix> <command> <params> :<trail>

Please refer to RFC 2812 how IRC messages normally look like.

The prefix and the trailing string will be omitted if they are undef.


   mk_msg (undef, "PRIVMSG", "you suck!", "magnus");
   # will return: "PRIVMSG magnus :you suck!\015\012"

   mk_msg (undef, "JOIN", undef, "#test");
   # will return: "JOIN #test\015\012"
decode_ctcp ($trailing)

This function decodes the $trailing part of an IRC message. It will first unescape the lower layer, extract CTCP messages and then return a list with two elements: the line without the ctcp messages and an array reference which contains array references of CTCP messages. Those CTCP message array references will have the CTCP message tag as first element (eg. "VERSION") and the rest of the CTCP message as the second element.

encode_ctcp (@msg)

This function encodes a ctcp message for the trailing part of a NOTICE or PRIVMSG. @msg is an array of strings or array references. If an array reference occurs in the @msg array it's first element will be interpreted as CTCP TAG (eg. one of PING, VERSION, .. whatever) the rest of the array ref will be appended to the tag and seperated by spaces.

All parts of the message will be contatenated and lowlevel quoted. That means you can embed _any_ character from 0 to 255 in this message (thats what the lowlevel quoting allows).

filter_colors ($line)

This function will filter out any mIRC colors and (most) ansi escape sequences. Unfortunately the mIRC color coding will destroy improper colored numbers. So this function may destroy the message in some occasions a bit.

split_prefix ($prefix)

This function splits an IRC user prefix as described by RFC 2817 into the three parts: nickname, user and host. Which will be returned as a list with that order.

$prefix can also be a hash like it is returned by parse_irc_msg.

prefix_nick ($prefix)

A shortcut to extract the nickname from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

prefix_user ($prefix)

A shortcut to extract the username from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

prefix_host ($prefix)

A shortcut to extract the hostname from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

rfc_code_to_name ($code)

This function is a interface to the internal mapping or numeric replies to the reply name in RFC 2812 (which you may also consult).

$code is returned if no name for $code exists (as some server may extended the protocol).


Robin Redeker, <>


Internet Relay Chat Client To Client Protocol from February 2, 1997

RFC 2812 - Internet Relay Chat: Client Protocol


Copyright 2006 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.