Templat...nstants(3)
π Template::Namespace::Constants(3) β the manual page, bestie edition β¨
okay so real talk, the fancy-pants full title of this page is Template::Namespace::Constants(3), from the User Contributed Perl Documentation corner of the internet π«Ά and it's lowkey one of those little modules that does something kind of iconic.
β¨ NAME β¨
Template::Namespace::Constants β compile time constant folding. that's it, that's the whole vibe π«
π SYNOPSIS π
so there's the easy way, and then there's the nitty-gritty hands-dirty way. both are valid, bestie, we don't judge π
the easy way to define constants:
# easy way to define constants
use Template;
my $tt = Template->new({
CONSTANTS => {
pi => 3.14,
e => 2.718,
},
});
and the nitty-gritty, hands-dirty way:
# nitty-gritty, hands-dirty way
use Template::Namespace::Constants;
my $tt = Template->new({
NAMESPACE => {
constants => Template::Namespace::Constants->new({
pi => 3.14,
e => 2.718,
},
},
});
no cap, they're doing the same job β one's just wearing a cuter outfit πΈ
π¦ DESCRIPTION π¦
so the Template::Namespace::Constants module implements a namespace handler (main character energy, honestly π) which gets plugged into the Template::Directive compiler module. and then? it performs compile time constant folding of variables in a particular namespace. yes. that. it ate and left no crumbs π₯
β METHODS β
new(\%constants)
the new() constructor method creates and returns a reference to a brand-new Template::Namespace::Constants object, periodt π it also sets up an internal stash to store all the constant variable definitions you passed in as arguments. like a little purse for your constants, iykyk π
my $handler = Template::Namespace::Constants->new({
pi => 3.14,
e => 2.718,
});
ident(\@ident)
this is the method that gets called to resolve a variable identifier into a compiled form β¨ and in this case? the method fetches the corresponding constant value out of its internal stash and returns it. literally that simple, no drama, we love a clean return π
π AUTHOR π
Andy Wardley <abw@wardley.org> <http://wardley.org/> β legend behavior fr fr π
π 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 π
okay but actually read that license bit, bestie β it's the real deal, not just cute decoration πΈ
π§ SEE ALSO π§
Template::Directive β go look, it's the whole reason this module gets to shine β¨
and that's the whole page, bestie!! π this was perl v5.42.0, dated 2024-06-23, and yes the footer still calls it Templat...nstants(3) because truncation is a lifestyle ππ«Ά mwah, go fold some constants π
π¦ 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