lib/Template/Benchmark/Engines/TextClevery.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/TextClearSilver.pm ↑ Summary lib/Template/Benchmark/Engines/TextMicroMasonHM.pm »
1 package Template::Benchmark::Engines::TextClevery;
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::Clevery;
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 item=i from=$array_loop}{$i}{/foreach}',
25 hash_loop_value =>
26 # 'key' attribute not yet implemented in Text::Clevery.
27 undef,
28 # '{foreach key=k item=v from=$hash_loop}{$k}: ' .
29 # '{$v}{/foreach}',
30 records_loop_value =>
31 '{foreach item=r from=$records_loop}{$r.name}: ' .
32 '{$r.age}{/foreach}',
33 array_loop_template =>
34 '{foreach item=i from=$array_loop}{$i}{/foreach}',
35 hash_loop_template =>
36 # 'key' attribute not yet implemented in Text::Clevery.
37 undef,
38 # '{foreach key=k item=v from=$hash_loop}{$k}: ' .
39 # '{$v}{/foreach}',
40 records_loop_template =>
41 '{foreach item=r from=$records_loop}{$r.name}: ' .
42 '{$r.age}{/foreach}',
43 constant_if_literal =>
44 '{if 1}true{/if}',
45 variable_if_literal =>
46 '{if $variable_if}true{/if}',
47 constant_if_else_literal =>
48 '{if 1}true{else}false{/if}',
49 variable_if_else_literal =>
50 '{if $variable_if_else}true{else}false{/if}',
51 constant_if_template =>
52 '{if 1}{$template_if_true}{/if}',
53 variable_if_template =>
54 '{if $variable_if}{$template_if_true}{/if}',
55 constant_if_else_template =>
56 '{if 1}{$template_if_true}{else}' .
57 '{$template_if_false}{/if}',
58 variable_if_else_template =>
59 '{if $variable_if_else}{$template_if_true}{else}' .
60 '{$template_if_false}{/if}',
61 constant_expression =>
62 '{10 + 12}',
63 variable_expression =>
64 '{$variable_expression_a * $variable_expression_b}',
65 complex_variable_expression =>
66 '{( ( $variable_expression_a * $variable_expression_b ) + ' .
67 '$variable_expression_a - $variable_expression_b ) / ' .
68 '$variable_expression_b}',
69 constant_function =>
70 # TODO: functions in Smarty have named param, no idea how this links to Xslate
71 undef,
72 # q[{substr( 'this has a substring.', 11, 9 )}],
73 variable_function =>
74 # TODO: functions in Smarty have named param, no idea how this links to Xslate
75 undef,
76 # '{substr( $variable_function_arg, 4, 2 )}',
77 );
78  
79 sub syntax_type { return( 'mini-language' ); }
80 sub pure_perl
81 {
82 return( 1 ) if $ENV{ XSLATE } and $ENV{ XSLATE } =~ / \b pp \b /xms;
83 return( 0 );
84 }
85  
86 sub benchmark_descriptions
87 {
88 if( __PACKAGE__->pure_perl() )
89 {
90 return( {
91 TeClevPP =>
92 "Text::Clevery ($Text::Clevery::VERSION) in Pure Perl mode",
93 } );
94 }
95 return( {
96 TeClev =>
97 "Text::Clevery ($Text::Clevery::VERSION) in XS mode",
98 } );
99 }
100  
101 sub benchmark_functions_for_uncached_string
102 {
103 my ( $self ) = @_;
104  
105 return( {
106 ( __PACKAGE__->pure_perl() ? 'TeClevPP' : 'TeClev' ) =>
107 sub
108 {
109 my $t = Text::Clevery->new(
110 cache => 0,
111 function => {
112 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
113 },
114 );
115 \$t->render_string( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
116 },
117 } );
118 }
119  
120 sub benchmark_functions_for_uncached_disk
121 {
122 my ( $self, $template_dir ) = @_;
123 my ( @template_dirs );
124  
125 @template_dirs = ( $template_dir );
126  
127 return( {
128 ( __PACKAGE__->pure_perl() ? 'TeClevPP' : 'TeClev' ) =>
129 sub
130 {
131 my $t = Text::Clevery->new(
132 path => \@template_dirs,
133 cache => 0,
134 function => {
135 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
136 },
137 );
138 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
139 },
140 } );
141 }
142  
143 sub benchmark_functions_for_disk_cache
144 {
145 my ( $self, $template_dir, $cache_dir ) = @_;
146 my ( @template_dirs );
147  
148 @template_dirs = ( $template_dir );
149  
150 return( {
151 ( __PACKAGE__->pure_perl() ? 'TeClevPP' : 'TeClev' ) =>
152 sub
153 {
154 my $t = Text::Clevery->new(
155 path => \@template_dirs,
156 cache_dir => $cache_dir,
157 cache => 2,
158 function => {
159 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
160 },
161 );
162 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
163 },
164 } );
165 }
166  
167 sub benchmark_functions_for_shared_memory_cache
168 {
169 my ( $self, $template_dir, $cache_dir ) = @_;
170  
171 return( undef );
172 }
173  
174 sub benchmark_functions_for_memory_cache
175 {
176 my ( $self, $template_dir, $cache_dir ) = @_;
177  
178 return( undef );
179 }
180  
181 sub benchmark_functions_for_instance_reuse
182 {
183 my ( $self, $template_dir, $cache_dir ) = @_;
184 my ( @template_dirs, $t );
185  
186 @template_dirs = ( $template_dir );
187  
188 return( {
189 ( __PACKAGE__->pure_perl() ? 'TeClevPP' : 'TeClev' ) =>
190 sub
191 {
192 $t = Text::Clevery->new(
193 path => \@template_dirs,
194 cache_dir => $cache_dir,
195 cache => 2,
196 function => {
197 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
198 },
199 ) unless $t;
200 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
201 },
202 } );
203 }
204  
205 1;
206  
207 __END__
« lib/Template/Benchmark/Engines/TextClearSilver.pm ↑ Summary lib/Template/Benchmark/Engines/TextMicroMasonHM.pm »