lib/Template/Benchmark/Engines/TextMiniTmpl.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/TextMicroTemplateExtended.pm ↑ Summary lib/Template/Benchmark/Engines/TextTemplate.pm »
1 package Template::Benchmark::Engines::TextMiniTmpl;
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::MiniTmpl 1.1.0 qw( render tmpl2code raw );
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 ( @{$_{array_loop}} ) {~&' .
25 '#~ $_ ~#' .
26 '&~}~&',
27 hash_loop_value =>
28 '&~foreach ( sort( keys( %{$_{hash_loop}} ) ) ) {~&' .
29 '#~ $_ ~#: #~ $_{hash_loop}->{$_} ~#' .
30 '&~}~&',
31 records_loop_value =>
32 '&~foreach ( @{$_{records_loop}} ) {~&' .
33 '#~ $_->{ name } ~#: #~ $_->{ age } ~#' .
34 '&~}~&',
35 array_loop_template =>
36 '&~foreach ( @{$_{array_loop}} ) {~&' .
37 '#~ $_ ~#' .
38 '&~}~&',
39 hash_loop_template =>
40 '&~foreach ( sort( keys( %{$_{hash_loop}} ) ) ) {~&' .
41 '#~ $_ ~#: #~ $_{hash_loop}->{$_} ~#' .
42 '&~}~&',
43 records_loop_template =>
44 '&~foreach ( @{$_{records_loop}} ) {~&' .
45 '#~ $_->{ name } ~#: #~ $_->{ age } ~#' .
46 '&~}~&',
47 constant_if_literal =>
48 '&~if( 1 ) {~&true&~}~&',
49 variable_if_literal =>
50 '&~if( $_{variable_if} ) {~&true&~}~&',
51 constant_if_else_literal =>
52 '&~if( 1 ) {~&true&~} else {~&' .
53 'false&~}~&',
54 variable_if_else_literal =>
55 '&~if( $_{variable_if_else} ) {~&true&~} ' .
56 'else {~&false&~}~&',
57 constant_if_template =>
58 '&~if( 1 ) {~&' .
59 '#~ $_{template_if_true} ~#&~}~&',
60 variable_if_template =>
61 '&~if( $_{variable_if} ) {~&' .
62 '#~ $_{template_if_true} ~#&~}~&',
63 constant_if_else_template =>
64 '&~if( 1 ) {~&' .
65 '#~ $_{template_if_true} ~#&~} ' .
66 'else {~&' .
67 '#~ $_{template_if_false} ~#&~}~&',
68 variable_if_else_template =>
69 '&~if( $_{variable_if_else} ) {~&' .
70 '#~ $_{template_if_true} ~#&~} ' .
71 'else {~&' .
72 '#~ $_{template_if_false} ~#&~}~&',
73 constant_expression =>
74 '#~ 10 + 12 ~#',
75 variable_expression =>
76 '#~ $_{variable_expression_a} * $_{variable_expression_b} ~#',
77 complex_variable_expression =>
78 '#~ ( ( $_{variable_expression_a} * $_{variable_expression_b} ) + ' .
79 '$_{variable_expression_a} - $_{variable_expression_b} ) / ' .
80 '$_{variable_expression_b} ~#',
81 constant_function =>
82 q[#~ substr( 'this has a substring.', 11, 9 ) ~#],
83 variable_function =>
84 '#~ substr( $_{variable_function_arg}, 4, 2 ) ~#',
85 );
86  
87 sub syntax_type { return( 'embedded-perl' ); }
88 sub pure_perl { return( 1 ); }
89  
90 sub benchmark_descriptions
91 {
92 return( {
93 TMT =>
94 "Text::MiniTmpl ($Text::MiniTmpl::VERSION)",
95 TMTU =>
96 "Text::MiniTmpl ($Text::MiniTmpl::VERSION) with enabled Unicode",
97 } );
98 }
99  
100 sub benchmark_functions_for_uncached_string
101 {
102 my ( $self ) = @_;
103  
104 return( undef );
105 }
106  
107 sub benchmark_functions_for_uncached_disk
108 {
109 my ( $self, $template_dir ) = @_;
110  
111 return( {
112 TMT =>
113 sub
114 {
115 raw(1);
116 tmpl2code( $template_dir . '/' . $_[ 0 ] )->(
117 %{$_[ 1 ]}, %{$_[ 2 ]},
118 )
119 },
120 TMTU =>
121 sub
122 {
123 raw(0);
124 tmpl2code( $template_dir . '/' . $_[ 0 ] )->(
125 %{$_[ 1 ]}, %{$_[ 2 ]},
126 )
127 },
128 } );
129 }
130  
131 sub benchmark_functions_for_disk_cache
132 {
133 my ( $self, $template_dir, $cache_dir ) = @_;
134  
135 return( undef );
136 }
137  
138 sub benchmark_functions_for_shared_memory_cache
139 {
140 my ( $self, $template_dir, $cache_dir ) = @_;
141  
142 return( undef );
143 }
144  
145 sub benchmark_functions_for_memory_cache
146 {
147 my ( $self, $template_dir, $cache_dir ) = @_;
148  
149 return( undef );
150 }
151  
152 sub benchmark_functions_for_instance_reuse
153 {
154 my ( $self, $template_dir, $cache_dir ) = @_;
155 my ( $t, $out );
156  
157 return( {
158 TMT =>
159 sub
160 {
161 raw(1);
162 \render( $template_dir . '/' . $_[ 0 ],
163 %{$_[ 1 ]}, %{$_[ 2 ]},
164 )
165 },
166 TMTU =>
167 sub
168 {
169 raw(0);
170 # use ../../ to force different paths/caches for TMT and TMTU
171 \render( ('../' x 20) . $template_dir . '/' . $_[ 0 ],
172 %{$_[ 1 ]}, %{$_[ 2 ]},
173 )
174 },
175 } );
176 }
177  
178 1;
179  
180 __END__
« lib/Template/Benchmark/Engines/TextMicroTemplateExtended.pm ↑ Summary lib/Template/Benchmark/Engines/TextTemplate.pm »