Why not adopt me?
NAME
IRC::Toolkit::Modes - IRC mode parsing utilities
SYNOPSIS
use IRC::Toolkit::Modes;
my $array = mode_to_array( $mode_string );
my $hash = mode_to_hash( $mode_string );
DESCRIPTION
Utility functions for parsing IRC mode strings.
mode_to_array
my $array = mode_to_array(
## Mode change string with or without params, e.g. '+kl-t'
$mode_string,
## Modes that always have a param:
param_always => ARRAY,
## Modes that only have a param when set:
param_set => ARRAY,
## Respective params for modes specified above
## (or can be specified as part of mode string)
params => ARRAY,
);
Given a mode string and some options, return an ARRAY of ARRAYs containing parsed mode changes.
The structure looks like:
[
[ FLAG, MODE, MAYBE_PARAM ],
[ . . . ],
]
For example:
mode_to_array( '+kl-t',
params => [ 'key', 10 ],
param_always => [ split //, 'bkov' ],
param_set => [ 'l' ],
);
## Result:
[
[ '+', 'k', 'key' ],
[ '+', 'l', 10 ],
[ '-', 't' ],
],
(If the mode string contains (space-delimited) parameters, they are given precedence ahead of the optional 'params' ARRAY.)
mode_to_hash
Takes the same parameters as "mode_to_array" -- this is just a way to inflate the ARRAY to a hash.
Given a mode string and some options, return a HASH with the keys add and del.
add and del are HASHes mapping mode characters to either a simple boolean true value or an ARRAY whose only element is the mode's parameters, e.g.:
mode_to_hash( '+kl-t',
params => [ 'key', 10 ],
param_always => [ split //, 'bkov' ],
param_set => [ 'l' ],
);
## Result:
{
add => {
'l' => [ 10 ],
'k' => [ 'key' ],
},
del => {
't' => 1,
},
}
This is a 'lossy' approach that won't deal well with multiple conflicting mode changes in a single line; it is useful for internal mode examination, but "mode_to_array" should generally be preferred for IRC-directed mode handling.
AUTHOR
Jon Portnoy <avenj@cobaltirc.org>