The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Konstrukt::Parser - Parser for the tag syntax

SYNOPSIS

        #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);

DESCRIPTION

Parses a given file against special (e.g. <&...&>) tags.

CONFIGURATION

        #all tag names will be lowercased
        parser/lowercase_tags 1
        parser/tag_start      <
        parser/tag_end        >
        parser/comment_start  <!--
        parser/comment_end    -->
        

METHODS

new

Constructor of this class

init

Initialization of this class

prepare

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.

parse_and_prepare_tag

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.

Parameters:

  • $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,
                    ...
            }

prepare_tag

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.

Parameters:

  • $tag - The tag to prepare.

  • $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,
                    ...
            }

execute

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.

Parameters:

  • $node - Reference to a node of the tree. Usually you will pass the root node, which is the result of "prepare".

  • $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, ... }

  • $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.

merge_plugin_results

Only used internally by "prepare" and "execute". Will merge the result returned by a plugin into the current position of the tree.

Parameters:

  • $tag - The tag which generated/modified the result.

  • $result - The result returned by a plugin.

merge_similar_neighbours

Only used internally by "prepare". Will recursively merge neighbouring plaintext or comment nodes of the same type.

Parameters:

  • $start - The node whose children should be processed

parse_tag

Accepts a tag-string (e.g. template src="blah.template") and returns the parsed tag as an hashreference.

Parameters:

  • $tagstring - The tag string

Returns:

The parsed tag as an hashreference. Example for template src="blah.template" /

        $tag = {
                type => 'template',
                attributes => { src => 'blah.template' },
                singleclosing => 1
        }

AUTHOR

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.

SEE ALSO

Konstrukt::Parser::Node, Konstrukt::TagHandler, Konstrukt