« lib/Template/Benchmark/Engines/TextMicroTemplate.pm
↑ Summary
lib/Template/Benchmark/Engines/TextMiniTmpl.pm »
| 1 | package Template::Benchmark::Engines::TextMicroTemplateExtended; | ||
| 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::MicroTemplate::Extended; |
|
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 | '<?= $_[0]->{scalar_variable} ?>', | ||
| 17 | hash_variable_value => | ||
| 18 | '<?= $_[0]->{hash_variable}{hash_value_key} ?>', | ||
| 19 | array_variable_value => | ||
| 20 | '<?= $_[0]->{array_variable}[ 2 ] ?>', | ||
| 21 | deep_data_structure_value => | ||
| 22 | '<?= $_[0]->{this}{is}{a}{very}{deep}{hash}{structure} ?>', | ||
| 23 | array_loop_value => | ||
| 24 | '<? foreach ( @{$_[0]->{array_loop}} ) { ?><?= $_ ?><? } ?>', | ||
| 25 | hash_loop_value => | ||
| 26 | '<? foreach ( sort( keys( %{$_[0]->{hash_loop}} ) ) ) { ?>' . | ||
| 27 | '<?= $_ ?>: <?= $_[0]->{hash_loop}{$_} ?>' . | ||
| 28 | '<? } ?>', | ||
| 29 | records_loop_value => | ||
| 30 | '<? foreach ( @{$_[0]->{records_loop}} ) { ?>' . | ||
| 31 | '<?= $_->{name} ?>: <?= $_->{age} ?>' . | ||
| 32 | '<? } ?>', | ||
| 33 | array_loop_template => | ||
| 34 | '<? foreach ( @{$_[0]->{array_loop}} ) { ?><?= $_ ?><? } ?>', | ||
| 35 | hash_loop_template => | ||
| 36 | '<? foreach ( sort( keys( %{$_[0]->{hash_loop}} ) ) ) { ?>' . | ||
| 37 | '<?= $_ ?>: <?= $_[0]->{hash_loop}{$_} ?>' . | ||
| 38 | '<? } ?>', | ||
| 39 | records_loop_template => | ||
| 40 | '<? foreach ( @{$_[0]->{records_loop}} ) { ?>' . | ||
| 41 | '<?= $_->{name} ?>: <?= $_->{age} ?>' . | ||
| 42 | '<? } ?>', | ||
| 43 | constant_if_literal => | ||
| 44 | '<? if( 1 ) { ?>true<? } ?>', | ||
| 45 | variable_if_literal => | ||
| 46 | '<? if( $_[0]->{variable_if} ) { ?>true<? } ?>', | ||
| 47 | constant_if_else_literal => | ||
| 48 | '<? if( 1 ) { ?>true<? } else { ?>false<? } ?>', | ||
| 49 | variable_if_else_literal => | ||
| 50 | '<? if( $_[0]->{variable_if_else} ) { ?>true<? } else { ?>' . | ||
| 51 | 'false<? } ?>', | ||
| 52 | constant_if_template => | ||
| 53 | '<? if( 1 ) { ?><?= $_[0]->{template_if_true} ?><? } ?>', | ||
| 54 | variable_if_template => | ||
| 55 | '<? if( $_[0]->{variable_if} ) { ?><?= $_[0]->{template_if_true} ?>' . | ||
| 56 | '<? } ?>', | ||
| 57 | constant_if_else_template => | ||
| 58 | '<? if( 1 ) { ?><?= $_[0]->{template_if_true} ?><? } else { ?>' . | ||
| 59 | '<?= $_[0]->{template_if_false} ?><? } ?>', | ||
| 60 | variable_if_else_template => | ||
| 61 | '<? if( $_[0]->{variable_if_else} ) { ?>' . | ||
| 62 | '<?= $_[0]->{template_if_true} ?><? } else { ?>' . | ||
| 63 | '<?= $_[0]->{template_if_false} ?><? } ?>', | ||
| 64 | constant_expression => | ||
| 65 | '<?= 10 + 12 ?>', | ||
| 66 | variable_expression => | ||
| 67 | '<?= $_[0]->{variable_expression_a} * ' . | ||
| 68 | '$_[0]->{variable_expression_b} ?>', | ||
| 69 | complex_variable_expression => | ||
| 70 | '<?= ( ( $_[0]->{variable_expression_a} * ' . | ||
| 71 | '$_[0]->{variable_expression_b} ) + ' . | ||
| 72 | '$_[0]->{variable_expression_a} - ' . | ||
| 73 | '$_[0]->{variable_expression_b} ) / ' . | ||
| 74 | '$_[0]->{variable_expression_b} ?>', | ||
| 75 | constant_function => | ||
| 76 | q{<?= substr( 'this has a substring.', 11, 9 ) ?>}, | ||
| 77 | variable_function => | ||
| 78 | '<?= substr( $_[0]->{variable_function_arg}, 4, 2 ) ?>', | ||
| 79 | ); | ||
| 80 | |||
| 81 | sub syntax_type { return( 'embedded-perl' ); } | ||
| 82 | sub pure_perl { return( 1 ); } | ||
| 83 | |||
| 84 | sub benchmark_descriptions | ||
| 85 | { | ||
| 86 | return( { | ||
| 87 | TeMTE => | ||
| 88 | "Text::MicroTemplate::Extended " . | ||
| 89 | "($Text::MicroTemplate::Extended::VERSION)", | ||
| 90 | } ); | ||
| 91 | } | ||
| 92 | |||
| 93 | sub benchmark_functions_for_uncached_string | ||
| 94 | { | ||
| 95 | my ( $self ) = @_; | ||
| 96 | |||
| 97 | return( undef ); | ||
| 98 | } | ||
| 99 | |||
| 100 | sub benchmark_functions_for_uncached_disk | ||
| 101 | { | ||
| 102 | my ( $self, $template_dir ) = @_; | ||
| 103 | |||
| 104 | return( { | ||
| 105 | TeMTE => | ||
| 106 | sub | ||
| 107 | { | ||
| 108 | my $t = Text::MicroTemplate::Extended->new( | ||
| 109 | include_path => [ $template_dir ], | ||
| 110 | extension => '', | ||
| 111 | escape_func => undef, | ||
| 112 | use_cache => 0, | ||
| 113 | ); | ||
| 114 | \$t->render_file( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 115 | }, | ||
| 116 | } ); | ||
| 117 | } | ||
| 118 | |||
| 119 | sub benchmark_functions_for_disk_cache | ||
| 120 | { | ||
| 121 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 122 | |||
| 123 | return( undef ); | ||
| 124 | } | ||
| 125 | |||
| 126 | sub benchmark_functions_for_shared_memory_cache | ||
| 127 | { | ||
| 128 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 129 | |||
| 130 | return( undef ); | ||
| 131 | } | ||
| 132 | |||
| 133 | sub benchmark_functions_for_memory_cache | ||
| 134 | { | ||
| 135 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 136 | |||
| 137 | return( { | ||
| 138 | TeMTE => | ||
| 139 | sub | ||
| 140 | { | ||
| 141 | my $t = Text::MicroTemplate::Extended->new( | ||
| 142 | include_path => [ $template_dir ], | ||
| 143 | extension => '', | ||
| 144 | escape_func => undef, | ||
| 145 | use_cache => 1, | ||
| 146 | ); | ||
| 147 | \$t->render_file( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 148 | }, | ||
| 149 | } ); | ||
| 150 | } | ||
| 151 | |||
| 152 | sub benchmark_functions_for_instance_reuse | ||
| 153 | { | ||
| 154 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 155 | |||
| 156 | return( undef ); | ||
| 157 | } | ||
| 158 | |||
| 159 | 1; | ||
| 160 | |||
| 161 | __END__ | ||