Creating synergy throughout the world by bringing harmonious designs and interfaces into a collaborative space that resides between what users want and also giving people what they need.
Also, a templating system that allows you to embed perl6. EVAL
s your templates into a callable sub and caches them for later use, if you want.
- Don't match a closer embedded in quotes
- Make the opener escapable
- Run template sub in a space where custom functions are available to the template
- Save template sub to a file so it doesn't need to be rebuilt every time app is restarted
use Template::Protone;
my Template::Protone $templ .= new;
$templ.parse(template => [q|
Hello <% print "WORLD!"; %>
Oh, did you want variables too? I can do <% print $data<what>; %> too.
<% for ^3 { %>
<% print $_ ~ ($_ == 2 ?? '' !! ', '); %>
<% } %>
|], :name<example>);
say $templ.render(:name<example>, :data(what => 'that'));
Hello WORLD!
Oh, did you want variables too? I can do that too.
0, 1, 2
qw<...>;
use Template::Protone;
my Template::Protone $templ .= new(:open('%%'), :close("%%"));
say $templ.render(template => [q|
Hello %% print "WORLD!"; %%
List: %% for ^3 {
print $_ ~ ($_ == 2 ?? '' !! ', ');
} %%
|]);
qw<...>;
Hello WORLD!
List: 0, 1, 2
Yea, yea, but how fast does your car go
$ perl6 -Ilib bench.pl6; perl6 -Iblib/lib bench.pl6
Benchmark:
Timing 1000 iterations of parsing, render...
parsing: 11.5185 wallclock secs @ 86.8168/s (n=1000)
render: 0.1311 wallclock secs @ 7629.1286/s (n=1000)
Benchmark:
Timing 1000 iterations of parsing, render...
parsing: 11.4190 wallclock secs @ 87.5737/s (n=1000)
render: 0.1288 wallclock secs @ 7762.4681/s (n=1000)
Tony O'Dell
You can use and distribute this module under the terms of the The Artistic License 2.0.
See the LICENSE
file included in this distribution for complete details.