Konstrukt::Parser - Parser for the tag syntax
#this will be done in your top-level handler. use Konstrukt::Parser; #prepare run my $actions = { '&' => $Konstrukt::TagHandler::Plugin }; my $prepared = $Konstrukt::Parser->prepare(\$some_input, $actions); #execute run my $executed = $Konstrukt::Parser->execute($prepared, $actions);
Parses a given file against special (e.g. <&...&>) tags.
#all tag names will be lowercased parser/lowercase_tags 1 parser/tag_start < parser/tag_end > parser/comment_start <!-- parser/comment_end -->
Constructor of this class
Initialization of this class
This sub will accept a scalarref or a node with some children.
Plaintext nodes will be parsed into tags and executed.
All plugins/tags that return static output on static input will be executed ($plugin->prepare()) and replaced by the returned static content.
Plugins/tags that generate dynamic content will stay in the tree to be executed in the "execute" run ($plugin->execute()).
Tag nodes will be prepare()'d recursively.
Parameters:
$input - Reference to a scalar (plaintext) or a node (Konstrukt::Parser::Node) with some plaintext nodes.
$actions - Hashreference containing the tag-types (as hash-keys) that are recognized and the handler object (see also Konstrukt::TagHandlers that should handle this tag-type. Should look like $actions = { '&' => $Konstrukt::TagHandler::Plugin, ... }
Currently only used by the template plugin.
Will generate a final tag of the passed preliminary tag. The prepare method will be called on this tag.
Returns the new "parent" node, under which all new nodes will be collected.
$node - The preliminary Tag.
$actions - Hashreference containing the tag-types (as hash-keys) that are recognized and the handler object (see also Konstrukt::TagHandlers that should handle this tag-type.
Should look like:
$actions = { '&' => $Konstrukt::TagHandler::Plugin, ... }
Will run the prepare method on a specified tag, if possible (i.e. if the tag could be finally parsed, an action is specified and the tag doesn't have dynamic children).
The result will be put into the tree instead of the prepared tag, if the tag returned a result.
$tag - The tag to prepare.
This sub takes a tree (usually the result of "prepare") and executes all plugins. Every plugin must return static content now as the result of the execution is the final result of the parsing process.
$node - Reference to a node of the tree. Usually you will pass the root node, which is the result of "prepare".
$executionstage - Optional: Only tags whose stage is <= the execution stage will be executed. This parameter will only be set internally. You should never set it on your own when calling the execute method.
Only used internally by "prepare" and "execute". Will merge the result returned by a plugin into the current position of the tree.
$tag - The tag which generated/modified the result.
$result - The result returned by a plugin.
Only used internally by "prepare". Will recursively merge neighbouring plaintext or comment nodes of the same type.
$start - The node whose children should be processed
Accepts a tag-string (e.g. template src="blah.template") and returns the parsed tag as an hashreference.
template src="blah.template"
$tagstring - The tag string
The parsed tag as an hashreference. Example for template src="blah.template" /
template src="blah.template" /
$tag = { type => 'template', attributes => { src => 'blah.template' }, singleclosing => 1 }
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.
Konstrukt::Parser::Node, Konstrukt::TagHandler, Konstrukt
To install Konstrukt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Konstrukt
CPAN shell
perl -MCPAN -e shell install Konstrukt
For more information on module installation, please visit the detailed CPAN module installation guide.