SYNOPSIS

  my $template = Template::Tiny->new(
      TRIM => 1,
  );

  # Print the template results to STDOUT
  $template->process( <<'END_TEMPLATE', { foo => 'World' } );
  Hello [% foo %]!
  END_TEMPLATE

DESCRIPTION

Template::Tiny is a reimplementation of a subset of the functionality from Template Toolkit in as few lines of code as possible.

It is intended for use in light-usage, low-memory, or low-cpu templating situations, where you may need to upgrade to the full feature set in the future, or if you want the retain the familiarity of TT-style templates.

For the subset of functionality it implements, it has fully-compatible template and stash \s-1API\s0. All templates used with Template::Tiny should be able to be transparently upgraded to full Template Toolkit.

Unlike Template Toolkit, Template::Tiny will process templates without a compile phase (but despite this is still quicker, owing to heavy use of the Perl regular expression engine.

\s-1SUPPORTED\s0 \s-1USAGE\s0

Only the default \*(C`[% %]\*(C' tag style is supported.

Both the \*(C`[%+ +%]\*(C' style explicit whitespace and the \*(C`[%- -%]\*(C' style explicit chomp are support, although the \*(C`[%+ +%]\*(C' version is unneeded in practice as Template::Tiny does not support default-enabled \*(C`PRE_CHOMP\*(C' or \*(C`POST_CHOMP\*(C'.

Variable expressions in the form \*(C`[% foo.bar.baz %]\*(C' are supported.

Appropriate simple behaviours for \*(C`ARRAY\*(C' references, \*(C`HASH\*(C' references and objects are supported. \*(L"VMethods\*(R" such as [% array.length %] are not supported at this time.

\*(C`IF\*(C', \*(C`ELSE\*(C' and \*(C`UNLESS\*(C' conditional blocks are supported, but only with simple \*(C`[% foo.bar.baz %]\*(C' conditions.

Support for looping (or rather iteration) is available in simple \*(C`[% FOREACH item IN list %]\*(C' form is supported. Other loop structures are not supported. Because support for arbitrary or infinite looping is not available, Template::Tiny templates are not turing complete. This is intentional.

All of the four supported control structures \*(C`IF\*(C'/\*(C`ELSE\*(C'/\*(C`UNLESS\*(C'/\*(C`FOREACH\*(C' can be nested to arbitrary depth.

The treatment of \*(C`_private\*(C' hash and method keys is compatible with Template Toolkit, returning null or false rather than the actual content of the hash key or method.

Anything beyond the above is currently out of scope.

METHODS

new

my $template = Template::Tiny->new( TRIM => 1, );

The \*(C`new\*(C' constructor is provided for compatibility with Template Toolkit.

The only parameter it currently supports is \*(C`TRIM\*(C' (which removes leading and trailing whitespace from processed templates).

Additional parameters can be provided without error, but will be ignored.

process

# DEPRECATED: Return template results (emits a warning) my $text = $template->process( \$input, $vars );

# Print template results to STDOUT $template->process( \$input, $vars );

# Generate template results into a variable my $output = ''; $template->process( \$input, $vars, \$output );

The \*(C`process\*(C' method is called to process a template.

The first parameter is a reference to a text string containing the template text. A reference to a hash may be passed as the second parameter containing definitions of template variables.

If a third parameter is provided, it must be a scalar reference to be populated with the output of the template.

For a limited amount of time, the old deprecated interface will continue to be supported. If \*(C`process\*(C' is called without a third parameter, and in scalar or list contest, the template results will be returned to the caller.

If \*(C`process\*(C' is called without a third parameter, and in void context, the template results will be \*(C`print()\*(C'ed to the currently selected file handle (probably \*(C`STDOUT\*(C') for compatibility with Template.

SUPPORT

Bugs should be reported via the \s-1CPAN\s0 bug tracker at

http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Tiny <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Tiny>

For other issues, or commercial enhancement or support, contact the author.

AUTHOR

Adam Kennedy <[email protected]>

RELATED TO Template::Tiny…

Config::Tiny, CSS::Tiny, YAML::Tiny

COPYRIGHT

Copyright 2009 - 2011 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the \s-1LICENSE\s0 file included with this module.