Why not adopt me?
NAME
POE::Component::Syntax::Highlight::CSS - non-blocking wrapper around Syntax::Highlight::CSS
SYNOPSIS
use strict;
use warnings;
use POE qw/Component::Syntax::Highlight::CSS/;
my $poco = POE::Component::Syntax::Highlight::CSS->spawn;
POE::Session->create( package_states => [ main => [qw(_start results)] ], );
$poe_kernel->run;
sub _start {
$poco->parse({
event => 'results',
in => 'a:hover { font-weight: bold; }',
}
);
}
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::CSS (although the major intention was to create event based interface) which provides interface to highlight CSS code by wrapping syntax elements into HTML <span>
elements with different class names.
CONSTRUCTOR
spawn
my $poco = POE::Component::Syntax::Highlight::CSS->spawn;
POE::Component::Syntax::Highlight::CSS->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::CSS 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',
nnn => 1,
pre => 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 => 'a:hover { font-weight: bold; }',
nnn => 1,
pre => 1,
_blah => 'pooh!',
session => 'other',
}
);
Instructs the component to parse given CSS 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 => 'a:hover { font-weight: bold; }', }
Mandatory. Takes a string as a value which represents CSS 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 CSS code. Defaults to: 0
pre
{ pre => 1, }
Optional. Takes either true or false values. When set to a true value will wrap highlighted CSS 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 class="css-code"><span class="ch-l"> 0</span> <span
class="ch-sel">a<span class="ch-ps">:hover</span></span> { <span
class="ch-p">font-weight</span>: <span class="ch-v">bold</span>; }</pre>',
'in' => 'a:hover { font-weight: bold; }',
'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 class="css-code"><span class="ch-l"> 0</span> <span
class="ch-sel">a<span class="ch-ps">:hover</span></span> { <span
class="ch-p">font-weight</span>: <span class="ch-v">bold</span>; }</pre>',
}
The out
key will contain a string representing highlighted CSS code. See documentation for Syntax::Highlight::CSS for explanation of each of the possible class=""
names on the generated <span>
s.
in
{ 'in' => 'a:hover { font-weight: bold; }', }
The in
key will contain the original CSS 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-css at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-Syntax-Highlight-CSS. 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::CSS
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-Syntax-Highlight-CSS
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
http://cpanratings.perl.org/d/POE-Component-Syntax-Highlight-CSS
Search CPAN
http://search.cpan.org/dist/POE-Component-Syntax-Highlight-CSS
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.