lib/Template/Benchmark/Engines/TextTmpl.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/TextTemplet.pm ↑ Summary lib/Template/Benchmark/Engines/TextXslate.pm »
1 package Template::Benchmark::Engines::TextTmpl;
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 Text::Tmpl;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 use File::Spec;
11  
12 our $VERSION = '1.09_01';
13  
14 our %feature_syntaxes = (
15 literal_text =>
16 join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ),
17 scalar_variable =>
18 '<!-- echo $scalar_variable -->',
19 hash_variable_value =>
20 undef,
21 array_variable_value =>
22 undef,
23 deep_data_structure_value =>
24 undef,
25 array_loop_value =>
26 '<!-- loop "array_loop" --><!-- echo $value --><!-- endloop -->',
27 hash_loop_value =>
28 '<!-- loop "hash_loop" --><!-- echo $key -->: <!-- echo $value --><!-- endloop -->',
29 records_loop_value =>
30 '<!-- loop "records_loop" --><!-- echo $name -->: <!-- echo $age --><!-- endloop -->',
31 array_loop_template =>
32 '<!-- loop "array_loop" --><!-- echo $value --><!-- endloop -->',
33 hash_loop_template =>
34 '<!-- loop "hash_loop" --><!-- echo $key -->: <!-- echo $value --><!-- endloop -->',
35 records_loop_template =>
36 '<!-- loop "records_loop" --><!-- echo $name -->: <!-- echo $age --><!-- endloop -->',
37 constant_if_literal =>
38 undef,
39 variable_if_literal =>
40 '<!-- if $variable_if -->true<!-- endif -->',
41 constant_if_else_literal =>
42 undef,
43 variable_if_else_literal =>
44 '<!-- if $variable_if_else -->true<!-- endif -->' .
45 '<!-- ifn $variable_if_else -->false<!-- endifn -->',
46 constant_if_template =>
47 undef,
48 variable_if_template =>
49 '<!-- if $variable_if -->' .
50 '<!-- echo $template_if_true -->' .
51 '<!-- endif -->',
52 constant_if_else_template =>
53 undef,
54 variable_if_else_template =>
55 '<!-- if $variable_if_else -->' .
56 '<!-- echo $template_if_true -->' .
57 '<!-- endif -->' .
58 '<!-- ifn $variable_if_else -->' .
59 '<!-- echo $template_if_false-->' .
60 '<!-- endifn -->',
61 constant_expression =>
62 undef,
63 variable_expression =>
64 undef,
65 complex_variable_expression =>
66 undef,
67 constant_function =>
68 undef,
69 variable_function =>
70 undef,
71 );
72  
73 sub syntax_type { return( 'mini-language' ); }
74 sub pure_perl { return( 0 ); }
75  
76 sub benchmark_descriptions
77 {
78 return( {
79 TeTmpl =>
80 "Text::Tmpl ($Text::Tmpl::VERSION)",
81 } );
82 }
83  
84 sub benchmark_functions_for_uncached_string
85 {
86 my ( $self ) = @_;
87  
88 return( {
89 TeTmpl =>
90 sub
91 {
92 my $t = Text::Tmpl->new();
93 my $h = { %{$_[ 1 ]}, %{$_[ 2 ]} };
94 # Somewhat unfair since we cause the transform hit even
95 # if we're not benchmarking this feature, then again, everyone
96 # else has to store it in their stash too.
97 foreach my $value ( @{$h->{ array_loop }} )
98 {
99 $t->loop_iteration( 'array_loop' )->set_values(
100 { value => $value } );
101 }
102 foreach my $key ( sort( keys( %{$h->{ hash_loop }} ) ) )
103 {
104 $t->loop_iteration( 'hash_loop' )->set_values(
105 { key => $key, value => $h->{ hash_loop }{ $key } } );
106 }
107 foreach my $record ( @{$h->{ records_loop }} )
108 {
109 $t->loop_iteration( 'records_loop' )->set_values(
110 $record );
111 }
112 $t->set_values( $h );
113 $t->set_delimiters( '<!--', '-->' );
114 $t->set_strip( 0 );
115 \$t->parse_string( $_[ 0 ] );
116 },
117 } );
118 }
119  
120 sub benchmark_functions_for_uncached_disk
121 {
122 my ( $self, $template_dir ) = @_;
123  
124 $template_dir .= '/';
125  
126 return( {
127 TeTmpl =>
128 sub
129 {
130 my $t = Text::Tmpl->new();
131 my $h = { %{$_[ 1 ]}, %{$_[ 2 ]} };
132 # Somewhat unfair since we cause the transform hit even
133 # if we're not benchmarking this feature, then again, everyone
134 # else has to store it in their stash too.
135 foreach my $value ( @{$h->{ array_loop }} )
136 {
137 $t->loop_iteration( 'array_loop' )->set_values(
138 { value => $value } );
139 }
140 foreach my $key ( sort( keys( %{$h->{ hash_loop }} ) ) )
141 {
142 $t->loop_iteration( 'hash_loop' )->set_values(
143 { key => $key, value => $h->{ hash_loop }{ $key } } );
144 }
145 foreach my $record ( @{$h->{ records_loop }} )
146 {
147 $t->loop_iteration( 'records_loop' )->set_values(
148 $record );
149 }
150 $t->set_values( $h );
151 $t->set_delimiters( '<!--', '-->' );
152 $t->set_strip( 0 );
153 $t->set_dir( $template_dir );
154 \$t->parse_file( $_[ 0 ] );
155 },
156 } );
157 }
158  
159 sub benchmark_functions_for_disk_cache
160 {
161 my ( $self, $template_dir, $cache_dir ) = @_;
162  
163 return( undef );
164 }
165  
166 sub benchmark_functions_for_shared_memory_cache
167 {
168 my ( $self, $template_dir, $cache_dir ) = @_;
169  
170 return( undef );
171 }
172  
173 sub benchmark_functions_for_memory_cache
174 {
175 my ( $self, $template_dir, $cache_dir ) = @_;
176  
177 return( undef );
178 }
179  
180 sub benchmark_functions_for_instance_reuse
181 {
182 my ( $self, $template_dir, $cache_dir ) = @_;
183  
184 return( undef );
185 }
186  
187 1;
188  
189 __END__
« lib/Template/Benchmark/Engines/TextTemplet.pm ↑ Summary lib/Template/Benchmark/Engines/TextXslate.pm »