« lib/Template/Benchmark/Engines/TextClevery.pm
↑ Summary
lib/Template/Benchmark/Engines/TextMicroMasonTeTe.pm »
| 1 | package Template::Benchmark::Engines::TextMicroMasonHM; | ||
| 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::MicroMason; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | |||
| 10 | use File::Spec; | ||
| 11 | |||
| 12 | our $VERSION = '1.09_01'; | ||
| 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 | '% $_out->( $_ ) foreach @{$ARGS{array_loop}};' . "\n", | ||
| 27 | hash_loop_value => | ||
| 28 | '% $_out->( "$_: $ARGS{hash_loop}->{$_}" ) foreach sort( keys( %{$ARGS{hash_loop}} ) );' . "\n", | ||
| 29 | records_loop_value => | ||
| 30 | '% $_out->( "$_->{name}: $_->{age}" ) foreach @{$ARGS{records_loop}};' . "\n", | ||
| 31 | array_loop_template => | ||
| 32 | '<%perl>foreach ( @{$ARGS{array_loop}} ) {</%perl>' . | ||
| 33 | '<% $_ %>' . | ||
| 34 | '<%perl>}</%perl>' . "\n", | ||
| 35 | hash_loop_template => | ||
| 36 | '<%perl>foreach ( sort( keys( %{$ARGS{hash_loop}} ) ) ) {</%perl>' . | ||
| 37 | '<% $_ %>: <% $ARGS{hash_loop}->{$_} %>' . | ||
| 38 | '<%perl>}</%perl>' . "\n", | ||
| 39 | records_loop_template => | ||
| 40 | '<%perl>foreach ( @{$ARGS{records_loop}} ) {</%perl>' . | ||
| 41 | '<% $_->{ name } %>: <% $_->{ age } %>' . | ||
| 42 | '<%perl>}</%perl>' . "\n", | ||
| 43 | constant_if_literal => | ||
| 44 | '<%perl>if( 1 ) {</%perl>true<%perl>}</%perl>' . "\n", | ||
| 45 | variable_if_literal => | ||
| 46 | '<%perl>if( $ARGS{variable_if} ) {</%perl>true<%perl>}</%perl>' . "\n", | ||
| 47 | constant_if_else_literal => | ||
| 48 | '<%perl>if( 1 ) {</%perl>true<%perl>} else {</%perl>' . | ||
| 49 | 'false<%perl>}</%perl>' . "\n", | ||
| 50 | variable_if_else_literal => | ||
| 51 | '<%perl>if( $ARGS{variable_if_else} ) {</%perl>true<%perl>} ' . | ||
| 52 | 'else {</%perl>false<%perl>}</%perl>' . "\n", | ||
| 53 | constant_if_template => | ||
| 54 | '<%perl>if( 1 ) {</%perl>' . | ||
| 55 | '<% $ARGS{template_if_true} %><%perl>}</%perl>' . "\n", | ||
| 56 | variable_if_template => | ||
| 57 | '<%perl>if( $ARGS{variable_if} ) {</%perl>' . | ||
| 58 | '<% $ARGS{template_if_true} %><%perl>}</%perl>' . "\n", | ||
| 59 | constant_if_else_template => | ||
| 60 | '<%perl>if( 1 ) {</%perl>' . | ||
| 61 | '<% $ARGS{template_if_true} %><%perl>} ' . | ||
| 62 | 'else {</%perl>' . | ||
| 63 | '<% $ARGS{template_if_false} %><%perl>}</%perl>' . "\n", | ||
| 64 | variable_if_else_template => | ||
| 65 | '<%perl>if( $ARGS{variable_if_else} ) {</%perl>' . | ||
| 66 | '<% $ARGS{template_if_true} %><%perl>} ' . | ||
| 67 | 'else {</%perl>' . | ||
| 68 | '<% $ARGS{template_if_false} %><%perl>}</%perl>' . "\n", | ||
| 69 | constant_expression => | ||
| 70 | '<% 10 + 12 %>', | ||
| 71 | variable_expression => | ||
| 72 | '<% $ARGS{variable_expression_a} * $ARGS{variable_expression_b} %>', | ||
| 73 | complex_variable_expression => | ||
| 74 | '<% ( ( $ARGS{variable_expression_a} * $ARGS{variable_expression_b} ) + ' . | ||
| 75 | '$ARGS{variable_expression_a} - $ARGS{variable_expression_b} ) / ' . | ||
| 76 | '$ARGS{variable_expression_b} %>', | ||
| 77 | constant_function => | ||
| 78 | q[<% substr( 'this has a substring.', 11, 9 ) %>], | ||
| 79 | variable_function => | ||
| 80 | '<% substr( $ARGS{variable_function_arg}, 4, 2 ) %>', | ||
| 81 | ); | ||
| 82 | |||
| 83 | sub syntax_type { return( 'embedded-perl' ); } | ||
| 84 | sub pure_perl { return( 1 ); } | ||
| 85 | |||
| 86 | sub benchmark_descriptions | ||
| 87 | { | ||
| 88 | return( { | ||
| 89 | TeMMHM => | ||
| 90 | "Text::MicroMason ($Text::MicroMason::VERSION) using " . | ||
| 91 | "Text::MicroMason::HTMLMason (no version number)", | ||
| 92 | } ); | ||
| 93 | } | ||
| 94 | |||
| 95 | sub benchmark_functions_for_uncached_string | ||
| 96 | { | ||
| 97 | my ( $self ) = @_; | ||
| 98 | |||
| 99 | return( { | ||
| 100 | TeMMHM => | ||
| 101 | sub | ||
| 102 | { | ||
| 103 | my $t = Text::MicroMason->new(); | ||
| 104 | \$t->execute( | ||
| 105 | text => $_[ 0 ], | ||
| 106 | ( %{$_[ 1 ]}, %{$_[ 2 ]} ) ); | ||
| 107 | }, | ||
| 108 | } ); | ||
| 109 | } | ||
| 110 | |||
| 111 | sub benchmark_functions_for_uncached_disk | ||
| 112 | { | ||
| 113 | my ( $self, $template_dir ) = @_; | ||
| 114 | |||
| 115 | return( { | ||
| 116 | TeMMHM => | ||
| 117 | sub | ||
| 118 | { | ||
| 119 | my $t = Text::MicroMason->new(); | ||
| 120 | \$t->execute( | ||
| 121 | file => File::Spec->catfile( $template_dir, $_[ 0 ] ), | ||
| 122 | ( %{$_[ 1 ]}, %{$_[ 2 ]} ) ); | ||
| 123 | }, | ||
| 124 | } ); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub benchmark_functions_for_disk_cache | ||
| 128 | { | ||
| 129 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 130 | |||
| 131 | return( undef ); | ||
| 132 | } | ||
| 133 | |||
| 134 | sub benchmark_functions_for_shared_memory_cache | ||
| 135 | { | ||
| 136 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 137 | |||
| 138 | return( undef ); | ||
| 139 | } | ||
| 140 | |||
| 141 | sub benchmark_functions_for_memory_cache | ||
| 142 | { | ||
| 143 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 144 | |||
| 145 | return( undef ); | ||
| 146 | } | ||
| 147 | |||
| 148 | sub benchmark_functions_for_instance_reuse | ||
| 149 | { | ||
| 150 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 151 | my ( $t ); | ||
| 152 | |||
| 153 | return( { | ||
| 154 | TeMMHM => | ||
| 155 | sub | ||
| 156 | { | ||
| 157 | $t = Text::MicroMason->new()->compile( | ||
| 158 | file => File::Spec->catfile( $template_dir, $_[ 0 ] ) | ||
| 159 | ) | ||
| 160 | unless $t; | ||
| 161 | \$t->( ( %{$_[ 1 ]}, %{$_[ 2 ]} ) ); | ||
| 162 | }, | ||
| 163 | } ); | ||
| 164 | } | ||
| 165 | |||
| 166 | 1; | ||
| 167 | |||
| 168 | __END__ | ||