Caleb Cushing's Blog Also known as XenoTerraCide
Posts with the tag Template Toolkit:

Annoucing Template::Plugin::Haml

A few months ago we had an assignment in Web Server Admin to create a CGI page, of course the perl was just to print text not actually do anything more, but I decided to use CGI.pmjust because I never had. The whole thing was nothing more than hello world.#!/usr/bin/env perluse 5.012;use CGI qw(:standard);say header,start_html(‘hello world’),h1(‘hello world’),end_html;and I thought, wow I can write all that html with just that? why can’t I use that syntax as a templating language.

Using ref to fix 5 year old bug

So I haven’t been hacking perl for 5 (or more) years but I forked Template::ShowStartStop from Template::Timer which is that old. since I forked it this test has bugged me since I didn’t really understand the test, the section of code it referred to or the actual problem. This is an approximation of the error you’d get. Couldn’t render template “undef error - Can’t call method “name” on unblessed reference at /usr/lib/perl5/site_perl/5.

Testing TT Template's

So the poorly made patch the other day converted my Test::More test to use Template::Testwhich removed quite a bit of code from the test itself. I hadn’t seen Template::Test beforehand.Here’s a very simple example of a test you could write to make sure a template is being output ok.#!perluse strict;use warnings;use Template::Test;my $tt = Template->new();my $vars = {var => ‘world’,};test_expect(*DATA, $tt, $vars);DATA–test–hello [% var %]–expect–hello worldIf you want more examples I now have quite a few for Template::ShowStartStopwhich you can see in the Test directory of the master branch.