CSS::Parser - parser for CSS-style syntax |
CSS::Parser - parser for CSS-style syntax
use CSS::Parser;
my $css = CSS::Parser->new( handlers => { css_comment => \&css_com, selector_string => \&sel, block_start => \&blk_s, property => \&prop, value => \&val, block_end => \&blk_e, at_rule => \&atr, at_symbol => \&ats, error => \&error } );
$css->parse(\$some_css_text);
sub css_com { my $self = shift; my $comment = shift; print "css comment:\n\t$comment\n"; }
...
The CSS::Parser
deals simply with fairly loose CSS syntax.
It doesn't know anything about what it is parsing, for that
see other classes. This allows it to be the base for CSS::CSSn
,
CSS::STTSn
and any other parser for a css-compatible syntax.
Chances are, you will want to use one of the existing subclasses or to subclass it yourself.
The interface to CSS::Parser
is:
style defines the style of parsing that you want from the parser. As of now the only style is 'callback' (default), however this may evolve in the future.
handlers specifies a hash of callbacks to be called when a given token has been met. Callbacks are CODEREFS. The callback sub will receive the parser object as it's first argument, and optionally the token when it makes sense (eg: selector_string will be passed the selector, but block_start won't receive the '{').
One may use 'default' to activate them all. Note that you can set a callback to the empty string (not undef) if you wish to set a default for all but to deactivate that specific callback.
url('foo')
print;) is seen,
receives the entire rule (it isn't further tokenized, that is the job
of the subclass because it requires it to know what is expected after
the specific at-keyword).
the XML::Parser manpage, the HTML::Parser manpage, the HTML::TreeBuilder manpage
Copyright 1998-1999 Robin Berjon (robin@knowscape.com) All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
CSS::Parser - parser for CSS-style syntax |