lib/Template/Benchmark/Engines/ParseTemplate.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/NTSTemplate.pm ↑ Summary lib/Template/Benchmark/Engines/Solution.pm »
1 package Template::Benchmark::Engines::ParseTemplate;
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 Parse::Template;
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 q|%% join( '', @array_loop ) %%|,
25 hash_loop_value =>
26 q|%% join( '', map { $_ . ': ' . $hash_loop{$_} } | .
27 q|sort( keys( %hash_loop ) ) ) %%|,
28 records_loop_value =>
29 q|%% join( '', map { $_->{ name } . ': ' . $_->{ age } } | .
30 q|@records_loop ) %%|,
31 array_loop_template =>
32 # Can't be done under the paradigm of Template::Benchmark,
33 # each content block needs to a separate template.
34 undef,
35 hash_loop_template =>
36 # Can't be done under the paradigm of Template::Benchmark,
37 # each content block needs to a separate template.
38 undef,
39 records_loop_template =>
40 # Can't be done under the paradigm of Template::Benchmark,
41 # each content block needs to a separate template.
42 undef,
43 constant_if_literal =>
44 q|%% if( 1 ) { 'true' } %%|,
45 variable_if_literal =>
46 q|%% if( $variable_if ) { 'true' } %%|,
47 constant_if_else_literal =>
48 q|%% if( 1 ) { 'true' } else { 'false' } %%|,
49 variable_if_else_literal =>
50 q|%% if( $variable_if_else ) { 'true' } else { | .
51 q|'false' } %%|,
52 constant_if_template =>
53 # Can't be done under the paradigm of Template::Benchmark,
54 # each content block needs to a separate template.
55 undef,
56 variable_if_template =>
57 # Can't be done under the paradigm of Template::Benchmark,
58 # each content block needs to a separate template.
59 undef,
60 constant_if_else_template =>
61 # Can't be done under the paradigm of Template::Benchmark,
62 # each content block needs to a separate template.
63 undef,
64 variable_if_else_template =>
65 # Can't be done under the paradigm of Template::Benchmark,
66 # each content block needs to a separate template.
67 undef,
68 constant_expression =>
69 '%% 10 + 12 %%',
70 variable_expression =>
71 '%% $variable_expression_a * ' .
72 '$variable_expression_b %%',
73 complex_variable_expression =>
74 '%% ( ( $variable_expression_a * ' .
75 '$variable_expression_b ) + ' .
76 '$variable_expression_a - ' .
77 '$variable_expression_b ) / ' .
78 '$variable_expression_b %%',
79 constant_function =>
80 q{%% substr( 'this has a substring.', 11, 9 ) %%},
81 variable_function =>
82 '%% substr( $variable_function_arg, 4, 2 ) %%',
83 );
84  
85 sub syntax_type { return( 'embedded-perl' ); }
86 sub pure_perl { return( 1 ); }
87  
88 sub benchmark_descriptions
89 {
90 return( {
91 PT =>
92 "Parse::Template ($Parse::Template::VERSION)",
93 } );
94 }
95  
96 sub benchmark_functions_for_uncached_string
97 {
98 my ( $self ) = @_;
99  
100 return( {
101 PT =>
102 sub
103 {
104 my $t = Parse::Template->new(
105 TOP => $_[ 0 ],
106 );
107 $t->env( %{$_[ 1 ]} );
108 $t->env( %{$_[ 2 ]} );
109 \$t->eval( 'TOP' );
110 },
111 } );
112 }
113  
114 sub benchmark_functions_for_uncached_disk
115 {
116 my ( $self, $template_dir ) = @_;
117  
118 return( undef );
119 }
120  
121 sub benchmark_functions_for_disk_cache
122 {
123 my ( $self, $template_dir, $cache_dir ) = @_;
124  
125 return( undef );
126 }
127  
128 sub benchmark_functions_for_shared_memory_cache
129 {
130 my ( $self, $template_dir, $cache_dir ) = @_;
131  
132 return( undef );
133 }
134  
135 sub benchmark_functions_for_memory_cache
136 {
137 my ( $self, $template_dir, $cache_dir ) = @_;
138  
139 return( undef );
140 }
141  
142 sub benchmark_functions_for_instance_reuse
143 {
144 my ( $self, $template_dir, $cache_dir ) = @_;
145 my ( $t );
146  
147 # Ew ick, I was almost templated to leave this as "unsupported"
148 # given how much crud I need to wrap around the template engine
149 # to get it to do this basic task.
150 return( {
151 PT =>
152 sub
153 {
154 unless( $t )
155 {
156 my ( $fh, $template );
157  
158 $fh = IO::File->new(
159 File::Spec->catfile( $template_dir, $_[ 0 ] ), '<' );
160 {
161 local $/ = undef;
162 $template = <$fh>;
163 }
164 $fh->close();
165  
166 $t = Parse::Template->new(
167 TOP => $template,
168 );
169 }
170 $t->env( %{$_[ 1 ]} );
171 $t->env( %{$_[ 2 ]} );
172 \$t->eval( 'TOP' );
173 },
174 } );
175 }
176  
177 1;
178  
179 __END__
« lib/Template/Benchmark/Engines/NTSTemplate.pm ↑ Summary lib/Template/Benchmark/Engines/Solution.pm »