lib/Template/Benchmark/Engines/TemplateToolkit.pm

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