This page describes how to attach custom processing handlers on the Plift template engine.
Besides the data interpolation feature, the Plift engine has just one core funcionality that is to search the HTML document using registered xpath expressions and triggering the associated subroutines.
A handler is just a perl subroutine bound to a xpath expression, usualy targgeting a element or attribute (like <x-include> or data-plift-include).
<x-include>
data-plift-include
The following example attaches a handler to the HTML <head> element:
<head>
$plift->add_handler({ name => 'head_example', tag => 'head', handler => sub { my ($head_element, $context) = @_; # do you custom processing on the <head> element: # - add SEO metadata? # - process asset files? # - add tracking code? } });
I encourage you to read the source of the builtin handlers. They are very simple, just a few lines of code.
To install Plift, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plift
CPAN shell
perl -MCPAN -e shell install Plift
For more information on module installation, please visit the detailed CPAN module installation guide.