Petal:...h::Test(3pm)

πŸ“¦
version 2.26 Β· 2 versions
  • 2.26 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.26 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  • $class is 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.
  • $hash is the execution context, i.e. the objects and data which will 'fill' your template. it's the whole vibe of your data, fr fr.
  • $argument is whatever was after your modifier's prefix. for example, for the expression 'test:foo bar', $argument would 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