http://qs1969.pair.com?node_id=1143767


in reply to Re: Template Toolkit custom plugins?
in thread Template Toolkit custom plugins?

I just wanted some different examples of types of plugin usage, the documentation is a little sparse on cookbook examples. My example:
package MyHungryHippo; use strict; use warnings; use 5.16.0; use base qw[Template::Plugin]; sub new { my ($class, $context) = @_; return bless { _context => $context }, $class; } sub nomnom { my $self = shift; return 'eat it'; } 1; package main; use strict; use warnings; use 5.16.0; use Test::More; use_ok 'MyHungryHippo'; use_ok 'Template'; ok my $tt = Template->new({ PLUGINS => { 'HIPPO' => 'MyHungryHippo' } +}); die $tt->error if $tt->error; ok my $tmpl = join('', <DATA>); ok my $output = $tt->context->process( \$tmpl, {} ); like $output, qr/eat/ or diag $output; done_testing(); __DATA__ [% USE HIPPO %] [%- HIPPO.nomnom() -%]

Replies are listed 'Best First'.
Re^3: Template Toolkit custom plugins?
by perlron (Pilgrim) on Oct 05, 2015 at 09:07 UTC

    Hi, Here's an older example of TT usage from merlyn.
    -update-
    Here's another one from the Twiki site, where i see Plugins have a separate Home page .

    Ask not what good Perl n country have done for you, Ask what good you will do for Perl n country