lib/Template/Benchmark/Engines/TextXslate.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/TextTmpl.pm ↑ Summary lib/Template/Benchmark/Engines/TextXslateTT.pm »
1 package Template::Benchmark::Engines::TextXslate;
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.1052 fixed a bug about literal colons
9 0 ▶use Text::Xslate 0.1052;
Subroutine BEGIN: called CC=1 SCAR=2.6
10  
11 our $VERSION = '1.09_01';
12  
13 our %feature_syntaxes = (
14 literal_text =>
15 join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ),
16 scalar_variable =>
17 '<:= $scalar_variable :>',
18 hash_variable_value =>
19 '<:= $hash_variable.hash_value_key :>',
20 array_variable_value =>
21 '<:= $array_variable[ 2 ] :>',
22 deep_data_structure_value =>
23 '<:= $this.is.a.very.deep.hash.structure :>',
24 array_loop_value =>
25 '<: for $array_loop ->($i) { :><:= $i :><: } :>',
26 hash_loop_value =>
27 '<: for $hash_loop.keys() ->($k) { :><:= $k :>: ' .
28 '<:= $hash_loop[ $k ] :><: } :>',
29 records_loop_value =>
30 '<: for $records_loop ->($r) { :><:= $r.name :>: ' .
31 '<:= $r.age :><: } :>',
32 array_loop_template =>
33 '<: for $array_loop ->($i) { :><:= $i :><: } :>',
34 hash_loop_template =>
35 '<: for $hash_loop.keys() ->($k) { :><:= $k :>: ' .
36 '<:= $hash_loop[ $k ] :><: } :>',
37 records_loop_template =>
38 '<: for $records_loop ->($r) { :><:= $r.name :>: ' .
39 '<:= $r.age :><: } :>',
40 constant_if_literal =>
41 '<: if 1 { :>true<: } :>',
42 variable_if_literal =>
43 '<: if $variable_if { :>true<: } :>',
44 constant_if_else_literal =>
45 '<: if 1 { :>true<: } else { :>false<: } :>',
46 variable_if_else_literal =>
47 '<: if $variable_if_else { :>true<: } else { :>false<: } :>',
48 constant_if_template =>
49 '<: if 1 { :><:= $template_if_true :><: } :>',
50 variable_if_template =>
51 '<: if $variable_if { :><:= $template_if_true :><: } :>',
52 constant_if_else_template =>
53 '<: if 1 { :><:= $template_if_true :><: } else { :>' .
54 '<:= $template_if_false :><: } :>',
55 variable_if_else_template =>
56 '<: if $variable_if_else { :><:= $template_if_true :><: } else { :>' .
57 '<:= $template_if_false :><: } :>',
58 constant_expression =>
59 '<:= 10 + 12 :>',
60 variable_expression =>
61 '<:= $variable_expression_a * $variable_expression_b :>',
62 complex_variable_expression =>
63 '<:= ( ( $variable_expression_a * $variable_expression_b ) + ' .
64 '$variable_expression_a - $variable_expression_b ) / ' .
65 '$variable_expression_b :>',
66 constant_function =>
67 q{<:= substr( 'this has a substring.', 11, 9 ) :>},
68 variable_function =>
69 '<:= substr( $variable_function_arg, 4, 2 ) :>',
70 );
71  
72 sub syntax_type { return( 'mini-language' ); }
73 sub pure_perl
74 {
75 return( 1 ) if $ENV{ XSLATE } and $ENV{ XSLATE } =~ / \b pp \b /xms;
76 return( 0 );
77 }
78  
79 sub benchmark_descriptions
80 {
81 if( __PACKAGE__->pure_perl() )
82 {
83 return( {
84 TeXsPP =>
85 "Text::Xslate::PP ($Text::Xslate::PP::VERSION)",
86 } );
87 }
88 return( {
89 TeXs =>
90 "Text::Xslate ($Text::Xslate::VERSION)",
91 } );
92 }
93  
94 sub benchmark_functions_for_uncached_string
95 {
96 my ( $self ) = @_;
97  
98 return( {
99 ( __PACKAGE__->pure_perl() ? 'TeXsPP' : 'TeXs' ) =>
100 sub
101 {
102 my $t = Text::Xslate->new(
103 cache => 0,
104 # TODO: Probably a better way to achieve this.
105 function => {
106 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
107 },
108 );
109 \$t->render_string( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
110 },
111 } );
112 }
113  
114 sub benchmark_functions_for_uncached_disk
115 {
116 my ( $self, $template_dir ) = @_;
117 my ( @template_dirs );
118  
119 @template_dirs = ( $template_dir );
120  
121 return( {
122 ( __PACKAGE__->pure_perl() ? 'TeXsPP' : 'TeXs' ) =>
123 sub
124 {
125 my $t = Text::Xslate->new(
126 path => \@template_dirs,
127 cache => 0,
128 # TODO: Probably a better way to achieve this.
129 function => {
130 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
131 },
132 );
133 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
134 },
135 } );
136 }
137  
138 sub benchmark_functions_for_disk_cache
139 {
140 my ( $self, $template_dir, $cache_dir ) = @_;
141 my ( @template_dirs );
142  
143 @template_dirs = ( $template_dir );
144  
145 return( {
146 ( __PACKAGE__->pure_perl() ? 'TeXsPP' : 'TeXs' ) =>
147 sub
148 {
149 my $t = Text::Xslate->new(
150 path => \@template_dirs,
151 cache_dir => $cache_dir,
152 cache => 2,
153 # TODO: Probably a better way to achieve this.
154 function => {
155 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
156 },
157 );
158 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
159 },
160 } );
161 }
162  
163 sub benchmark_functions_for_shared_memory_cache
164 {
165 my ( $self, $template_dir, $cache_dir ) = @_;
166  
167 return( undef );
168 }
169  
170 sub benchmark_functions_for_memory_cache
171 {
172 my ( $self, $template_dir, $cache_dir ) = @_;
173  
174 return( undef );
175 }
176  
177 sub benchmark_functions_for_instance_reuse
178 {
179 my ( $self, $template_dir, $cache_dir ) = @_;
180 my ( @template_dirs, $t );
181  
182 @template_dirs = ( $template_dir );
183  
184 return( {
185 ( __PACKAGE__->pure_perl() ? 'TeXsPP' : 'TeXs' ) =>
186 sub
187 {
188 $t = Text::Xslate->new(
189 path => \@template_dirs,
190 cache_dir => $cache_dir,
191 cache => 2,
192 # TODO: Probably a better way to achieve this.
193 function => {
194 substr => sub { substr( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) },
195 },
196 ) unless $t;
197 \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } );
198 },
199 } );
200 }
201  
202 1;
203  
204 __END__
« lib/Template/Benchmark/Engines/TextTmpl.pm ↑ Summary lib/Template/Benchmark/Engines/TextXslateTT.pm »