| POE-Component-IRC-Plugin-HTML-ElementInfo documentation | view source | Contained in the POE-Component-IRC-Plugin-HTML-ElementInfo distribution. |
POE::Component::IRC::Plugin::HTML::ElementInfo - lookup HTML element information from IRC
use strict;
use warnings;
use POE qw(Component::IRC Component::IRC::Plugin::HTML::ElementInfo);
my $irc = POE::Component::IRC->spawn(
nick => 'HTMLInfoBot',
server => 'irc.freenode.net',
port => 6667,
ircname => 'Lookup HTML element info',
);
POE::Session->create(
package_states => [
main => [ qw(_start irc_001) ],
],
);
$poe_kernel->run;
sub _start {
$irc->yield( register => 'all' );
$irc->plugin_add(
'HTMLInfo' =>
POE::Component::IRC::Plugin::HTML::ElementInfo->new
);
$irc->yield( connect => {} );
}
sub irc_001 {
$_[KERNEL]->post( $_[SENDER] => join => '#zofbot' );
}
<Zoffix> HTMLInfoBot, html span
<HTMLInfoBot> Zoffix, span [HTML 4.01] is not empty and not deprecated.
Start tag is required. End tag is required. Description:
generic language/style container.
<Zoffix> HTMLInfoBot, html head
<HTMLInfoBot> Zoffix, head [HTML 4.01] is not empty and not deprecated.
Start tag is optional. End tag is optional. Description:
document head.
<Zoffix> HTMLInfoBot, html u
<HTMLInfoBot> Zoffix, u [Loose HTML 4.01] is not empty and deprecated.
Start tag is required. End tag is required. Description:
underlined text style.
<Zoffix> HTMLInfoBot, html blah
<HTMLInfoBot> Zoffix, I don't have information for blah
This module is a POE::Component::IRC plugin which uses POE::Component::IRC::Plugin for its base. It provides interface to lookup HTML element information (description, whether or not the element is deprecated, are opening/closing tags required, etc)
It accepts input from public channel events, /notice messages as well
as /msg (private messages); although that can be configured at will.
# plain and simple
$irc->plugin_add(
'HTMLInfo' => POE::Component::IRC::Plugin::HTML::ElementInfo->new
);
# juicy flavor
$irc->plugin_add(
'HTMLInfo' =>
POE::Component::IRC::Plugin::HTML::ElementInfo->new(
auto => 1,
response_event => 'irc_html_info',
banned => [ qr/aol\.com$/i ],
root => [ qr/mah.net$/i ],
addressed => 1,
trigger => qr/^html\s+(?=\S+$)/i,
listen_for_input => [ qw(public notice privmsg) ],
eat => 1,
debug => 0,
out_format => '[[el]] [[[dtd]]] is [l[empty]] and '
. '[l[deprecated]]. Start tag is [l[start_tag]].'
. ' End tag is [l[end_tag]]. '
. 'Description: [l[description]].',
)
);
The new() method constructs and returns a new
POE::Component::IRC::Plugin::HTML::ElementInfo 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 the values for constructor's arguments by accessing
them as keys in plugin's object, i.e.
$plugin_object->{one_of_arguments} = 'blah'
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 emited by the plugin to retrieve the results (see
EMITED EVENTS section and response_event argument for details).
Defaults to: 1.
->new( response_event => 'event_name_to_recieve_results' );
Optional. Takes a scalar string specifying the name of the event
to emit when the results of the request are ready. See EMITED EVENTS
section for more information. Defaults to: irc_html_info
->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/\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.
->new( trigger => qr/^html\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/^html\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 span.
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( out_format =>
'[[el]] [[[dtd]]] is [l[empty]] and '
. '[l[deprecated]]. Start tag is [l[start_tag]]. End tag is '
. '[l[end_tag]]. Description: [l[description]].'
);
This monster argument specifies the format of the output message. As
a value it takes a string with "tags". Those tags will be substituted
by particular bits of information they represent. Tags in format
[[tag_name]] will be replaced as they are and tags in format
[l[tag_name]] (note the 'l') will be replaced by data in all lower case.
In other words if data for tag 'empty' reads "Not empty" the [[empty]]
tag will be replaced by words "Not empty" but [l[empty]] tags will
be replaced by words "not empty". You can duplicate tags if you like.
By default the out_format is set to:
'[[el]] [[[dtd]]] is [l[empty]] and '
. '[l[deprecated]]. Start tag is [l[start_tag]]. End tag is '
. '[l[end_tag]]. Description: [l[description]].'
Which results in message as:
<HTMLInfoBot> Zoffix, u [Loose HTML 4.01] is not empty and deprecated.
Start tag is required. End tag is required. Description: underlined
text style.
Possible tags are as follows:
[[el]]Will be replaced by element's name, i.e. what the user gave the plugin to lookup information for.
[[dtd]]Will be replaced with the DTD (Document Type Definition) in which the element is valid (this would usually be HTML 4.01 Strict, Loose and Frameset).
[[empty]]Will be replaced with words "empty" or "not empty" depending on whether or not the element is an empty element
[[deprecated]]Will be replaced with words "deprecated" or "not deprecated" indicating wether or not the element is deprecated in HTML 4.01 Strict.
[[start_tag]]Will be replaced by words "required" or "optional" indicating wether or not the start tag for this element is required.
[[end_tag]]Same as [[start_tag]] except this is for the end tag.
[[description]]Will be replaced with element's short description (its purpose)
->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' => 'span [HTML 4.01] is not empty and not deprecated. Start
tag is required. End tag is required. Description: generic
language/style container.',
'who' => 'Zoffix!n=Zoffix@unaffiliated/zoffix',
'what' => 'span',
'type' => 'public',
'channel' => '#zofbot',
'message' => 'HTMLInfoBot, html span'
};
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_html_info) will recieve input
every time request is completed. The input will come in $_[ARG0] in
a form of a hashref.
The keys/value of that hashref are as follows:
{ 'out' => 'span [HTML 4.01] is not empty and not deprecated. Start
tag is required. End tag is required. Description: generic
language/style container.' }
The out key will contain the "information message", this will be
your out_format (see constructor) string filled with bits of information
and this will be what will be sent to IRC if auto argument to constructor
is set to a true value.
{ 'what' => 'span' }
The what key will contain the name of the element which was looked up.
{ 'who' => 'Zoffix!n=Zoffix@unaffiliated/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
requestor. 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' => 'HTMLInfoBot, html span' }
The message key will contain the message which the user has
sent to request.
Zoffix Znet, <zoffix at cpan.org>
(http://zoffix.com, http://haslayout.net)
Please report any bugs or feature requests to bug-poe-component-irc-plugin-html-elementinfo at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-IRC-Plugin-HTML-ElementInfo. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc POE::Component::IRC::Plugin::HTML::ElementInfo
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-IRC-Plugin-HTML-ElementInfo
http://annocpan.org/dist/POE-Component-IRC-Plugin-HTML-ElementInfo
http://cpanratings.perl.org/d/POE-Component-IRC-Plugin-HTML-ElementInfo
http://search.cpan.org/dist/POE-Component-IRC-Plugin-HTML-ElementInfo
Copyright 2008 Zoffix Znet, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| POE-Component-IRC-Plugin-HTML-ElementInfo documentation | view source | Contained in the POE-Component-IRC-Plugin-HTML-ElementInfo distribution. |