NAME
POE::Component::Server::IRC::Common - provides a set of common functions for the POE::Component::Server::IRC suite.
SYNOPSIS
use strict;
use warnings;
use POE::Component::Server::IRC::Common qw( :ALL );
my $nickname = '^Lame|BOT[moo]';
my $uppercase_nick = u_irc( $nickname );
my $lowercase_nick = l_irc( $nickname );
my $mode_line = 'ov+b-i Bob sue stalin*!*@*';
my $hashref = parse_mode_line( $mode_line );
my $banmask = 'stalin*';
$full_banmask = parse_ban_mask( $banmask );
if ( matches_mask( $full_banmask, 'stalin!joe@kremlin.ru' ) ) {
print "EEK!";
}
my $results_hashref = matches_mask_array( \@masks, \@items_to_match_against );
my $mode_change = gen_mode_change( 'abcde', 'befmZ' );
my $passwd = mkpasswd( 'moocow' );
DESCRIPTION
POE::Component::IRC::Common provides a set of common functions for the POE::Component::Server::IRC suite. There are included functions for uppercase and lowercase nicknames/channelnames and for parsing mode lines and ban masks.
FUNCTIONS
- u_irc
-
Takes one mandatory parameter, a string to convert to IRC uppercase, and one optional parameter, the casemapping of the ircd ( which can be 'rfc1459', 'strict-rfc1459' or 'ascii'. Default is 'rfc1459' ). Returns the IRC uppercase equivalent of the passed string.
- l_irc
-
Takes one mandatory parameter, a string to convert to IRC lowercase, and one optional parameter, the casemapping of the ircd ( which can be 'rfc1459', 'strict-rfc1459' or 'ascii'. Default is 'rfc1459' ). Returns the IRC lowercase equivalent of the passed string.
- parse_mode_line
-
Takes a list representing an IRC mode line. Returns a hashref. If the modeline couldn't be parsed the hashref will be empty. On success the following keys will be available in the hashref:
'modes', an arrayref of normalised modes; 'args', an arrayref of applicable arguments to the modes;
Example:
my $hashref = parse_mode_line( 'ov+b-i', 'Bob', 'sue', 'stalin*!*@*' ); $hashref will be { 'modes' => [ '+o', '+v', '+b', '-i' ], 'args' => [ 'Bob', 'sue', 'stalin*!*@*' ], };
- parse_ban_mask
-
Takes one parameter, a string representing an IRC ban mask. Returns a normalised full banmask.
Example:
$fullbanmask = parse_ban_mask( 'stalin*' ); $fullbanmask will be 'stalin*!*@*';
- matches_mask
-
Takes two parameters, a string representing an IRC mask ( it'll be processed with parse_ban_mask() to ensure that it is normalised ) and something to match against the IRC mask, such as a nick!user@hostname string. Returns 1 if they match, 0 otherwise. Returns undef if parameters are missing. Optionally, one may pass the casemapping ( see u_irc() ), as this function ises u_irc() internally.
- matches_mask_array
-
Takes two array references, the first being a list of strings representing IRC mask, the second a list of somethings to test against the masks. Returns an empty hashref if there are no matches. Matches are returned are arrayrefs keyed on the mask that they matched.
- gen_mode_change
-
Takes two arguments, being a strings representing a set of IRC user modes before and after a change. Returns a string representing what changed.
my $mode_change = gen_mode_change( 'abcde', 'befmZ' ); $mode_change is now '-acd+fmZ'
- unparse_mode_line
-
Takes one argument a string representing a number of mode changes. Returns a condensed version of the changes.
my $mode_line = unparse_mode_line('+o+o+o-v+v'); $mode_line is now '+ooo-v+v'
- validate_chan_name
-
Takes one argument a channel name to validate. Returns true or false if the channel name is valid or not.
- validate_nick_name
-
Takes one argument a nickname to validate. Returns true or false if the nickname is valid or not.
- parse_user
-
Takes one parameter, a string representing a user in the form nick!user@hostname. In a scalar context it returns just the nickname. In a list context it returns a list consisting of the nick, user and hostname, respectively.
- mkpasswd
-
Takes one mandatory argument a plain string to 'encrypt'. If no further options are specified it uses
crypt
to generate the password. Specifying 'md5' option uses Crypt::PasswdMD5'sunix_md5_crypt
function to generate the password. Specifying 'apache' uses Crypt::PasswdMD5'sapache_md5_crypt
function to generate the password.my $passwd = mkpasswd( 'moocow' ); # vanilla crypt() my $passwd = mkpasswd( 'moocow', md5 => 1 ) # unix_md5_crypt() my $passwd = mkpasswd( 'moocow', apache => 1 ) # apache_md5_crypt()
- chkpasswd
-
Takes two mandatory arguments, a password string and something to check that password against. The function first tries md5 comparisons ( UNIX and Apache ), then
crypt
and finally plain-text password check.
AUTHOR
Chris 'BinGOs' Williams