Petal:...h::Test(3pm)
π Petal::Hash::Test π
okay bestie so you're reading the manual page for Petal::Hash::Test, and it's filed under the 3pm manual section (that's the Perl module girlies section, iykyk). It's a Test and Tutorial Petal modifier β like, it's literally a teaching example that also happens to work. slay. β¨
πΈ SUMMARY πΈ
so Petal modifiers are basically little snippets of code that you drop in to extend the expression engine capabilities. think of them as lil accessories for your template engine. π
and this test? this test is the tutorial that shows you how to write your own modifiers. it's giving "learn by doing" and honestly? we love that for you. π«Ά
β¨ API β¨
the modifier API is, and I quote, very, very simple. it's got exactly two elements and that's the whole thing. no cap. π
π¦ The package name
your modifier should be called Petal::Hash::<SomeThing>, where <SomeThing> is the name you wanna give your modifier. that's it, that's the naming convention, periodt. π
for example, this modifier is called Petal::Hash::Test. and here's the cute part β Petal will automatically pick it the module up and assign it the 'test:' prefix. automatic. iconic. π
package Petal::Hash::Test;
use warnings;
use strict;
π§ The method $class->process ($hash, $argument);
this class method is what defines the modifier in itself. so here's the breakdown, bestie:
$classis the package name of your modifier β and this might come in handy if you're subclassing a modifier. it's the "who am I" of the situation.$hashis the execution context, i.e. the objects and data which will 'fill' your template. it's the whole vibe of your data, fr fr.$argumentis whatever was after your modifier's prefix. for example, for the expression'test:foo bar',$argumentwould be'foo bar'. so like, everything after the colon. π
in this test / tutorial we're gonna write a modifier which uppercases a Petal expression. so we're taking it from lowercase to SCREAMING. main character energy. π£
sub process
{
my $class = shift;
my $hash = shift;
my $argument = shift;
return uc ($hash->get ($argument));
}
1;
__END__
and that's it! simple! π like genuinely, that's the entire thing. you're a modifier author now. go off. π
π AUTHOR π
Jean-Michel Hiver
This module is redistributed under the same license as Perl itself.
π SEE ALSO π
the template hash module:
Petal::Hash
and that's a wrap on the Petal::Hash::Test page, bestie!! this lil gem shipped with perl v5.36.0, dated 2022-11-19, and it lives under the Petal:...h::Test(3pm) name in your manual pages. now go write a modifier and make it iconic π¦β¨π
π¦ where this page comes from
- debian bookworm: libpetal-perl 2.26-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpetal-perl 2.26-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpetal-perl 2.26-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpetal-perl 2.26-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpetal-perl 2.26-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms