The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Component::IRC::Plugin::CSS::PropertyInfo - lookup CSS property information from IRC

SYNOPSIS

    use strict;
    use warnings;

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

    my $irc = POE::Component::IRC->spawn(
        nick        => 'CSSInfoBot',
        server      => 'irc.freenode.net',
        port        => 6667,
        ircname     => 'CSS Property Info bot',
    );

    POE::Session->create(
        package_states => [
            main => [ qw(_start irc_001) ],
        ],
    );

    $poe_kernel->run;

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

        $irc->plugin_add(
            'CSSInfo' =>
                POE::Component::IRC::Plugin::CSS::PropertyInfo->new
        );

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

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


    <Zoffix> CSSInfoBot, css exists foo
    <CSSInfoBot> Property 'foo' does not seem to exist
    <Zoffix> CSSInfoBot, css exists float
    <CSSInfoBot> Yes, property 'float' does exist

    <Zoffix> CSSInfoBot, css initial bar
    <CSSInfoBot> Property 'bar' does not seem to exist
    <Zoffix> CSSInfoBot, css initial float
    <CSSInfoBot> Initial value for 'float' is none

    <Zoffix> CSSInfoBot, css values position
    <CSSInfoBot> Property 'position' accepts: static | relative | absolute | fixed | inherit

    <Zoffix> CSSInfoBot, css inherited color
    <CSSInfoBot> Yes, 'color' is inherited
    <Zoffix> CSSInfoBot, css inherited display
    <CSSInfoBot> No, 'display' is not inherited

    <Zoffix> CSSInfoBot, css percentages width
    <CSSInfoBot> Percentages for 'width' refer to refer to width of containing block
    <Zoffix> CSSInfoBot, css percentages display
    <CSSInfoBot> Percetages do not apply to 'display'

    <Zoffix> CSSInfoBot, css applies to display
    <CSSInfoBot> Property 'display' applies to: all elements
    <Zoffix> CSSInfoBot, css applies to width
    <CSSInfoBot> Property 'width' applies to: all elements but non-replaced inline elements, table rows, and row groups

    <Zoffix> CSSInfoBot, css media color
    <CSSInfoBot> Property 'color' belongs to visual media type(s)
    <Zoffix> CSSInfoBot, css media azimut
    <CSSInfoBot> Property 'azimut' belongs to aural media type(s)

    <Zoffix> CSSInfoBot, css value type margin-width
    <CSSInfoBot> Value type 'margin-width' is described on http://www.w3.org/TR/CSS21/box.html#value-def-margin-width
    <Zoffix> CSSInfoBot, css value type counter
    <CSSInfoBot> Value type 'counter' is described on http://www.w3.org/TR/CSS21/syndata.html#value-def-counter

DESCRIPTION

This module is a POE::Component::IRC plugin which uses POE::Component::IRC::Plugin for its base. It provides means to lookup information pertaining to CSS properties (see log snippet in 'SYNOPSIS' above)

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

CONSTRUCTOR

new

    # plain and simple
    $irc->plugin_add(
        'CSSPropertyInfo' =>
            POE::Component::IRC::Plugin::CSS::PropertyInfo->new
    );

    # juicy flavor
    $irc->plugin_add(
        'CSSPropertyInfo' =>
      POE::Component::IRC::Plugin::CSS::PropertyInfo->new(
        auto             => 1,
        banned           => [ qr/aol\.com$/i ],
        root             => [ qr/mah.net$/i ],
        addressed        => 1,
        trigger          => qr/^css\s+(?=\S+\s+\S+)/i,
        command_triggers => {
            exists      => qr/^ e (?:xist s?)?                    \s+/xi,
            initial     => qr/^ i (?:nitial)?                     \s+/xi,
            values      => qr/^ v (?:alue s?)?                    \s+/xi,
            inherited   => qr/^ in (?:herit (?:ed)? )?            \s+/xi,
            percentages => qr/^ p (?:ercent (?:age s? )? )?       \s+/xi,
            applies_to  => qr/^ a (?: ppl (?:y|ies))? \s* (?:to)? \s+/xi,
            media       => qr/^ m (?: edia)? \s* (?:type)?        \s+/xi,
            value_type  => qr/^ v (?: alue )? \s* t (?: ypes?)?  \s+/xi,
        },
        response_event   => 'irc_css_property_info',
        listen_for_input => [ qw(public notice privmsg) ],
        eat              => 1,
        debug            => 0,
      )
    );

The new() method constructs and returns a new POE::Component::IRC::Plugin::CSS::PropertyInfo 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. The possible arguments/values are as follows:

auto

    ->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.

response_event

    ->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_property_info

banned

    ->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).

