« lib/Template/Benchmark/Engines/TextTemplateSimple.pm
↑ Summary
lib/Template/Benchmark/Engines/TextTmpl.pm »
| 1 | package Template::Benchmark::Engines::TextTemplet; | ||
| 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::Templet; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | |||
| 10 | our $VERSION = '1.09_01'; | ||
| 11 | |||
| 12 | use vars qw/$args $loop_counter @sorted_keys/; | ||
| 13 | |||
| 14 | our %feature_syntaxes = ( | ||
| 15 | literal_text => | ||
| 16 | join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ), | ||
| 17 | scalar_variable => | ||
| 18 | '$args->{scalar_variable}', | ||
| 19 | hash_variable_value => | ||
| 20 | '$args->{hash_variable}->{hash_value_key}', | ||
| 21 | array_variable_value => | ||
| 22 | '$args->{array_variable}->[ 2 ]', | ||
| 23 | deep_data_structure_value => | ||
| 24 | '$args->{this}->{is}{a}{very}{deep}{hash}{structure}', | ||
| 25 | array_loop_value => | ||
| 26 | # Oh good lord... | ||
| 27 | '<% $loop_counter = -1 %>' . | ||
| 28 | '<%LOOP%>' . | ||
| 29 | '<% $loop_counter++; ' . | ||
| 30 | 'return "*LOOP" ' . | ||
| 31 | 'if $loop_counter >= scalar( @{$args->{array_loop}} ); "" %>' . | ||
| 32 | '$args->{array_loop}->[$loop_counter]' . | ||
| 33 | '<%*LOOP%>', | ||
| 34 | hash_loop_value => | ||
| 35 | # Argh! | ||
| 36 | '<% $loop_counter = -1 %>' . | ||
| 37 | '<% @sorted_keys = sort( keys( %{$args->{hash_loop}} ) ) %>' . | ||
| 38 | '<%LOOP%>' . | ||
| 39 | '<% $loop_counter++; ' . | ||
| 40 | 'return "*LOOP" ' . | ||
| 41 | 'if $loop_counter >= scalar( @sorted_keys ); "" %>' . | ||
| 42 | '$sorted_keys[$loop_counter]: ' . | ||
| 43 | '$args->{hash_loop}->{$sorted_keys[$loop_counter]}' . | ||
| 44 | '<%*LOOP%>', | ||
| 45 | records_loop_value => | ||
| 46 | '<% $loop_counter = -1 %>' . | ||
| 47 | '<%LOOP%>' . | ||
| 48 | '<% $loop_counter++; ' . | ||
| 49 | 'return "*LOOP" ' . | ||
| 50 | 'if $loop_counter >= scalar( @{$args->{records_loop}} ); "" %>' . | ||
| 51 | '$args->{records_loop}->[$loop_counter]->{name}: ' . | ||
| 52 | '$args->{records_loop}->[$loop_counter]->{age}' . | ||
| 53 | '<%*LOOP%>', | ||
| 54 | array_loop_template => | ||
| 55 | '<% $loop_counter = -1 %>' . | ||
| 56 | '<%LOOP%>' . | ||
| 57 | '<% $loop_counter++; ' . | ||
| 58 | 'return "*LOOP" ' . | ||
| 59 | 'if $loop_counter >= scalar( @{$args->{array_loop}} ); "" %>' . | ||
| 60 | '$args->{array_loop}->[$loop_counter]' . | ||
| 61 | '<%*LOOP%>', | ||
| 62 | hash_loop_template => | ||
| 63 | # Argh! | ||
| 64 | '<% $loop_counter = -1 %>' . | ||
| 65 | '<% @sorted_keys = sort( keys( %{$args->{hash_loop}} ) ) %>' . | ||
| 66 | '<%LOOP%>' . | ||
| 67 | '<% $loop_counter++; ' . | ||
| 68 | 'return "*LOOP" ' . | ||
| 69 | 'if $loop_counter >= scalar( @sorted_keys ); "" %>' . | ||
| 70 | '$sorted_keys[$loop_counter]: ' . | ||
| 71 | '$args->{hash_loop}->{$sorted_keys[$loop_counter]}' . | ||
| 72 | '<%*LOOP%>', | ||
| 73 | records_loop_template => | ||
| 74 | '<% $loop_counter = -1 %>' . | ||
| 75 | '<%LOOP%>' . | ||
| 76 | '<% $loop_counter++; ' . | ||
| 77 | 'return "*LOOP" ' . | ||
| 78 | 'if $loop_counter >= scalar( @{$args->{records_loop}} ); "" %>' . | ||
| 79 | '$args->{records_loop}->[$loop_counter]->{name}: ' . | ||
| 80 | '$args->{records_loop}->[$loop_counter]->{age}' . | ||
| 81 | '<%*LOOP%>', | ||
| 82 | constant_if_literal => | ||
| 83 | '<% "IF" unless 1 %>true<%IF%>', | ||
| 84 | variable_if_literal => | ||
| 85 | '<% "IF" unless $args->{variable_if} %>true<%IF%>', | ||
| 86 | constant_if_else_literal => | ||
| 87 | '<% "*ELSE" unless 1 %>true<%*ELSE%>false<%ELSE%>', | ||
| 88 | variable_if_else_literal => | ||
| 89 | '<% "*ELSE" unless $args->{variable_if_else} %>true<%*ELSE%>' . | ||
| 90 | 'false<%ELSE%>', | ||
| 91 | constant_if_template => | ||
| 92 | '<% "IF" unless 1 %>$args->{template_if_true}<%IF%>', | ||
| 93 | variable_if_template => | ||
| 94 | '<% "IF" unless $args->{variable_if} %>$args->{template_if_true}<%IF%>', | ||
| 95 | constant_if_else_template => | ||
| 96 | '<% "*ELSE" unless 1 %>$args->{template_if_true}<%*ELSE%>' . | ||
| 97 | '$args->{template_if_false}<%ELSE%>', | ||
| 98 | variable_if_else_template => | ||
| 99 | '<% "*ELSE" unless $args->{variable_if_else} %>' . | ||
| 100 | '$args->{template_if_true}<%*ELSE%>' . | ||
| 101 | '$args->{template_if_false}<%ELSE%>', | ||
| 102 | constant_expression => | ||
| 103 | '<% &$_outf( 10 + 12 ) %>', | ||
| 104 | variable_expression => | ||
| 105 | '<% &$_outf( $args->{variable_expression_a} * ' . | ||
| 106 | '$args->{variable_expression_b} ) %>', | ||
| 107 | complex_variable_expression => | ||
| 108 | '<% &$_outf( ( ( $args->{variable_expression_a} * ' . | ||
| 109 | '$args->{variable_expression_b} ) + ' . | ||
| 110 | '$args->{variable_expression_a} - ' . | ||
| 111 | '$args->{variable_expression_b} ) / ' . | ||
| 112 | '$args->{variable_expression_b} ) %>', | ||
| 113 | constant_function => | ||
| 114 | q{<% &$_outf( substr( 'this has a substring.', 11, 9 ) ) %>}, | ||
| 115 | variable_function => | ||
| 116 | '<% &$_outf( substr( $args->{variable_function_arg}, 4, 2 ) ) %>', | ||
| 117 | ); | ||
| 118 | |||
| 119 | sub syntax_type { return( 'embedded-perl' ); } | ||
| 120 | sub pure_perl { return( 1 ); } | ||
| 121 | |||
| 122 | sub benchmark_descriptions | ||
| 123 | { | ||
| 124 | return( { | ||
| 125 | TeTemplet => | ||
| 126 | "Text::Templet ($Text::Templet::VERSION)", | ||
| 127 | } ); | ||
| 128 | } | ||
| 129 | |||
| 130 | # Labels need to be unique, so we have to fudge them to work | ||
| 131 | # with template_repeats. | ||
| 132 | sub preprocess_template | ||
| 133 | { | ||
| 134 | my ( $self, $template ) = @_; | ||
| 135 | my ( $label_id ); | ||
| 136 | |||
| 137 | # Replace label pairs first. | ||
| 138 | $label_id = 0; | ||
| 139 | $template =~ s~IF~'IF' . ( int( $label_id++ / 2 ) )~geo; | ||
| 140 | |||
| 141 | # Replace label triplets next. | ||
| 142 | $label_id = 0; | ||
| 143 | $template =~ s~(\*?(?:LOOP|ELSE))~$1 . ( int( $label_id++ / 3 ) )~geo; | ||
| 144 | |||
| 145 | return( $template ); | ||
| 146 | } | ||
| 147 | |||
| 148 | sub benchmark_functions_for_uncached_string | ||
| 149 | { | ||
| 150 | my ( $self ) = @_; | ||
| 151 | |||
| 152 | return( { | ||
| 153 | TeTemplet => | ||
| 154 | sub | ||
| 155 | { | ||
| 156 | local $args = { %{$_[ 1 ]}, %{$_[ 2 ]} }; | ||
| 157 | my $t = Templet( $_[ 0 ] ); | ||
| 158 | \$t; | ||
| 159 | }, | ||
| 160 | } ); | ||
| 161 | |||
| 162 | return( undef ); | ||
| 163 | } | ||
| 164 | |||
| 165 | sub benchmark_functions_for_uncached_disk | ||
| 166 | { | ||
| 167 | my ( $self, $template_dir ) = @_; | ||
| 168 | |||
| 169 | return( undef ); | ||
| 170 | } | ||
| 171 | |||
| 172 | sub benchmark_functions_for_disk_cache | ||
| 173 | { | ||
| 174 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 175 | |||
| 176 | return( undef ); | ||
| 177 | } | ||
| 178 | |||
| 179 | sub benchmark_functions_for_shared_memory_cache | ||
| 180 | { | ||
| 181 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 182 | |||
| 183 | return( undef ); | ||
| 184 | } | ||
| 185 | |||
| 186 | sub benchmark_functions_for_memory_cache | ||
| 187 | { | ||
| 188 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 189 | |||
| 190 | return( undef ); | ||
| 191 | } | ||
| 192 | |||
| 193 | sub benchmark_functions_for_instance_reuse | ||
| 194 | { | ||
| 195 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 196 | |||
| 197 | return( undef ); | ||
| 198 | } | ||
| 199 | |||
| 200 | 1; | ||
| 201 | |||
| 202 | __END__ | ||