lib/Template/Benchmark/Engines/TemplateAlloyTT.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Template/Benchmark/Engines/TemplateAlloyHT.pm ↑ Summary lib/Template/Benchmark/Engines/TemplateSandbox.pm »
1 package Template::Benchmark::Engines::TemplateAlloyTT;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw/Template::Benchmark::Engine/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶use Template::Alloy;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 our $VERSION = '1.09_01';
11  
12 our %feature_syntaxes = (
13 literal_text =>
14 join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ),
15 scalar_variable =>
16 '[% scalar_variable %]',
17 hash_variable_value =>
18 '[% hash_variable.hash_value_key %]',
19 array_variable_value =>
20 '[% array_variable.2 %]',
21 deep_data_structure_value =>
22 '[% this.is.a.very.deep.hash.structure %]',
23 array_loop_value =>
24 '[% FOREACH i IN array_loop %][% i %][% END %]',
25 # TODO: ordering?
26 hash_loop_value =>
27 '[% FOREACH k IN hash_loop %][% k.key %]: ' .
28 '[% k.value %][% END %]',
29 records_loop_value =>
30 '[% FOREACH r IN records_loop %][% r.name %]: ' .
31 '[% r.age %][% END %]',
32 array_loop_template =>
33 '[% FOREACH i IN array_loop %][% i %][% END %]',
34 # TODO: ordering?
35 hash_loop_template =>
36 '[% FOREACH k IN hash_loop %][% k.key %]: ' .
37 '[% k.value %][% END %]',
38 records_loop_template =>
39 '[% FOREACH r IN records_loop %][% r.name %]: ' .
40 '[% r.age %][% END %]',
41 constant_if_literal =>
42 '[% IF 1 %]true[% END %]',
43 variable_if_literal =>
44 '[% IF variable_if %]true[% END %]',
45 constant_if_else_literal =>
46 '[% IF 1 %]true[% ELSE %]false[% END %]',
47 variable_if_else_literal =>
48 '[% IF variable_if_else %]true[% ELSE %]false[% END %]',
49 constant_if_template =>
50 '[% IF 1 %][% template_if_true %][% END %]',
51 variable_if_template =>
52 '[% IF variable_if %][% template_if_true %][% END %]',
53 constant_if_else_template =>
54 '[% IF 1 %][% template_if_true %][% ELSE %]' .
55 '[% template_if_false %][% END %]',
56 variable_if_else_template =>
57 '[% IF variable_if_else %][% template_if_true %][% ELSE %]' .
58 '[% template_if_false %][% END %]',
59 constant_expression =>
60 '[% 10 + 12 %]',
61 variable_expression =>
62 '[% variable_expression_a * variable_expression_b %]',
63 complex_variable_expression =>
64 '[% ( ( variable_expression_a * variable_expression_b ) + ' .
65 'variable_expression_a - variable_expression_b ) / ' .
66 'variable_expression_b %]',
67 constant_function =>
68 # TODO: Hmm, this doesn't work, ideas anyone?
69 # q{[% 'this has a substring.'.substr( 11, 9 ) %]},
70 undef,
71 variable_function =>
72 '[% variable_function_arg.substr( 4, 2 ) %]',
73 );
74  
75 sub syntax_type { return( 'mini-language' ); }
76 sub pure_perl { return( 1 ); }
77  
78 sub benchmark_descriptions
79 {
80 return( {
81 TATT =>
82 "Template::Alloy ($Template::Alloy::VERSION) in " .
83 "Template::Toolkit mode",
84 TATT_S =>
85 "Template::Alloy ($Template::Alloy::VERSION) in " .
86 "Template::Toolkit mode (using process_simple())",
87 TATT_P =>
88 "Template::Alloy ($Template::Alloy::VERSION) in " .
89 "Template::Toolkit mode (compile to perl)",
90 TATT_PS =>
91 "Template::Alloy ($Template::Alloy::VERSION) in " .
92 "Template::Toolkit mode (compile to perl, using process_simple())",
93 } );
94 }
95  
96 sub benchmark_functions_for_uncached_string
97 {
98 my ( $self ) = @_;
99  
100 return( {
101 TATT =>
102 sub
103 {
104 my $t = Template::Alloy->new(
105 VARIABLES => $_[ 1 ],
106 CACHE_STR_REFS => 0,
107 );
108 my $out = '';
109 $t->process( \$_[ 0 ], $_[ 2 ], \$out );
110 \$out;
111 },
112 } );
113 }
114  
115 sub benchmark_functions_for_uncached_disk
116 {
117 my ( $self, $template_dir ) = @_;
118  
119 return( undef );
120 }
121  
122 sub benchmark_functions_for_disk_cache
123 {
124 my ( $self, $template_dir, $cache_dir ) = @_;
125 my ( @template_dirs );
126  
127 @template_dirs = ( $template_dir );
128  
129 return( {
130 TATT =>
131 sub
132 {
133 my $t = Template::Alloy->new(
134 VARIABLES => $_[ 1 ],
135 INCLUDE_PATH => \@template_dirs,
136 COMPILE_DIR => $cache_dir,
137 );
138 my $out = '';
139 $t->process( $_[ 0 ], $_[ 2 ], \$out );
140 \$out;
141 },
142 TATT_S =>
143 sub
144 {
145 my $t = Template::Alloy->new(
146 INCLUDE_PATH => \@template_dirs,
147 COMPILE_DIR => $cache_dir,
148 );
149 my $out = '';
150 $t->process_simple( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} },
151 \$out );
152 \$out;
153 },
154 TATT_P =>
155 sub
156 {
157 my $t = Template::Alloy->new(
158 VARIABLES => $_[ 1 ],
159 INCLUDE_PATH => \@template_dirs,
160 COMPILE_DIR => $cache_dir,
161 COMPILE_PERL => 1,
162 );
163 my $out = '';
164 $t->process( $_[ 0 ], $_[ 2 ], \$out );
165 \$out;
166 },
167 TATT_PS =>
168 sub
169 {
170 my $t = Template::Alloy->new(
171 INCLUDE_PATH => \@template_dirs,
172 COMPILE_DIR => $cache_dir,
173 COMPILE_PERL => 1,
174 );
175 my $out = '';
176 $t->process_simple( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} },
177 \$out );
178 \$out;
179 },
180 } );
181 }
182  
183 sub benchmark_functions_for_shared_memory_cache
184 {
185 my ( $self, $template_dir, $cache_dir ) = @_;
186  
187 return( undef );
188 }
189  
190 sub benchmark_functions_for_memory_cache
191 {
192 my ( $self, $template_dir, $cache_dir ) = @_;
193  
194 return( undef );
195 }
196  
197 sub benchmark_functions_for_instance_reuse
198 {
199 my ( $self, $template_dir, $cache_dir ) = @_;
200 my ( $ta, $ta_s, $ta_p, $ta_ps, @template_dirs );
201  
202 @template_dirs = ( $template_dir );
203  
204 $ta = Template::Alloy->new(
205 INCLUDE_PATH => \@template_dirs,
206 COMPILE_DIR => $cache_dir,
207 );
208 $ta_s = Template::Alloy->new(
209 INCLUDE_PATH => \@template_dirs,
210 COMPILE_DIR => $cache_dir,
211 );
212 $ta_p = Template::Alloy->new(
213 INCLUDE_PATH => \@template_dirs,
214 COMPILE_DIR => $cache_dir,
215 COMPILE_PERL => 1,
216 );
217 $ta_ps = Template::Alloy->new(
218 INCLUDE_PATH => \@template_dirs,
219 COMPILE_DIR => $cache_dir,
220 COMPILE_PERL => 1,
221 );
222  
223 return( {
224 TATT =>
225 sub
226 {
227 my $out = '';
228 $ta->process( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} }, \$out );
229 \$out;
230 },
231 TATT_S =>
232 sub
233 {
234 my $out = '';
235 $ta_s->process_simple( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} },
236 \$out );
237 \$out;
238 },
239 TATT_P =>
240 sub
241 {
242 my $out = '';
243 $ta_p->process( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} }, \$out );
244 \$out;
245 },
246 TATT_PS =>
247 sub
248 {
249 my $out = '';
250 $ta_ps->process_simple( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} },
251 \$out );
252 \$out;
253 },
254 } );
255 }
256  
257 1;
258  
259 __END__
« lib/Template/Benchmark/Engines/TemplateAlloyHT.pm ↑ Summary lib/Template/Benchmark/Engines/TemplateSandbox.pm »