The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Petal::Canonicalizer - a class which builds a canonical XML file from a XML / HTML / whatever parser's events. The canonical file can then be sent to the Petal::PerlBuilder module.

DESCRIPTION

This modules mainly implements the XML::Parser 'Stream' interface.

$class->process ($parser, $data_ref);

returns undef if $parser object (i.e. a Petal::Parser::XML object) could not parse the data which $data_ref pointed to.

returns a reference to the canonicalized string otherwise.

XML::Parser functions

These are meant to implement the XML::Parser 'Stream' interface

StartDocument

Initializes the local variables @Result and @NodeStack.

@NodeStack keeps track of the current parsing state (so that the state of the parent nodes can be remembered without having to build a full DOM tree).

@Result keeps the results, so that join '', @result will represent the canonical data to return when the parsing is over.

StartTag

Called for every start tag with a second parameter of the element type. It will check for special PETAL attributes like petal:if, petal:loop, etc... and rewrite the start tag into @Result accordingly.

For example

  <foo petal:if="blah">

Is rewritten

  <?if name="blah"?><foo>

EndTag

Called for every end tag with a second parameter of the element type. It will check in the @NodeStack to see if this end-tag also needs to close some 'condition' or 'repeat' statements, i.e.

  </li>

Could be rewritten

  </li><?end?>

If the starting LI used a loop, i.e. <li petal:loop="element list">

Text

Called just before start or end tags. Turns all variables such as $foo:bar into <?petal var name=":foo bar"?>

AUTHOR

Jean-Michel Hiver <jhiver@mkdoc.com>

This module is redistributed under the same license as Perl itself.