{
    "mode": "perldoc",
    "parameter": "Template::Parser",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Template%3A%3AParser/json",
    "generated": "2026-06-13T20:04:56Z",
    "synopsis": "use Template::Parser;\n$parser   = Template::Parser->new(\\%config);\n$template = $parser->parse($text)\n|| die $parser->error(), \"\\n\";",
    "sections": {
        "NAME": {
            "content": "Template::Parser - LALR(1) parser for compiling template documents\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Template::Parser;\n\n$parser   = Template::Parser->new(\\%config);\n$template = $parser->parse($text)\n|| die $parser->error(), \"\\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The \"Template::Parser\" module implements a LALR(1) parser and associated methods for parsing\ntemplate documents into Perl code.\n",
            "subsections": []
        },
        "PUBLIC METHODS": {
            "content": "new(\\%params)\nThe \"new()\" constructor creates and returns a reference to a new \"Template::Parser\" object.\n\nA reference to a hash may be supplied as a parameter to provide configuration values. See\n\"CONFIGURATION OPTIONS\" below for a summary of these options and Template::Manual::Config for\nfull details.\n\nmy $parser = Template::Parser->new({\nSTARTTAG => quotemeta('<+'),\nENDTAG   => quotemeta('+>'),\n});\n\nparse($text)\nThe \"parse()\" method parses the text passed in the first parameter and returns a reference to a\nhash array of data defining the compiled representation of the template text, suitable for\npassing to the Template::Document new() constructor method. On error, undef is returned.\n\n$data = $parser->parse($text)\n|| die $parser->error();\n\nThe $data hash reference returned contains a \"BLOCK\" item containing the compiled Perl code for\nthe template, a \"DEFBLOCKS\" item containing a reference to a hash array of sub-template \"BLOCK\"s\ndefined within in the template, and a \"METADATA\" item containing a reference to a hash array of\nmetadata values defined in \"META\" tags.\n",
            "subsections": []
        },
        "CONFIGURATION OPTIONS": {
            "content": "The \"Template::Parser\" module accepts the following configuration options. Please see\nTemplate::Manual::Config for further details on each option.\n\nSTARTTAG, ENDTAG\nThe STARTTAG and ENDTAG options are used to specify character sequences or regular expressions\nthat mark the start and end of a template directive.\n\nmy $parser = Template::Parser->new({\nSTARTTAG => quotemeta('<+'),\nENDTAG   => quotemeta('+>'),\n});\n\nTAGSTYLE\nThe TAGSTYLE option can be used to set both STARTTAG and ENDTAG according to pre-defined tag\nstyles.\n\nmy $parser = Template::Parser->new({\nTAGSTYLE => 'star',     # [* ... *]\n});\n\nPRECHOMP, POSTCHOMP\nThe PRECHOMP and POSTCHOMP can be set to remove any whitespace before or after a directive\ntag, respectively.\n\nmy $parser = Template::Parser-E<gt>new({\nPRECHOMP  => 1,\nPOSTCHOMP => 1,\n});\n\nINTERPOLATE\nThe INTERPOLATE flag can be set to allow variables to be embedded in plain text blocks.\n\nmy $parser = Template::Parser->new({\nINTERPOLATE => 1,\n});\n\nVariables should be prefixed by a \"$\" to identify them, using curly braces to explicitly scope\nthe variable name where necessary.\n\nHello ${name},\n\nThe day today is ${day.today}.\n\nANYCASE\nThe ANYCASE option can be set to allow directive keywords to be specified in any case.\n\n# with ANYCASE set to 1\n[% INCLUDE foobar %]    # OK\n[% include foobar %]    # OK\n[% include = 10   %]    # ERROR, 'include' is a reserved word\n\nGRAMMAR\nThe GRAMMAR configuration item can be used to specify an alternate grammar for the parser. This\nallows a modified or entirely new template language to be constructed and used by the Template\nToolkit.\n\nuse MyOrg::Template::Grammar;\n\nmy $parser = Template::Parser->new({\nGRAMMAR = MyOrg::Template::Grammar->new();\n});\n\nBy default, an instance of the default Template::Grammar will be created and used automatically\nif a \"GRAMMAR\" item isn't specified.\n\nDEBUG\nThe DEBUG option can be used to enable various debugging features of the \"Template::Parser\"\nmodule.\n\nuse Template::Constants qw( :debug );\n\nmy $template = Template->new({\nDEBUG => DEBUGPARSER | DEBUGDIRS,\n});\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Andy Wardley <abw@wardley.org> <http://wardley.org/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nThe main parsing loop of the \"Template::Parser\" module was derived from a standalone parser\ngenerated by version 0.16 of the \"Parse::Yapp\" module. The following copyright notice appears in\nthe \"Parse::Yapp\" documentation.\n\nThe Parse::Yapp module and its related modules and shell\nscripts are copyright (c) 1998 Francois Desarmenien,\nFrance. All rights reserved.\n\nYou may use and distribute them under the terms of either\nthe GNU General Public License or the Artistic License, as\nspecified in the Perl README file.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Template, Template::Grammar, Template::Directive\n",
            "subsections": []
        }
    },
    "summary": "Template::Parser - LALR(1) parser for compiling template documents",
    "flags": [],
    "examples": [],
    "see_also": []
}