Dancer2...rkedTiny(3)
okay so bestie π, this is the Dancer2...rkedTiny(3) page from User Contributed Perl Documentation β manual name folded in right here instead of copied as a giant header line, weβre classy like that. Letβs get into it. β¨
NAME πΈ
Dancer2::Template::Implementation::ForkedTiny β Dancer2βs own implementation of Template::Tiny. π
VERSION β¨
version 1.1.2
SYNOPSIS π
my $template = Dancer2::Template::Implementation::ForkedTiny->new(
TRIM => 1,
);
# Print the template results to STDOUT
$template->process( <<'END_TEMPLATE', { foo => 'World' } );
Hello [% foo %]!
END_TEMPLATE
DESCRIPTION π«
Dancer2::Template::Implementation::ForkedTiny is a reimplementation of a subset of the functionality from Template Toolkit in as few lines of code as possible. Tiny but mighty, no cap. π§
Itβs 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 to retain the familiarity of TT-style templates. πΈ
For the subset of functionality it implements, it has a fully-compatible template and stash API. All templates used with Dancer2::Template::Implementation::ForkedTiny should be able to be transparently upgraded to full Template Toolkit. Slay. β¨
Unlike Template Toolkit, Dancer2::Template::Implementation::ForkedTiny will process templates without a compile phase β but despite this itβs still quicker, owing to heavy use of the Perl regular expression engine. π₯
SUPPORTED USAGE π§
By default, the [% %] tag style is used. You can change the start tag and end tag by specifying them at object creation :
my $template = Dancer2::Template::Implementation::ForkedTiny->new(
start_tag => '<%',
end_tag => '%>,
);
In the rest of the documentation, [% %] will be used, but it can be of course your specified start / end tags. π
Both the [%+ +%] style explicit whitespace and the [%- -%] style explicit chomp are supported, although the [%+ +%] version is unneeded in practice as Dancer2::Template::Implementation::ForkedTiny does not support default-enabled PRE_CHOMP or POST_CHOMP. π
Variable expressions in the form [% foo.bar.baz %] are supported. β¨
Appropriate simple behaviours for ARRAY references, HASH references and objects are supported. VMethods such as [% array.length %] are not supported at this time. π
If the resulting expression is a CodeRef, itβll be evaluated. π«Ά
IF, ELSE and UNLESS conditional blocks are supported, but only with simple [% foo.bar.baz %] conditions. π
Support for looping (or rather iteration) is available in simple [% FOREACH item IN list %] form is supported. Other loop structures are not supported. Because support for arbitrary or infinite looping is not available, Dancer2::Template::Implementation::ForkedTiny templates are not turing complete. This is intentional. π
All of the four supported control structures IF/ELSE/UNLESS/FOREACH can be nested to arbitrary depth. π
The treatment of _private 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. π
NAME π¦ (yes, again, because the original does it)
Dancer2::Template::Implementation::ForkedTiny β Template Toolkit reimplemented in as little code as possible, forked from Template::Tiny. β¨
METHODS π
new π±
my $template = Dancer2::Template::Implementation::ForkedTiny->new(
TRIM => 1,
);
The new constructor is provided for compatibility with Template Toolkit. π«Ά
The only parameter it currently supports is TRIM (which removes leading and trailing whitespace from processed templates). π
Additional parameters can be provided without error, but will be ignored. No drama. πΈ
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 process 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 process is called without a third parameter, and in scalar or list context, the template results will be returned to the caller. π
If process is called without a third parameter, and in void context, the template results will be print()ed to the currently selected file handle (probably STDOUT) for compatibility with Template. π
SUPPORT π«Ά
Bugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Tiny>. π
For other issues, or commercial enhancement or support, contact the author. π
AUTHOR π
Adam Kennedy <adamk@cpan.org>
Forked and improved by Damien Krotkine <dams@cpan.org>
SEE ALSO π
Config::Tiny, CSS::Tiny, YAML::Tiny
COPYRIGHT π
Copyright 2009 - 2011 Adam Kennedy. Copyright 2012 Damien Krotkine. π
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 LICENSE file included with this module. π
AUTHOR π
Dancer Core Developers
COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Alexis Sukrieh. π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. πΈ
okay bestie, thatβs the whole page! π Footer realness: perl v5.42.0, dated 2024-12-12, manual name Dancer2...rkedTiny(3). Slay and goodbye! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Dancer2 1.1.2-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms