POE::Component::IRC::Plugin::CSS::SelectorTools - couple of CSS selector tools for IRC bots


    use strict;
    use warnings;

    use POE qw(Component::IRC  Component::IRC::Plugin::CSS::SelectorTools);

    my $irc = POE::Component::IRC->spawn(
        nick        => 'CSSToolsBot',
        server      => '',
        port        => 6667,
        ircname     => 'CSSToolsBot',
        plugin_debug => 1,

        package_states => [
            main => [ qw(_start  irc_001 ) ],


    sub _start {
        $irc->yield( register => 'all' );

            'CSSSelectorTools' =>

        $irc->yield( connect => {} );

    sub irc_001 {
        $irc->yield( join => '#zofbot' );

    <Zoffix> CSSToolsBot, sel link #foo div #beer .bas a
    <CSSToolsBot> #foo div #beer .bas a:link, #foo div #beer .bas a:visited, #foo div #beer .bas a:hover, #foo div #beer .bas a:active

    <Zoffix> CSSToolsBot, sel multi [#foo] bar, beer, bez, p, div, a
    <CSSToolsBot> #foo bar, #foo beer, #foo bez, #foo p, #foo div, #foo a


This module is a POE::Component::IRC plugin which uses POE::Component::IRC::Plugin for its base. It provides basic CSS selector making tools. So far there are only two tools, the "link rule maker" and "multi-selector maker". If you have any suggestions for other tools feel free to let me know.

It accepts input from public channel events, /notice messages as well as /msg (private messages); although that can be configured at will.

The "commands" and their functionality is described under triggers sub section of CONSTRUCTOR section.



    # plain and simple
        'CSSSelectorTools' =>

    # juicy flavor
        'CSSSelectorTools' =>
                auto             => 1,
                response_event   => 'irc_css_selector_tools',
                banned           => [ qr/aol\.com$/i ],
                root             => [ qr/$/i ],
                addressed        => 1,
                line_length      => 350,
                max_length       => 695,
                trigger          => qr/^sel(?:ector)?\s+(?=\S+)/i,
                ztriggers        => {
                    link    => qr/^link\s+(?=\S+)/i,
                    multi   => qr/^multi\s+(?=\S+)/i,
                listen_for_input => [ qw(public notice privmsg) ],
                eat              => 1,
                debug            => 0,

The new() method constructs and returns a new POE::Component::IRC::Plugin::CSS::SelectorTools object suitable to be fed to POE::Component::IRC's plugin_add method. The constructor takes a few arguments, but all of them are optional. Note: you can change all these arguments dynamically by accessing your plugin object as a hashref; in other words, if you want to ban a user on the fly you can do: push @{ $your_plugin_object->{banned} }, qr/\Quser!; . The possible arguments/values are as follows:


    ->new( auto => 0 );

Optional. Takes either true or false values, specifies whether or not the plugin should auto respond to requests. When the auto argument is set to a true value plugin will respond to the requesting person with the results automatically. When the auto argument is set to a false value plugin will not respond and you will have to listen to the events emitted by the plugin to retrieve the results (see EMITTED EVENTS section and response_event argument for details). Defaults to: 1.


    ->new( response_event => 'event_name_to_receive_results' );

Optional. Takes a scalar string specifying the name of the event to emit when the results of the request are ready. See EMITTED EVENTS section for more information. Defaults to: irc_css_selector_tools


    ->new( banned => [ qr/aol\.com$/i ] );

Optional. Takes an arrayref of regexes as a value. If the usermask of the person (or thing) making the request matches any of the regexes listed in the banned arrayref, plugin will ignore the request. Defaults to: [] (no bans are set).


    ->new( root => [ qr/\\E$/i ] );

Optional. As opposed to banned argument, the root argument allows access only to people whose usermasks match any of the regexen you specify in the arrayref the argument takes as a value. By default: it is not specified. Note: as opposed to banned specifying an empty arrayref to root argument will restrict access to everyone.


    { line_length => 350, }

Optional. Depending on the input plugin's output may be quite verbose. If the length of the output is longer than line_length characters it will be split into several messages (to avoid disconnects or content cut offs). Defaults to: 350


    { max_length => 695, }

Optional. Same as line_length argument except max_length specifies the maximum length of the output plugin is allowed to emit. If length of the output is longer than max_length the excess will be cut off and ... will be appended to indicate "overflow". Defaults to: 695


    ->new( trigger => qr/^sel(?:ector)?\s+(?=\S+)/i );

Optional. Takes a regex as an argument. Messages matching this regex will be considered as requests. See also addressed option below which is enabled by default. Note: the trigger will be removed from the message, therefore make sure your trigger doesn't match the actual data that needs to be processed. Defaults to: qr/^sel(?:ector)?\s+(?=\S+)/i


    ->new( triggers => {
                    link    => qr/^link\s+(?=\S+)/i,
                    multi   => qr/^multi\s+(?=\S+)/i,

Optional. The ztriggers (not the plural form with "z" at the front) argument takes a hashref as a value. The keys of that hashref are command names and values are regex (qr//) which represent the trigger for the corresponding command. Same as with trigger, the individual command ztriggers will be removed from input so make sure they don't match the actual data to be processed. If none of ztriggers regexes match plugin will inform the user that the used command is invalid. Currently plugin provides only two commands:

    { link => qr/^link\s+(?=\S+)/i, }

    <Zoffix> CSSToolsBot, sel link #foo div #beer .bas a
    <CSSToolsBot> #foo div #beer .bas a:link, #foo div #beer .bas
                  a:visited, #foo div #beer .bas a:hover, #foo div #beer
                  .bas a:active

The link command is a "link selector" maker. Say you want to style #foo bar beer a links but too lazy to type out the :hover and the rest (or what is more importantly - don't remember the correct order). Just give the plugin the selector for your link and it will do everything itself. Trigger defaults to: qr/^link\s+(?=\S+)/i


    { multi   => qr/^multi\s+(?=\S+)/i, }

    <Zoffix> CSSToolsBot, sel multi [#foo] bar, beer, bez, p, div, a
    <CSSToolsBot> #foo bar, #foo beer, #foo bez, #foo p, #foo div, #foo a

The multi command is a "repeater"; as useless as it is it helps to use this one when all those people ask whether or not selector #foo bar, beer, bez selects beer and bez under #foo. Trigger defaults to: qr/^multi\s+(?=\S+)/i


    ->new( addressed => 1 );

Optional. Takes either true or false values. When set to a true value all the public messages must be addressed to the bot. In other words, if your bot's nickname is Nick and your trigger is qr/^trig\s+/ you would make the request by saying Nick, trig link #foo. When addressed mode is turned on, the bot's nickname, including any whitespace and common punctuation character will be removed before matching the trigger (see above). When addressed argument it set to a false value, public messages will only have to match trigger regex in order to make a request. Note: this argument has no effect on /notice and /msg requests. Defaults to: 1


    ->new( listen_for_input => [ qw(public  notice  privmsg) ] );

Optional. Takes an arrayref as a value which can contain any of the three elements, namely public, notice and privmsg which indicate which kind of input plugin should respond to. When the arrayref contains public element, plugin will respond to requests sent from messages in public channels (see addressed argument above for specifics). When the arrayref contains notice element plugin will respond to requests sent to it via /notice messages. When the arrayref contains privmsg element, the plugin will respond to requests sent to it via /msg (private messages). You can specify any of these. In other words, setting ( listen_for_input = [ qr(notice privmsg) ] )> will enable functionality only via /notice and /msg messages. Defaults to: [ qw(public notice privmsg) ]


    ->new( eat => 0 );

Optional. If set to a false value plugin will return a PCI_EAT_NONE after responding. If eat is set to a true value, plugin will return a PCI_EAT_ALL after responding. See POE::Component::IRC::Plugin documentation for more information if you are interested. Defaults to: 1


    ->new( debug => 1 );

Optional. Takes either a true or false value. When debug argument is set to a true value some debugging information will be printed out. When debug argument is set to a false value no debug info will be printed. Defaults to: 0.



    $VAR1 = {
        'out' => [
            '#foo bar, #foo beer, #foo bez, #foo p, #foo div, #foo a'
        'who' => 'Zoffix!',
        'what' => 'multi [#foo] bar, beer, bez, p, div, a',
        'type' => 'public',
        'channel' => '#zofbot',
        'message' => 'CSSToolsBot, sel multi [#foo] bar, beer, bez, p, div, a'

The event handler set up to handle the event, name of which you've specified in the response_event argument to the constructor (it defaults to irc_css_selector_tools) will receive input every time request is completed. The input will come in $_[ARG0] in a form of a hashref. The possible keys/values of that hashref are as follows:


        'out' => [
            '#foo bar, #foo beer, #foo bez, #foo p, #foo div, #foo a'

The out key will contain an arrayref of responses the plugin would send to IRC if auto argument to constructor is set to a true value. If the length of output is more than line_length (see CONSTRUCTOR) then this arrayref will contain several elements.


    { 'what' => 'multi [#foo] bar, beer, bez, p, div, a', }

The what key will contain the command and the data associated with it. In other words what the user requested after the trigger was stripped off (note that triggers are NOT stripped here yet)


    { 'who' => 'Zoffix!', }

The who key will contain the usermask of the user who sent the request.


    { 'type' => 'public' }

The type key will contain the "type" of the message sent by the requester. The possible values are: public, notice and privmsg indicating that request was requested in public channel, via /notice and via /msg (private message) respectively.


    { 'channel' => '#zofbot' }

The channel key will contain the name of the channel from which the request came from. This will only make sense when type key (see above) contains public.


    { 'message' => 'CSSToolsBot, sel multi [#foo] bar, beer, bez, p, div, a' }

The message key will contain the message which the user has sent as a request (i.e. without any triggers being stripped off).


Fork this module on GitHub:


To report bugs or request features, please use

If you can't access GitHub, you can email your request to bug-POE-Component-IRC-PluginBundle-WebDevelopment at


Zoffix Znet <zoffix at> (,


You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.