root

    ->new( root => [ qr/\Qjust.me.and.my.friend.net\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.

trigger

    ->new( trigger => qr/^css\s+(?=\S+\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 including sub triggers which are set by command_triggers argument (see below). Defaults to: qr/^css\s+(?=\S+\s+\S+)/i

command_triggers

    command_triggers => {
        exists      => qr/^ e (?:xist s?)?                    \s+/xi,
        initial     => qr/^ i (?:nitial)?                     \s+/xi,
        values      => qr/^ v (?:alue s?)?                    \s+/xi,
        inherited   => qr/^ in (?:herit (?:ed)? )?            \s+/xi,
        percentages => qr/^ p (?:ercent (?:age s? )? )?       \s+/xi,
        applies_to  => qr/^ a (?: ppl (?:y|ies))? \s* (?:to)? \s+/xi,
        media       => qr/^ m (?: edia)? \s* (?:type)?        \s+/xi,
        value_type  => qr/^ v (?: alue )? \s* t (?: ypes?)?  \s+/xi,
    },

Optional. After the trigger (see above) is matched and removed a match for a particular "command" will be made. As the case is with trigger the command_triggers will be removed from the request string before proceeding thus make sure they don't match the data needed for the request. That data will be a name of the CSS property for all the commands except for value_type command for which the data are CSS value types listed below. The command_triggers argument takes a hashref with keys being command names and values being regexes. The default settings are presented in the snippet above. The commands (keys of the command_triggers hashref) represent the following commands:

exists

    exists      => qr/^ e (?:xist s?)?                    \s+/xi,

    <Zoffix> CSSInfoBot, css exists foo
    <CSSInfoBot> Property 'foo' does not seem to exist
    <Zoffix> CSSInfoBot, css exists float
    <CSSInfoBot> Yes, property 'float' does exist

The exists command checks whether or not CSS property exists.

initial

    initial     => qr/^ i (?:nitial)?                     \s+/xi,

    <Zoffix> CSSInfoBot, css initial bar
    <CSSInfoBot> Property 'bar' does not seem to exist
    <Zoffix> CSSInfoBot, css initial float
    <CSSInfoBot> Initial value for 'float' is none

The initial command lists property's initial values.

values

    values      => qr/^ v (?:alue s?)?                    \s+/xi,

    <Zoffix> CSSInfoBot, css values position
    <CSSInfoBot> Property 'position' accepts: static | relative | absolute | fixed | inherit

The values command lists valid values accepted by CSS property. Those will be either literal values or "value types". The link describing certain value type can be obtained by inquiring the plugin's value_type command (see below).

inherited

    inherited   => qr/^ in (?:herit (?:ed)? )?            \s+/xi,

    <Zoffix> CSSInfoBot, css inherited color
    <CSSInfoBot> Yes, 'color' is inherited
    <Zoffix> CSSInfoBot, css inherited display
    <CSSInfoBot> No, 'display' is not inherited

The inherited command tells one whether or not a certain CSS property's values are inherited or not.

percentages

    percentages => qr/^ p (?:ercent (?:age s? )? )?       \s+/xi,

    <Zoffix> CSSInfoBot, css percentages width
    <CSSInfoBot> Percentages for 'width' refer to refer to width of containing block
    <Zoffix> CSSInfoBot, css percentages display
    <CSSInfoBot> Percetages do not apply to 'display'

The percentages command tells one to what do the percentage values for the property refer to.

applies_to

    applies_to  => qr/^ a (?: ppl (?:y|ies))? \s* (?:to)? \s+/xi,

    <Zoffix> CSSInfoBot, css applies to display
    <CSSInfoBot> Property 'display' applies to: all elements
    <Zoffix> CSSInfoBot, css applies to width
    <CSSInfoBot> Property 'width' applies to: all elements but non-replaced inline elements, table rows, and row groups

The applies_to command tells one to which elements the specified property applies.

media

    media       => qr/^ m (?: edia)? \s* (?:type)?        \s+/xi,

    <Zoffix> CSSInfoBot, css media color
    <CSSInfoBot> Property 'color' belongs to visual media type(s)
    <Zoffix> CSSInfoBot, css media azimut
    <CSSInfoBot> Property 'azimut' belongs to aural media type(s)

The media command tells one to which media type a certain property belongs.

value_type

    value_type  => qr/^ v (?: alue )? \s* t (?: ypes?)?  \s+/xi,

    <Zoffix> CSSInfoBot, css value type margin-width
    <CSSInfoBot> Value type 'margin-width' is described on http://www.w3.org/TR/CSS21/box.html#value-def-margin-width
    <Zoffix> CSSInfoBot, css value type counter
    <CSSInfoBot> Value type 'counter' is described on http://www.w3.org/TR/CSS21/syndata.html#value-def-counter

Lastly, the value_type command. It takes "value types" as an argument as opposed to CSS properties and simply returns a URI pointing to the documentation describing the value type. Possible value types are these:

    margin-width
    absolute-size
    number
    time
    string
    border-width
    border-style
    frequency
    identifier
    color
    integer
    specific-voice
    relative-size
    generic-voice
    padding-width
    angle
    percentage
    family-name
    uri
    length
    generic-family
    shape
    counter

addressed

    ->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 a float. 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

listen_for_input

    ->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) ]

eat

    ->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

debug

    ->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.

EMITTED EVENTS

response_event

    $VAR1 = {
        'out' => 'Property \'float\' applies to: all, but see http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo',
        'who' => 'Zoffix!n=Zoffix@unaffiliated/zoffix',
        'what' => 'a float',
        'type' => 'public',
        'channel' => '#zofbot',
        'message' => 'CSSInfoBot_, css a float'
    };

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_property_info) will receive input every time request is completed. The input will come in a form of a hashref in $_[ARG0]. The keys/values of that hashref are as follows:

out

    { 'out' => 'Property \'float\' applies to: all, but see http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo', }

The out key will contain the "information message", this will be the response string containing the response to the particular command and this will be what will be sent to IRC if auto argument to constructor is set to a true value.

what

    { 'what' => 'a float' }

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, in the sample above the command is applies_to and the property is float.

who

    { 'who' => 'Zoffix!n=Zoffix@unaffiliated/zoffix' }

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

type

    { '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

    { '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

    { 'message' => 'CSSInfoBot_, css a float' }

The message key will contain the message which the user has sent to request.

REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/POE-Component-IRC-PluginBundle-WebDevelopment

BUGS

To report bugs or request features, please use https://github.com/zoffixznet/POE-Component-IRC-PluginBundle-WebDevelopment/issues

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

AUTHOR

Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)

LICENSE

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.