lib/Template/Benchmark/Engines/HTMLMason.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/HTMLMacro.pm ↑ Summary lib/Template/Benchmark/Engines/HTMLTemplate.pm »
1 package Template::Benchmark::Engines::HTMLMason;
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 HTML::Mason;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use HTML::Mason::Interp;
10  
11 use File::Spec;
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 '<% $ARGS{scalar_variable} %>',
20 hash_variable_value =>
21 '<% $ARGS{hash_variable}->{hash_value_key} %>',
22 array_variable_value =>
23 '<% $ARGS{array_variable}->[ 2 ] %>',
24 deep_data_structure_value =>
25 '<% $ARGS{this}->{is}{a}{very}{deep}{hash}{structure} %>',
26 array_loop_value =>
27 '<%perl>foreach ( @{$ARGS{array_loop}} ) {</%perl>' .
28 '<% $_ %>' .
29 '<%perl>}</%perl>' . "\n",
30 hash_loop_value =>
31 '<%perl>foreach ( sort( keys( %{$ARGS{hash_loop}} ) ) ) {</%perl>' .
32 '<% $_ %>: <% $ARGS{hash_loop}->{$_} %>' .
33 '<%perl>}</%perl>' . "\n",
34 records_loop_value =>
35 '<%perl>foreach ( @{$ARGS{records_loop}} ) {</%perl>' .
36 '<% $_->{ name } %>: <% $_->{ age } %>' .
37 '<%perl>}</%perl>' . "\n",
38 array_loop_template =>
39 '<%perl>foreach ( @{$ARGS{array_loop}} ) {</%perl>' .
40 '<% $_ %>' .
41 '<%perl>}</%perl>' . "\n",
42 hash_loop_template =>
43 '<%perl>foreach ( sort( keys( %{$ARGS{hash_loop}} ) ) ) {</%perl>' .
44 '<% $_ %>: <% $ARGS{hash_loop}->{$_} %>' .
45 '<%perl>}</%perl>' . "\n",
46 records_loop_template =>
47 '<%perl>foreach ( @{$ARGS{records_loop}} ) {</%perl>' .
48 '<% $_->{ name } %>: <% $_->{ age } %>' .
49 '<%perl>}</%perl>' . "\n",
50 constant_if_literal =>
51 '<%perl>if( 1 ) {</%perl>true<%perl>}</%perl>' . "\n",
52 variable_if_literal =>
53 '<%perl>if( $ARGS{variable_if} ) {</%perl>true<%perl>}</%perl>' . "\n",
54 constant_if_else_literal =>
55 '<%perl>if( 1 ) {</%perl>true<%perl>} else {</%perl>' .
56 'false<%perl>}</%perl>' . "\n",
57 variable_if_else_literal =>
58 '<%perl>if( $ARGS{variable_if_else} ) {</%perl>true<%perl>} ' .
59 'else {</%perl>false<%perl>}</%perl>' . "\n",
60 constant_if_template =>
61 '<%perl>if( 1 ) {</%perl>' .
62 '<% $ARGS{template_if_true} %><%perl>}</%perl>' . "\n",
63 variable_if_template =>
64 '<%perl>if( $ARGS{variable_if} ) {</%perl>' .
65 '<% $ARGS{template_if_true} %><%perl>}</%perl>' . "\n",
66 constant_if_else_template =>
67 '<%perl>if( 1 ) {</%perl>' .
68 '<% $ARGS{template_if_true} %><%perl>} ' .
69 'else {</%perl>' .
70 '<% $ARGS{template_if_false} %><%perl>}</%perl>' . "\n",
71 variable_if_else_template =>
72 '<%perl>if( $ARGS{variable_if_else} ) {</%perl>' .
73 '<% $ARGS{template_if_true} %><%perl>} ' .
74 'else {</%perl>' .
75 '<% $ARGS{template_if_false} %><%perl>}</%perl>' . "\n",
76 constant_expression =>
77 '<% 10 + 12 %>',
78 variable_expression =>
79 '<% $ARGS{variable_expression_a} * $ARGS{variable_expression_b} %>',
80 complex_variable_expression =>
81 '<% ( ( $ARGS{variable_expression_a} * $ARGS{variable_expression_b} ) + ' .
82 '$ARGS{variable_expression_a} - $ARGS{variable_expression_b} ) / ' .
83 '$ARGS{variable_expression_b} %>',
84 constant_function =>
85 q[<% substr( 'this has a substring.', 11, 9 ) %>],
86 variable_function =>
87 '<% substr( $ARGS{variable_function_arg}, 4, 2 ) %>',
88 );
89  
90 sub syntax_type { return( 'embedded-perl' ); }
91 sub pure_perl { return( 1 ); }
92  
93 sub benchmark_descriptions
94 {
95 return( {
96 HM =>
97 "HTML::Mason ($HTML::Mason::VERSION)",
98 } );
99 }
100  
101 # These flags lifted from HTML::Mason::Admin PERFORMANCE section.
102 # code_cache_max_size => 0, # turn off memory caching
103 # use_object_files => 0, # turn off disk caching
104 # static_source => 1, # turn off disk stat()s
105 # enable_autoflush = 0, # turn off dynamic autoflush checking
106  
107 sub benchmark_functions_for_uncached_string
108 {
109 my ( $self ) = @_;
110  
111 return( {
112 HM =>
113 sub
114 {
115 my $out = '';
116 my $t = HTML::Mason::Interp->new(
117 code_cache_max_size => 0,
118 use_object_files => 0,
119 static_source => 1,
120 enable_autoflush => 0,
121 out_method => \$out,
122 );
123  
124 my $c = $t->make_component(
125 comp_source => $_[ 0 ],
126 );
127  
128 $t->exec(
129 $c,
130 %{$_[ 1 ]}, %{$_[ 2 ]},
131 );
132 \$out;
133 },
134 } );
135 }
136  
137 sub benchmark_functions_for_uncached_disk
138 {
139 my ( $self, $template_dir ) = @_;
140  
141 return( {
142 HM =>
143 sub
144 {
145 my $out = '';
146 my $t = HTML::Mason::Interp->new(
147 comp_root => $template_dir,
148 code_cache_max_size => 0,
149 use_object_files => 0,
150 static_source => 1,
151 enable_autoflush => 0,
152 out_method => \$out,
153 );
154  
155 $t->exec(
156 # Don't use File::Spec, Mason reads it like a URL path.
157 '/' . $_[ 0 ],
158 %{$_[ 1 ]}, %{$_[ 2 ]},
159 );
160 \$out;
161 },
162 } );
163 }
164  
165 sub benchmark_functions_for_disk_cache
166 {
167 my ( $self, $template_dir, $cache_dir ) = @_;
168  
169 return( {
170 HM =>
171 sub
172 {
173 my $out = '';
174 my $t = HTML::Mason::Interp->new(
175 comp_root => $template_dir,
176 data_dir => $cache_dir,
177 code_cache_max_size => 0,
178 static_source => 1,
179 enable_autoflush => 0,
180 out_method => \$out,
181 );
182  
183 $t->exec(
184 # Don't use File::Spec, Mason reads it like a URL path.
185 '/' . $_[ 0 ],
186 %{$_[ 1 ]}, %{$_[ 2 ]},
187 );
188 \$out;
189 },
190 } );
191 }
192  
193 sub benchmark_functions_for_shared_memory_cache
194 {
195 my ( $self, $template_dir, $cache_dir ) = @_;
196  
197 return( undef );
198 }
199  
200 sub benchmark_functions_for_memory_cache
201 {
202 my ( $self, $template_dir, $cache_dir ) = @_;
203  
204 return( {
205 HM =>
206 sub
207 {
208 my $out = '';
209 my $t = HTML::Mason::Interp->new(
210 comp_root => $template_dir,
211 data_dir => $cache_dir,
212 static_source => 1,
213 enable_autoflush => 0,
214 out_method => \$out,
215 );
216  
217 $t->exec(
218 # Don't use File::Spec, Mason reads it like a URL path.
219 '/' . $_[ 0 ],
220 %{$_[ 1 ]}, %{$_[ 2 ]},
221 );
222 \$out;
223 },
224 } );
225 }
226  
227 sub benchmark_functions_for_instance_reuse
228 {
229 my ( $self, $template_dir, $cache_dir ) = @_;
230 my ( $t, $out );
231  
232 $t = HTML::Mason::Interp->new(
233 comp_root => $template_dir,
234 data_dir => $cache_dir,
235 static_source => 1,
236 enable_autoflush => 0,
237 out_method => \$out,
238 );
239  
240 return( {
241 HM =>
242 sub
243 {
244 $out = '';
245 $t->exec(
246 # Don't use File::Spec, Mason reads it like a URL path.
247 '/' . $_[ 0 ],
248 %{$_[ 1 ]}, %{$_[ 2 ]},
249 );
250 \$out;
251 },
252 } );
253 }
254  
255 1;
256  
257 __END__
« lib/Template/Benchmark/Engines/HTMLMacro.pm ↑ Summary lib/Template/Benchmark/Engines/HTMLTemplate.pm »