Björn Höhrmann > CSS-SAC-0.08 > CSS::SAC

Download:
CSS-SAC-0.08.tar.gz

Dependencies

Annotate this POD

Related Modules

Text::Balanced
Text::Template
CGI::Carp
HTML::Parser
more...
By perlmonks.org

CPAN RT

New  5
Open  3
View/Report Bugs
Module Version: 0.08   Source  

NAME ^

CSS::SAC - SAC CSS parser

SYNOPSIS ^

  use CSS::SAC qw();
  use My::SACHandler ();
  use My::SACErrors ();

  my $doc_handler = My::SACHandler->new;
  my $err_handler = My::SACErrors->new;
  my $sac = CSS::SAC->new({
                           DocumentHandler => $doc_handler,
                           ErrorHandler    => $err_handler,
                         });

  # generate a stream of events
  $sac->parse({ filename => 'foo.css' });

DESCRIPTION ^

SAC (Simple API for CSS) is an event-based API much like SAX for XML. If you are familiar with the latter, you should have little trouble getting used to SAC. More information on SAC can be found online at http://www.w3.org/TR/SAC.

CSS having more constructs than XML, core SAC is still more complex than core SAX. However, if you need to parse a CSS style sheet, SAC probably remains the easiest way to get it done.

Most of the spec is presently implemented. The following interfaces are not yet there: Locator, CSSException, CSSParseException, ParserFactory. They may or may not be implemented at a later date (the most likely candidates are the exception classes, for which I still have to find an appropriate model).

Some places differ slightly from what is in the spec. I have tried to keep those to a justified minimum and to flag them correctly.

the CSS::SAC module itself

The Parser class doesn't exist separately, it's defined in CSS::SAC. It doesn't expose the locale interface because we don't localize errors (yet). It also doesn't have parse_style_sheet but rather parse, which is more consistent with other Perl parsing interfaces.

I have added the charset($charset) callback to the DocumentHandler interface. There are valid reasons why it wasn't there (it can be trusted only ever so often, and one should look at the actual encoding instead) but given that it's a token in the grammar, I believe that there should still be a way to access it.

METHODS ^

OTHER METHODS ^

Methods in this section are of relevance mostly to the internal workings of the parser. I document them here but I don't really consider them part of the interface, and thus may change them if need be. If you are using them directly tell me about it and I will "officialize" them. These have no Java style equivalent.

CSS::SAC::DefaultErrorHandler ^

This is pretty much a non package, it is just there to provide the default error handler if you are too lazy to provide one yourself.

All it does is pretty simple. There are three error levels: warning, error, and fatal_error. What it does is warn on the two first and die on the last. Yes, it ain't fancy but then you can plug anything more intelligent into it at any moment.

CSS3 ISSUES ^

One problem is that I have modelled this parser after existing SAC implementations that do not take into account as much of CSS3 as it is possible to. Some parts of that are trivial, and I have provided support on my own in this module. Other parts though are more important and I believe that coordination between the SAC authors would be beneficial on these points (once the relevant CSS3 modules will have moved to REC).

BUGS ^

 - the problem with attaching pseudo-elements to elements as
 coselectors. I'm not sure which is the right representation. Don't
 forget to update CSS::SAC::Writer too so that it writes it out
 properly.

 - see Bjoern's list

ACKNOWLEDGEMENTS ^

 - Bjoern Hoehrmann for his immediate reaction and much valuable
 feedback and suggestions. It's certainly much harder to type with all
 those fingers that all those Mafia padres have cut off, but at least
 I get work done much faster than before. And also those nasty bugs he
 kindly uncovered.

 - Steffen Goeldner for spotting bugs and providing patches.

 - Ian Hickson for very very very kind testing support, and all sorts
 of niceties.

 - Manos Batsis for starting a very long discussion on this that
 eventually deviated into other very interesting topics, and for
 giving me some really weird style sheets to feed into this module.

 - Simon St.Laurent for posting this on xmlhack.com and thus pointing a
 lot of people to this module (as seen in my referer logs).

And of course all the other people that have sent encouragement notes and feature requests.

TODO ^

 - add a pointer to the SAC W3 page

 - create the Exception classes

 - update PositionalCondition to include logic that can normalize the
 an+n notation and add a method that given a position will return a
 boolean indicating whether it matches the condition.

 - add stringify overloading to all classes so that they may be
 printed directly

 - have parser version return an overloaded object that circumvents the
 current problems

 - add docs on how to write a {Document,Error}Handler, right now there
 is example code in Writer, but it isn't all clearly explained.

 - find a way to make the '-' prefix to properties optional

 - add a filter that switches events to spec names, and that can be used
 directly through an option

 - add DOM-like hasFeature support (in view of SAC 3)

 - prefix all constants with SAC_. Keep the old ones around for a few 
 versions, importable with :old-constants.

 - update docs

AUTHOR ^

Robin Berjon <robin@knowscape.com>

This module is licensed under the same terms as Perl itself.

syntax highlighting: