Templat...Context(3)
okay bestie π this is the Templat...Context(3) page, a User Contributed Perl Documentation moment, and we're talking about Template::Stash::Context.
πΈ NAME πΈ
Template::Stash::Context - Experimetal stash allowing list/scalar context definition. Yes, "Experimetal" is literally how it's spelled in the NAME line β no cap, we keep the typo π«Ά.
β¨ SYNOPSIS β¨
use Template;
use Template::Stash::Context;
my $stash = Template::Stash::Context->new(\%vars);
my $tt2 = Template->new({ STASH => $stash });
π DESCRIPTION π
Okay so this is an alternate stash object that includes a patch from Craig Barratt to implement various new virtual methods. The glow-up? It lets a dotted template variable say whether object methods and subroutines should be called in scalar context or list context. It adds a little overhead to each stash call, and the author is a little wary of applying that to the core default stash without investigating the effects first. So for now it's implemented as a separate stash module, which will allow us to test it out, benchmark it and switch it in or out as we require. Slay, honestly β¨.
This is what Craig has to say about it:
Here's a better set of features for the core. Attached is a new version of Stash.pm (based on TT2.02) that:
- supports the special op
"scalar"that forces scalar context on function calls, eg:
cgi.param("foo").scalar
calls cgi.param("foo") in scalar context (unlike my wimpy scalar op from last night). Array context is the default.
With non-function operands, scalar behaves like the perl version (eg: no-op for scalar, size for arrays, etc).
- supports the special op
"ref"that behaves like the perlref. If applied to a function the function is not called. Eg:
cgi.param("foo").ref
does not call cgi.param and evaluates to "CODE". Similarly, HASH.ref, ARRAY.ref return what you expect.
- adds a new scalar and list op called
"array"that is a no-op for arrays and promotes scalars to one-element arrays. - allows scalar ops to be applied to arrays and hashes in place, eg:
ARRAY.repeat(3)repeats each element in place. - allows list ops to be applied to scalars by promoting the scalars to one-element arrays (like an implicit
"array"). So you can do things likeSCALAR.size,SCALAR.joinand get a useful result.
This also means you can now use x.0 to safely get the first element whether x is an array or scalar.
The new Stash.pm passes the TT2.02 test suite. But I haven't tested the new features very much. One nagging implementation problem is that the "scalar" and "ref" ops have higher precedence than user variable names.
π¦ AUTHOR π¦
Andy Wardley <abw@wardley.org>
π VERSION π
1.63, distributed as part of the Template Toolkit version 3.100, released on 30 March 2020.
π 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.
π SEE ALSO π
Template::Stash
byeee bestie π
this page is from perl v5.42.0, dated 2024-06-23, and its footer tag is Templat...Context(3) π«Ά
π¦ 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