Skip to content

Instantly share code, notes, and snippets.

@b-abctech
Created December 12, 2013 16:41
Show Gist options
  • Save b-abctech/7931035 to your computer and use it in GitHub Desktop.
Save b-abctech/7931035 to your computer and use it in GitHub Desktop.
Simple sample to create template plugins
# this example based on module to do html/text truncate
# the Template plugin package
package Template::Plugin::TextTruncater;
use warnings;
use strict;
use utf8;
use DateTime;
use Moose;
use MooseX::NonMoose;
extends 'Template::Plugin';
sub BUILDARGS {
}
sub truncater {
my ( $self ) = @_;
return sub {
my $text = shift;
return '-' unless $text;
return "message from plugin";
};
}
1;
# the in template just use and initial its
[% USE TextTruncater; %]
[% SET tc = TextTruncater.truncater(); %]
[% tc('my message') %]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment