++ed by:
CARWASH RSRCHBOY KARJALA HOUSTON NEBULOUS

59 PAUSE users
38 non-PAUSE users.

Andy Wardley

NAME

Template::Parser - module implementing LALR(1) parser for compiling template documents

SYNOPSIS

    use Template::Parser;

    my $parser   = Template::Parser->new();
    my $template = $parser->parse($text);

    die $parser->error()
        unless defined $template;

DESCRIPTION

The Template::Parser module implements a LALR(1) parser and associated methods for parsing template documents into an internal compiled format.

PUBLIC METHODS

new(\%params)

The new() constructor creates and returns a reference to a new Template::Parser object. A reference to a hash may be supplied as a parameter to provide configuration values. These may include:

START_TAG, END_TAG, TAG_STYLE

The START_TAG and END_TAG options are used to specify the character sequences that mark the start and end of a template directive.

INTERPOLATE

The INTERPOLATE flag, when set to any true value will cause variable references in plain text (i.e. not surrounded by START_TAG and END_TAG) to be recognised and interpolated accordingly. Variables should be prefixed by a '$' to identify them and may contain only alphanumeric characters, underscores or periods. Curly braces can be used to explicitly specify the variable name where it may be ambiguous.

PRE_CHOMP, POST_CHOMP

These values set the chomping options for the parser. With POST_CHOMP set true, any whitespace after a directive up to and including the newline will be deleted. This has the effect of joining a line that ends with a directive onto the start of the next line.

With PRE_CHOMP set true, the newline and whitespace preceeding a directive at the start of a line will be deleted. This has the effect of concatenating a line that starts with a directive onto the end of the previous line.

GRAMMAR

The GRAMMAR configuration item can be used to specify an alternate grammar for the parser. If not specified, an instance of the default Template::Grammar will be created and used automatically.

    use Template::Parser;
    use MyTemplate::MyGrammar;

    my $parser = Template::Parser->new({ 
        GRAMMAR = MyTemplate::MyGrammar->new();
    });

parse($text)

The parse() method parses the text passed in the first parameter and returns a reference to a Template::Directive::Block object which contains the compiled representation of the template text. On error, undef is returned.

Example:

    $parser->parse($text)
        || die $parser->error();

error()

Returns a string indicating the most recent parser error.

AUTHOR

Andy Wardley <abw@cre.canon.co.uk>

REVISION

$Revision: 1.14 $

COPYRIGHT

Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved. Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The Template::Parser module is derived from a standalone parser generated by version 0.16 of the Parse::Yapp module. The following copyright notice appears in the Parse::Yapp documentation.

    The Parse::Yapp module and its related modules and shell
    scripts are copyright (c) 1998 Francois Desarmenien,
    France. All rights reserved.

    You may use and distribute them under the terms of either
    the GNU General Public License or the Artistic License, as
    specified in the Perl README file.

SEE ALSO

Template, Template::Grammar, Template::Directive