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 (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