Why not adopt me?
NAME
POE::Component::Syntax::Highlight::HTML - non-blocking wrapper around Syntax::Highlight::HTML
SYNOPSIS
use strict;
use warnings;
use POE qw/Component::Syntax::Highlight::HTML/;
my $poco = POE::Component::Syntax::Highlight::HTML->spawn;
POE::Session->create( package_states => [ main => [qw(_start results)] ], );
$poe_kernel->run;
sub _start {
$poco->parse( {
event => 'results',
in => '<p>Foo <a href="bar">bar</a></p>',
}
);
}
sub results {
print "$_[ARG0]->{out}\n";
$poco->shutdown;
}
Using event based interface is also possible of course.
DESCRIPTION
The module is a non-blocking wrapper around Syntax::Highlight::HTML (although the major intention was to create event based interface) which provides interface to highlight HTML code by wrapping syntax elements into HTML <span>
elements with different class names.
CONSTRUCTOR
spawn
my $poco = POE::Component::Syntax::Highlight::HTML->spawn;
POE::Component::Syntax::Highlight::HTML->spawn(
alias => 'highlighter',
options => {
debug => 1,
trace => 1,
# POE::Session arguments for the component
},
debug => 1, # output some debug info
);
The spawn
method returns a POE::Component::Syntax::Highlight::HTML object. It takes a few arguments, all of which are optional. The possible arguments are as follows:
alias
->spawn( alias => 'highlighter' );
Optional. Specifies a POE Kernel alias for the component.
options
->spawn(
options => {
trace => 1,
default => 1,
},
);
Optional. A hashref of POE Session options to pass to the component's session.
debug
->spawn(
debug => 1
);
When set to a true value turns on output of debug messages. Defaults to: 0
.
METHODS
parse
$poco->parse( {
event => 'event_for_output',
in => '<p>Foo <a href="bar">bar</a></p>',
pre => 1,
nnn => 1,
_blah => 'pooh!',
session => 'other',
}
);
Takes a hashref as an argument, does not return a sensible return value. See parse
event's description for more information.
session_id
my $poco_id = $poco->session_id;
Takes no arguments. Returns component's session ID.
shutdown
$poco->shutdown;
Takes no arguments. Shuts down the component.
ACCEPTED EVENTS
parse
$poe_kernel->post( highlighter => parse => {
event => 'event_for_output',
in => '<p>Foo <a href="bar">bar</a></p>',
pre => 1,
nnn => 1,
_blah => 'pooh!',
session => 'other',
}
);
Instructs the component to highlight HTML code. Takes a hashref as an argument, the possible keys/value of that hashref are as follows:
event
{ event => 'results_event', }
Mandatory. Specifies the name of the event to emit when results are ready. See OUTPUT section for more information.
in
{ in => '<p>Foo <a href="bar">bar</a></p>', }
Mandatory. Takes a string as a value which represents HTML code to syntax-highlight.
nnn
{ nnn => 1, }
Optional. Takes either true or false values. When set to a true value will insert line numbers into the highlighted HTML code. Defaults to: 0
pre
{ pre => 1, }
Optional. Takes either true or false values. When set to a true value will wrap highlighted HTML code into a <pre>
element. Defaults to: 1
session
{ session => 'other' }
{ session => $other_session_reference }
{ session => $other_session_ID }
Optional. Takes either an alias, reference or an ID of an alternative session to send output to.
user defined
{
_user => 'random',
_another => 'more',
}
Optional. Any keys starting with _
(underscore) will not affect the component and will be passed back in the result intact.
shutdown
$poe_kernel->post( highlighter => 'shutdown' );
Takes no arguments. Tells the component to shut itself down.
OUTPUT
$VAR1 = {
'out' => '<pre>
<span class="h-ab"><</span><span class="h-tag">p</span><span
class="h-ab">></span>Foo <span class="h-ab"><</span><span
class="h-tag">a</span> <span class="h-attr">href</span>=<span
class="h-attv">"bar</span>"<span class="h-ab">></span>bar<span
class="h-ab"></</span><span class="h-tag">a</span><span
class="h-ab">></span><span class="h-ab"></</span><span
class="h-tag">p</span><span class="h-ab">></span></pre>',
'in' => '<p>Foo <a href="bar">bar</a></p>',
'nnn' => 1,
'pre' => 1,
'_blah' => 'foos'
};
The event handler set up to handle the event which you've specified in the event
argument to parse()
method/event will recieve input in the $_[ARG0]
in a form of a hashref. The possible keys/value of that hashref are as follows:
out
{
'out' => '<pre>
<span class="h-ab"><</span><span class="h-tag">p</span><span
class="h-ab">></span>Foo <span class="h-ab"><</span><span
class="h-tag">a</span> <span class="h-attr">href</span>=<span
class="h-attv">"bar</span>"<span class="h-ab">></span>bar<span
class="h-ab"></</span><span class="h-tag">a</span><span
class="h-ab">></span><span class="h-ab"></</span><span
class="h-tag">p</span><span class="h-ab">></span></pre>',
}
The out
key will contain a string representing highlighted HTML code. See documentation for Syntax::Highlight::HTML for explanation of each of the possible class=""
names on the generated <span>
s.
in
{ 'in' => '<p>Foo <a href="bar">bar</a></p>', }
The in
key will contain the original HTML code.
nnn
and pre
{
'nnn' => 1,
'pre' => 1,
}
If you specified either nnn
or pre
arguments to the parse()
event/method they will be present in the output with the values that you set to them.
user defined
{ '_blah' => 'foos' }
Any arguments beginning with _
(underscore) passed into the parse()
event/method will be present intact in the result.
SEE ALSO
AUTHOR
'Zoffix, <'zoffix at cpan.org'>
(http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)
BUGS
Please report any bugs or feature requests to bug-poe-component-syntax-highlight-html at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-Syntax-Highlight-HTML. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Component::Syntax::Highlight::HTML
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-Syntax-Highlight-HTML
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/POE-Component-Syntax-Highlight-HTML
CPAN Ratings
http://cpanratings.perl.org/d/POE-Component-Syntax-Highlight-HTML
Search CPAN
http://search.cpan.org/dist/POE-Component-Syntax-Highlight-HTML
COPYRIGHT & LICENSE
Copyright 2008 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.