« lib/Template/Benchmark/Engines/HTMLTemplateCompiled.pm
↑ Summary
lib/Template/Benchmark/Engines/HTMLTemplateJIT.pm »
| 1 | package Template::Benchmark::Engines::HTMLTemplateExpr; | ||
| 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::Template::Expr; |
|
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 | '<TMPL_VAR NAME=scalar_variable>', | ||
| 17 | hash_variable_value => | ||
| 18 | undef, | ||
| 19 | array_variable_value => | ||
| 20 | undef, | ||
| 21 | deep_data_structure_value => | ||
| 22 | undef, | ||
| 23 | array_loop_value => | ||
| 24 | undef, | ||
| 25 | hash_loop_value => | ||
| 26 | undef, | ||
| 27 | records_loop_value => | ||
| 28 | '<TMPL_LOOP NAME=records_loop><TMPL_VAR NAME=name>: ' . | ||
| 29 | '<TMPL_VAR NAME=age></TMPL_LOOP>', | ||
| 30 | array_loop_template => | ||
| 31 | undef, | ||
| 32 | hash_loop_template => | ||
| 33 | undef, | ||
| 34 | records_loop_template => | ||
| 35 | '<TMPL_LOOP NAME=records_loop><TMPL_VAR NAME=name>: ' . | ||
| 36 | '<TMPL_VAR NAME=age></TMPL_LOOP>', | ||
| 37 | constant_if_literal => | ||
| 38 | '<TMPL_IF EXPR="1">true</TMPL_IF>', | ||
| 39 | variable_if_literal => | ||
| 40 | '<TMPL_IF NAME=variable_if>true</TMPL_IF>', | ||
| 41 | constant_if_else_literal => | ||
| 42 | '<TMPL_IF EXPR="1">true<TMPL_ELSE>false</TMPL_IF>', | ||
| 43 | variable_if_else_literal => | ||
| 44 | '<TMPL_IF NAME=variable_if_else>true<TMPL_ELSE>false</TMPL_IF>', | ||
| 45 | constant_if_template => | ||
| 46 | '<TMPL_IF EXPR="1"><TMPL_VAR NAME=template_if_true></TMPL_IF>', | ||
| 47 | variable_if_template => | ||
| 48 | '<TMPL_IF NAME=variable_if><TMPL_VAR NAME=template_if_true></TMPL_IF>', | ||
| 49 | constant_if_else_template => | ||
| 50 | '<TMPL_IF EXPR="1"><TMPL_VAR NAME=template_if_true>' . | ||
| 51 | '<TMPL_ELSE><TMPL_VAR NAME=template_if_false></TMPL_IF>', | ||
| 52 | variable_if_else_template => | ||
| 53 | '<TMPL_IF NAME=variable_if_else><TMPL_VAR NAME=template_if_true>' . | ||
| 54 | '<TMPL_ELSE><TMPL_VAR NAME=template_if_false></TMPL_IF>', | ||
| 55 | constant_expression => | ||
| 56 | '<TMPL_VAR EXPR="10 + 12">', | ||
| 57 | variable_expression => | ||
| 58 | '<TMPL_VAR EXPR="variable_expression_a * variable_expression_b">', | ||
| 59 | complex_variable_expression => | ||
| 60 | '<TMPL_VAR EXPR="' . | ||
| 61 | '( ( variable_expression_a * variable_expression_b ) + ' . | ||
| 62 | 'variable_expression_a - variable_expression_b ) / ' . | ||
| 63 | 'variable_expression_b">', | ||
| 64 | constant_function => | ||
| 65 | q{<TMPL_VAR EXPR="substr( 'this has a substring', 11, 9 )">}, | ||
| 66 | variable_function => | ||
| 67 | '<TMPL_VAR EXPR="substr( variable_function_arg, 4, 2 )">', | ||
| 68 | ); | ||
| 69 | |||
| 70 | sub syntax_type { return( 'mini-language' ); } | ||
| 71 | sub pure_perl { return( 1 ); } | ||
| 72 | |||
| 73 | sub benchmark_descriptions | ||
| 74 | { | ||
| 75 | return( { | ||
| 76 | HTE => | ||
| 77 | "HTML::Template::Expr ($HTML::Template::Expr::VERSION)", | ||
| 78 | } ); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub benchmark_functions_for_uncached_string | ||
| 82 | { | ||
| 83 | my ( $self ) = @_; | ||
| 84 | |||
| 85 | return( { | ||
| 86 | HTE => | ||
| 87 | sub | ||
| 88 | { | ||
| 89 | my $t = HTML::Template::Expr->new( | ||
| 90 | scalarref => \$_[ 0 ], | ||
| 91 | case_sensitive => 1, | ||
| 92 | die_on_bad_params => 0, | ||
| 93 | cache => 0, | ||
| 94 | ); | ||
| 95 | $t->param( $_[ 1 ] ); | ||
| 96 | $t->param( $_[ 2 ] ); | ||
| 97 | my $out = $t->output(); | ||
| 98 | \$out; | ||
| 99 | }, | ||
| 100 | } ); | ||
| 101 | } | ||
| 102 | |||
| 103 | sub benchmark_functions_for_uncached_disk | ||
| 104 | { | ||
| 105 | my ( $self, $template_dir ) = @_; | ||
| 106 | my ( @template_dirs ); | ||
| 107 | |||
| 108 | @template_dirs = ( $template_dir ); | ||
| 109 | |||
| 110 | return( { | ||
| 111 | HTE => | ||
| 112 | sub | ||
| 113 | { | ||
| 114 | my $t = HTML::Template::Expr->new( | ||
| 115 | path => \@template_dirs, | ||
| 116 | filename => $_[ 0 ], | ||
| 117 | case_sensitive => 1, | ||
| 118 | die_on_bad_params => 0, | ||
| 119 | cache => 0, | ||
| 120 | ); | ||
| 121 | $t->param( $_[ 1 ] ); | ||
| 122 | $t->param( $_[ 2 ] ); | ||
| 123 | my $out = $t->output(); | ||
| 124 | \$out; | ||
| 125 | }, | ||
| 126 | } ); | ||
| 127 | } | ||
| 128 | |||
| 129 | sub benchmark_functions_for_disk_cache | ||
| 130 | { | ||
| 131 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 132 | my ( @template_dirs ); | ||
| 133 | |||
| 134 | # HTE doesn't "currently" support file caches. | ||
| 135 | return( undef ); | ||
| 136 | |||
| 137 | # @template_dirs = ( $template_dir ); | ||
| 138 | # | ||
| 139 | # return( { | ||
| 140 | # HTE => | ||
| 141 | # sub | ||
| 142 | # { | ||
| 143 | # my $t = HTML::Template::Expr->new( | ||
| 144 | # type => 'filename', | ||
| 145 | # path => \@template_dirs, | ||
| 146 | # source => $_[ 0 ], | ||
| 147 | # case_sensitive => 1, | ||
| 148 | # file_cache => 1, | ||
| 149 | # file_cache_dir => $cache_dir, | ||
| 150 | # die_on_bad_params => 0, | ||
| 151 | # ); | ||
| 152 | # $t->param( $_[ 1 ] ); | ||
| 153 | # $t->param( $_[ 2 ] ); | ||
| 154 | # \$t->output(); | ||
| 155 | # }, | ||
| 156 | # } ); | ||
| 157 | } | ||
| 158 | |||
| 159 | sub benchmark_functions_for_shared_memory_cache | ||
| 160 | { | ||
| 161 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 162 | my ( @template_dirs ); | ||
| 163 | |||
| 164 | # HTE doesn't "currently" support shared memory caches. | ||
| 165 | return( undef ); | ||
| 166 | |||
| 167 | # # TODO: some means to push this onto error stack? | ||
| 168 | # eval "use IPC::SharedCache"; | ||
| 169 | # return( undef ) if $@; | ||
| 170 | # | ||
| 171 | # @template_dirs = ( $template_dir ); | ||
| 172 | # | ||
| 173 | # return( { | ||
| 174 | # HTE => | ||
| 175 | # sub | ||
| 176 | # { | ||
| 177 | # my $t = HTML::Template::Expr->new( | ||
| 178 | # type => 'filename', | ||
| 179 | # path => \@template_dirs, | ||
| 180 | # source => $_[ 0 ], | ||
| 181 | # case_sensitive => 1, | ||
| 182 | # shared_cache => 1, | ||
| 183 | # die_on_bad_params => 0, | ||
| 184 | # ); | ||
| 185 | # $t->param( $_[ 1 ] ); | ||
| 186 | # $t->param( $_[ 2 ] ); | ||
| 187 | # \$t->output(); | ||
| 188 | # }, | ||
| 189 | # } ); | ||
| 190 | } | ||
| 191 | |||
| 192 | sub benchmark_functions_for_memory_cache | ||
| 193 | { | ||
| 194 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 195 | my ( @template_dirs ); | ||
| 196 | |||
| 197 | @template_dirs = ( $template_dir ); | ||
| 198 | |||
| 199 | return( { | ||
| 200 | HTE => | ||
| 201 | sub | ||
| 202 | { | ||
| 203 | my $t = HTML::Template::Expr->new( | ||
| 204 | path => \@template_dirs, | ||
| 205 | filename => $_[ 0 ], | ||
| 206 | case_sensitive => 1, | ||
| 207 | cache => 1, | ||
| 208 | die_on_bad_params => 0, | ||
| 209 | ); | ||
| 210 | $t->param( $_[ 1 ] ); | ||
| 211 | $t->param( $_[ 2 ] ); | ||
| 212 | my $out = $t->output(); | ||
| 213 | \$out; | ||
| 214 | }, | ||
| 215 | } ); | ||
| 216 | } | ||
| 217 | |||
| 218 | sub benchmark_functions_for_instance_reuse | ||
| 219 | { | ||
| 220 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 221 | |||
| 222 | return( undef ); | ||
| 223 | } | ||
| 224 | |||
| 225 | 1; | ||
| 226 | |||
| 227 | __END__ | ||