1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# -*-perl-*-
# run with perl -d:DProf $0 ; dprofpp
use strict;
use POSIX qw(tmpnam);
use File::Path qw(rmtree);
use Template::Alloy;
#use Template::Alloy_60;
my $tt_cache_dir = tmpnam;
END { rmtree $tt_cache_dir };
mkdir $tt_cache_dir, 0755;
my $cet = Template::Alloy->new(ABSOLUTE => 1);
#use Template;
#my $cet = Template->new(ABSOLUTE => 1);
###----------------------------------------------------------------###
my $swap = {
one => "ONE",
two => "TWO",
three => "THREE",
a_var => "a",
hash => {a => 1, b => 2, c => { d => ["hmm"] }},
array => [qw(A B C D E a A)],
code => sub {"($_[0])"},
cet => $cet,
};
my $txt = '';
$txt .= "[% one %]\n";
$txt .= ((" "x1000)."[% one %]\n")x100;
$txt .= "[%f=10; WHILE (g=f) ; f = f - 1 ; f ; END %]";
$txt .= ("[% \"".(" "x10)."\$one\" %]\n")x1000;
my $file = \$txt;
if (1) {
$file = $tt_cache_dir .'/template.txt';
open(my $fh, ">$file") || die "Couldn't open $file: $!";
print $fh $txt;
close $fh;
}
###----------------------------------------------------------------###
sub cet {
my $out = '';
$cet->process($file, $swap, \$out);
return $out;
}
cet() for 1 .. 500;
|