NAME
Template::Teeny - Teeny-weeny templating system
VERSION
Version 0.00_002
SYNOPSIS
use Template::Teeny;
my $tt = Template::Teeny->new({
include_path => ['foo/templates']
});
my $stash = Template::Teeny->new({
a => 1, b => 2, c => 3
});
$stash->add_section('items', $item1);
$stash->add_section('items', $item2);
$tt->process('foo.html', $stash);
DESCRIPTION
Template::Teeny is a more perlish implementation of the concepts in googles ctemplate library. The template syntax does not have any conditionals or looping directly.
A basic template would look like so:
Hi [% name %],
You ordered the following:
[% SECTION items %]
Title: [% title %]
Date: [% date %]
Identifier: [% id | uc %]
[% INCLUDE 'full_description.txt' %]
[% END %]
When processing the template, we supply a stash object which contains all the variables for processing.
- [% name %]
-
This pulls variables directly from the current stash.
- [% SECTION items %]
-
The current stash may have other stashes associated with it by name
$stash->add_section('foo', $other_stash);
This would then would run the SECTION block with $other_stash as its stash.
- [% id | uc %]
-
TODO - This still need implemented
This is a variable which will be run through the filter 'uc' before being output. These filters can be chained.
- [% INCLUDE 'full_description.txt %]
-
TODO - This still need implemented
This will pull in the template from the file 'full_description.txt'
- [% END %]
-
This simply marks the end of a section.
Why yet another templating system?
There are a multitude of different templating systems out there, so what makes this one so different? The aim of this system is to move all business logic out of the templates and back into the code where it belongs. This means that the templating becomes very lightweight and fast.
The Google CTemplate library is a great example of this approach, however I had attempted to bind this to perl and unfortunately was unable to make it work correctly enough for production use.
I aim to have a fully working perl version and further down the line implement a full C version with XS bindings. Other than that, I wanted to have a try at writing parsers/compilers for fun.
METHODS
process
$tt->process('foo/bar/baz.tpl', $stash);
This method takes a template file name and a stash object to be processed.
parse
$tt->parse('[% foo %]');
Takes a string representing the template. Returns an AST.
compile
my $eval_string = $tt->compile( ...<AST>... );
This method take a generated AST and translates it into an eval-able string of perl code.
include_path
This is an accessor for the template include path.
AUTHOR
Scott McWhirter, <konobi at cpan.org>
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Template::Teeny
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2008 Scott McWhirter, all rights reserved.
This program is released under the following license: BSD