HTML::...uggable(3pm)

πŸ“¦
version 0.22+~cs0.7 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ HTML::Template::Pluggable ✨

okay bestie, so this is HTML::Template::Pluggable β€” it's the module that extends HTML::Template with plugin support. that's the whole name-and-purpose situation, we love a clear thesis πŸ’…

(also it lives in the User Contributed Perl Documentation section of the manual, iykyk.)


🌸 SYNOPSIS 🌸

the vibe here is stupidly simple: literally just use this module instead of HTML::Template, then use any plugins you want, and go on with your life. that's it. that's the whole thing. no cap.

use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;

# Everything works the same, except for functionality that plugins add.
my $t = HTML::Template::Pluggable->new();

like, everything works the same except the extra stuff your plugins add. iconic behaviour honestly.


🎯 THE GOAL

ideally?? we'd love to see this functionality merged straight into HTML::Template, and turn this module into a null sub-class. that's the dream. the endgame. the final form πŸ¦‹


πŸ“Œ STATUS

okay so real talk, the design of the plugin system is still in progress. right now we have just two triggers, in param and output. the name and function of these may change, and we'd like to add triggers in new() and other methods when the need arises.

the one promise we're making for now: keep HTML::Template::Plugin::Dot compatible. periodt.

πŸ’Œ if you've got suggestions with feedback on designing the plugin system and you'd like to contribute β€” please get in touch. we want to hear it fr fr.

πŸ› οΈ WRITING PLUGINS

so HTML::Template offers a plugin system which lets developers extend the functionality in significant ways without creating a sub-class β€” because a sub-class might be impossible to use in combination with another sub-class extension. yeah. that's the whole reason this exists, bestie.

currently, two triggers have been made available to alter how the values of TMPL_VARs are set. if more hooks are needed to implement your own plugin idea, it may be feasible to add them β€” so check the FAQ then ask about it on the list.

Class::Trigger is used to provide plugins. basically, you can just:

HTML::Template->add_trigger('middle_param', \&trigger);

a good place to add one is in your plugin's import subroutine:

package HTML::Template::Plugin::MyPlugin;
use base 'Exporter';
sub import {
    HTML::Template->add_trigger('middle_param', \&dot_notation);
    goto &Exporter::import;
}

look at that. chef's kiss πŸŽ€

πŸ” TRIGGER LOCATIONS

param

we've added one trigger location to this method, named "middle_param".

# in a Plugin's import() routine.
HTML::Template->add_trigger('middle_param',   \&_set_tmpl_var_with_dot  );

this sets a callback which is executed in param() with all of the same arguments. heads up tho β€” it's only useful for altering how /setting/ params works. the logic to read a param is unaffected. don't come for it.

it can set any TMPL_VAR values before the normal param logic kicks in. to do that, $self->{param_map} is modified, as can be seen from source in HTML::Template::param(). however β€” and this is the important part β€” it must obey the following convention of setting $self->{param_map_done}{$param_name} for each param that is set. $param_name would be a key from $self->{param_map}. this notifies the other plugins and the core param() routine to skip trying to set this value. πŸ’«

and $self->{param_map_done} is reset with each call to param(), so that β€” like with a hash β€” you have the option to reset a param later with the same name. slay.

output

one trigger location here: "before_output".

HTML::Template->add_trigger('before_output',   \&_last_chance_params  );

this sets a callback which is executed right before output is generated. last chance, bestie 🫢


πŸ‘€ SEE ALSO

  • HTML::Template::Plugin::Dot β€” add Template Toolkit's magic dot notation to HTML::Template. obsessed.

πŸ‘‘ AUTHOR

Mark Stosberg, "<mark@summersault.com>" β€” the icon, the moment, the main character.


πŸ› BUGS

please report any bugs or feature requests to "bug-html-template-pluggable@rt.cpan.org", or through the web interface at http://rt.cpan.org. i will be notified, and then you'll automatically be notified of progress on your bug as i make changes. we love a feedback loop πŸ’–


Copyright 2006 Mark Stosberg, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie!! this little manual page came to you via perl v5.38.2, dated 2024-03-30, filed under HTML::...uggable(3pm) in the User Contributed Perl Documentation. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from