IRC::Toolkit::Modes - IRC mode parsing utilities
use IRC::Toolkit::Modes; my $array = mode_to_array( $mode_string ); my $hash = mode_to_hash( $mode_string );
Utility functions for parsing IRC mode strings.
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.)
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.
Jon Portnoy <avenj@cobaltirc.org>
To install IRC::Toolkit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IRC::Toolkit
CPAN shell
perl -MCPAN -e shell install IRC::Toolkit
For more information on module installation, please visit the detailed CPAN module installation guide.