« lib/Template/Benchmark/Engines/HTMLMason.pm
↑ Summary
lib/Template/Benchmark/Engines/HTMLTemplateCompiled.pm »
| 1 | package Template::Benchmark::Engines::HTMLTemplate; | ||
| 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; |
|
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 | undef, | ||
| 39 | variable_if_literal => | ||
| 40 | '<TMPL_IF NAME=variable_if>true</TMPL_IF>', | ||
| 41 | constant_if_else_literal => | ||
| 42 | undef, | ||
| 43 | variable_if_else_literal => | ||
| 44 | '<TMPL_IF NAME=variable_if_else>true<TMPL_ELSE>false</TMPL_IF>', | ||
| 45 | constant_if_template => | ||
| 46 | undef, | ||
| 47 | variable_if_template => | ||
| 48 | '<TMPL_IF NAME=variable_if><TMPL_VAR NAME=template_if_true></TMPL_IF>', | ||
| 49 | constant_if_else_template => | ||
| 50 | undef, | ||
| 51 | variable_if_else_template => | ||
| 52 | '<TMPL_IF NAME=variable_if_else><TMPL_VAR NAME=template_if_true>' . | ||
| 53 | '<TMPL_ELSE><TMPL_VAR NAME=template_if_false></TMPL_IF>', | ||
| 54 | constant_expression => | ||
| 55 | undef, | ||
| 56 | variable_expression => | ||
| 57 | undef, | ||
| 58 | complex_variable_expression => | ||
| 59 | undef, | ||
| 60 | constant_function => | ||
| 61 | undef, | ||
| 62 | variable_function => | ||
| 63 | undef, | ||
| 64 | ); | ||
| 65 | |||
| 66 | sub syntax_type { return( 'mini-language' ); } | ||
| 67 | sub pure_perl { return( 1 ); } | ||
| 68 | |||
| 69 | sub benchmark_descriptions | ||
| 70 | { | ||
| 71 | return( { | ||
| 72 | HT => | ||
| 73 | "HTML::Template ($HTML::Template::VERSION)", | ||
| 74 | } ); | ||
| 75 | } | ||
| 76 | |||
| 77 | sub benchmark_functions_for_uncached_string | ||
| 78 | { | ||
| 79 | my ( $self ) = @_; | ||
| 80 | |||
| 81 | return( { | ||
| 82 | HT => | ||
| 83 | sub | ||
| 84 | { | ||
| 85 | my $t = HTML::Template->new( | ||
| 86 | type => 'scalarref', | ||
| 87 | source => \$_[ 0 ], | ||
| 88 | case_sensitive => 1, | ||
| 89 | die_on_bad_params => 0, | ||
| 90 | ); | ||
| 91 | $t->param( $_[ 1 ] ); | ||
| 92 | $t->param( $_[ 2 ] ); | ||
| 93 | \$t->output(); | ||
| 94 | }, | ||
| 95 | } ); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub benchmark_functions_for_uncached_disk | ||
| 99 | { | ||
| 100 | my ( $self, $template_dir ) = @_; | ||
| 101 | my ( @template_dirs ); | ||
| 102 | |||
| 103 | @template_dirs = ( $template_dir ); | ||
| 104 | |||
| 105 | return( { | ||
| 106 | HT => | ||
| 107 | sub | ||
| 108 | { | ||
| 109 | my $t = HTML::Template->new( | ||
| 110 | type => 'filename', | ||
| 111 | path => \@template_dirs, | ||
| 112 | source => $_[ 0 ], | ||
| 113 | case_sensitive => 1, | ||
| 114 | file_cache => 0, | ||
| 115 | die_on_bad_params => 0, | ||
| 116 | ); | ||
| 117 | $t->param( $_[ 1 ] ); | ||
| 118 | $t->param( $_[ 2 ] ); | ||
| 119 | \$t->output(); | ||
| 120 | }, | ||
| 121 | } ); | ||
| 122 | } | ||
| 123 | |||
| 124 | sub benchmark_functions_for_disk_cache | ||
| 125 | { | ||
| 126 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 127 | my ( @template_dirs ); | ||
| 128 | |||
| 129 | @template_dirs = ( $template_dir ); | ||
| 130 | |||
| 131 | return( { | ||
| 132 | HT => | ||
| 133 | sub | ||
| 134 | { | ||
| 135 | my $t = HTML::Template->new( | ||
| 136 | type => 'filename', | ||
| 137 | path => \@template_dirs, | ||
| 138 | source => $_[ 0 ], | ||
| 139 | case_sensitive => 1, | ||
| 140 | file_cache => 1, | ||
| 141 | file_cache_dir => $cache_dir, | ||
| 142 | die_on_bad_params => 0, | ||
| 143 | ); | ||
| 144 | $t->param( $_[ 1 ] ); | ||
| 145 | $t->param( $_[ 2 ] ); | ||
| 146 | \$t->output(); | ||
| 147 | }, | ||
| 148 | } ); | ||
| 149 | } | ||
| 150 | |||
| 151 | sub benchmark_functions_for_shared_memory_cache | ||
| 152 | { | ||
| 153 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 154 | my ( @template_dirs ); | ||
| 155 | |||
| 156 | # TODO: some means to push this onto error stack? | ||
| 157 | eval "use IPC::SharedCache"; | ||
| 158 | return( undef ) if $@; | ||
| 159 | |||
| 160 | @template_dirs = ( $template_dir ); | ||
| 161 | |||
| 162 | return( { | ||
| 163 | HT => | ||
| 164 | sub | ||
| 165 | { | ||
| 166 | my $t = HTML::Template->new( | ||
| 167 | type => 'filename', | ||
| 168 | path => \@template_dirs, | ||
| 169 | source => $_[ 0 ], | ||
| 170 | case_sensitive => 1, | ||
| 171 | shared_cache => 1, | ||
| 172 | die_on_bad_params => 0, | ||
| 173 | ); | ||
| 174 | $t->param( $_[ 1 ] ); | ||
| 175 | $t->param( $_[ 2 ] ); | ||
| 176 | \$t->output(); | ||
| 177 | }, | ||
| 178 | } ); | ||
| 179 | } | ||
| 180 | |||
| 181 | sub benchmark_functions_for_memory_cache | ||
| 182 | { | ||
| 183 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 184 | my ( @template_dirs ); | ||
| 185 | |||
| 186 | @template_dirs = ( $template_dir ); | ||
| 187 | |||
| 188 | return( { | ||
| 189 | HT => | ||
| 190 | sub | ||
| 191 | { | ||
| 192 | my $t = HTML::Template->new( | ||
| 193 | type => 'filename', | ||
| 194 | path => \@template_dirs, | ||
| 195 | source => $_[ 0 ], | ||
| 196 | case_sensitive => 1, | ||
| 197 | cache => 1, | ||
| 198 | die_on_bad_params => 0, | ||
| 199 | ); | ||
| 200 | $t->param( $_[ 1 ] ); | ||
| 201 | $t->param( $_[ 2 ] ); | ||
| 202 | \$t->output(); | ||
| 203 | }, | ||
| 204 | } ); | ||
| 205 | } | ||
| 206 | |||
| 207 | sub benchmark_functions_for_instance_reuse | ||
| 208 | { | ||
| 209 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 210 | |||
| 211 | return( undef ); | ||
| 212 | } | ||
| 213 | |||
| 214 | 1; | ||
| 215 | |||
| 216 | __END__ | ||