Template::Parser(3)
π Template::Parser(3) β LALR(1) parser for compiling template documents π
okay bestie, this is the User Contributed Perl Documentation page for Template::Parser β say hi to the LALR(1) parser bestie π
β¨ NAME β¨
Template::Parser β LALR(1) parser for compiling template documents π
πΈ SYNOPSIS πΈ
use Template::Parser;
$parser = Template::Parser->new(\%config);
$template = $parser->parse($text)
|| die $parser->error(), "\n";
π DESCRIPTION π
The Template::Parser module implements a LALR(1) parser and associated methods for parsing template documents into Perl code. no cap, that's the whole glow-up β¨
π«Ά PUBLIC METHODS π«Ά
π new(\%params) π
The new() constructor creates and returns a reference to a new Template::Parser object. main character energy fr π
A reference to a hash may be supplied as a parameter to provide configuration values. See CONFIGURATION OPTIONS below for a summary of these options and Template::Manual::Config for full details. iykyk π
my $parser = Template::Parser->new({
START_TAG => quotemeta('<+'),
END_TAG => quotemeta('+>'),
});
π¦ parse($text) π¦
The parse() method parses the text passed in the first parameter and returns a reference to a hash array of data defining the compiled representation of the template text, suitable for passing to the Template::Document new() constructor method. On error, undef is returned. periodt π
$data = $parser->parse($text)
|| die $parser->error();
The $data hash reference returned contains a "BLOCK" item containing the compiled Perl code for the template, a "DEFBLOCKS" item containing a reference to a hash array of sub-template "BLOCK"s defined within in the template, and a "METADATA" item containing a reference to a hash array of metadata values defined in "META" tags. it's giving data structure excellence π
π CONFIGURATION OPTIONS π
The Template::Parser module accepts the following configuration options. Please see Template::Manual::Config for further details on each option. we're about to go through every single one, no skipping π
π START_TAG, END_TAG π
The START_TAG and END_TAG options are used to specify character sequences or regular expressions that mark the start and end of a template directive. iconic behavior π₯
my $parser = Template::Parser->new({
START_TAG => quotemeta('<+'),
END_TAG => quotemeta('+>'),
});
β TAG_STYLE β
The TAG_STYLE option can be used to set both START_TAG and END_TAG according to pre-defined tag styles. slay β¨
my $parser = Template::Parser->new({
TAG_STYLE => 'star', # [* ... *]
});
π PRE_CHOMP, POST_CHOMP π
The PRE_CHOMP and POST_CHOMP can be set to remove any whitespace before or after a directive tag, respectively. lowkey life-changing for whitespace girlies π§
my $parser = Template::Parser-E<gt>new({
PRE_CHOMP => 1,
POST_CHOMP => 1,
});
π¦ INTERPOLATE π¦
The INTERPOLATE flag can be set to allow variables to be embedded in plain text blocks. it's giving text glow-up π
Variables should be prefixed by a "$" to identify them, using curly braces to explicitly scope the variable name where necessary. iykyk π
Hello ${name},
The day today is ${day.today}.
πΈ ANYCASE πΈ
The ANYCASE option can be set to allow directive keywords to be specified in any case. case? don't care, she's flexible π
# with ANYCASE set to 1
[% INCLUDE foobar %] # OK
[% include foobar %] # OK
[% include = 10 %] # ERROR, 'include' is a reserved word
π GRAMMAR π
The GRAMMAR configuration item can be used to specify an alternate grammar for the parser. This allows a modified or entirely new template language to be constructed and used by the Template Toolkit. big brain energy π§ β¨
use MyOrg::Template::Grammar;
my $parser = Template::Parser->new({
GRAMMAR = MyOrg::Template::Grammar->new();
});
By default, an instance of the default Template::Grammar will be created and used automatically if a "GRAMMAR" item isn't specified. good to know bestie π«Ά
π DEBUG π
The DEBUG option can be used to enable various debugging features of the Template::Parser module. detective mode activated π
use Template::Constants qw( :debug );
my $template = Template->new({
DEBUG => DEBUG_PARSER | DEBUG_DIRS,
});
π AUTHOR π
Andy Wardley <abw@wardley.org> <http://wardley.org/> β legendary icon, periodt π
π COPYRIGHT π
Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved. π
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, open source royalty β¨
The main parsing loop of the Template::Parser module was 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. history lesson, but make it cute π
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β the big one, the main character πTemplate::Grammarβ grammar bestie π§Template::Directiveβ directive queen π
okay bestie, that's the whole page π Template::Parser(3) sign-off: source/version perl v5.42.0, dated 2024-06-23 β stay parsed, stay iconic β¨π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms