« lib/Template/Benchmark/Engines/MojoTemplate.pm
↑ Summary
lib/Template/Benchmark/Engines/TemplateToolkit.pm »
| 1 | package Template::Benchmark::Engines::Tenjin; | ||
| 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 | 1 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | # 0.05 has a different API to prior versions. | ||
| 11 | 0 | ▶ | use Tenjin 0.05; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | # Governs how long cached files remain valid, given it can be ten | ||
| 14 | # minutes or more after cache generation before it runs again, we | ||
| 15 | # want to set this to a high value. | ||
| 16 | $Tenjin::TIMESTAMP_INTERVAL = 60 * 60 * 24; | ||
| 17 | |||
| 18 | use IO::File; | ||
| 19 | |||
| 20 | our $VERSION = '1.09_01'; | ||
| 21 | |||
| 22 | our %feature_syntaxes = ( | ||
| 23 | literal_text => | ||
| 24 | join( "\n", ( join( ' ', ( 'foo' ) x 12 ) ) x 5 ), | ||
| 25 | scalar_variable => | ||
| 26 | '[== $scalar_variable =]', | ||
| 27 | hash_variable_value => | ||
| 28 | '[== $hash_variable->{hash_value_key} =]', | ||
| 29 | array_variable_value => | ||
| 30 | '[== $array_variable->[ 2 ] =]', | ||
| 31 | deep_data_structure_value => | ||
| 32 | '[== $this->{is}{a}{very}{deep}{hash}{structure} =]', | ||
| 33 | array_loop_value => | ||
| 34 | '<?pl foreach ( @{$array_loop} ) { ?>[== $_ =]<?pl } ?>' . "\n", | ||
| 35 | hash_loop_value => | ||
| 36 | '<?pl foreach ( sort( keys( %{$hash_loop} ) ) ) { ?>' . | ||
| 37 | '[== $_ =]: [== $hash_loop->{$_} =]' . | ||
| 38 | '<?pl } ?>' . "\n", | ||
| 39 | records_loop_value => | ||
| 40 | '<?pl foreach ( @{$records_loop} ) { ?>' . | ||
| 41 | '[== $_->{name} =]: [== $_->{age} =]' . | ||
| 42 | '<?pl } ?>' . "\n", | ||
| 43 | array_loop_template => | ||
| 44 | '<?pl foreach ( @{$array_loop} ) { ?>[== $_ =]<?pl } ?>' . "\n", | ||
| 45 | hash_loop_template => | ||
| 46 | '<?pl foreach ( sort( keys( %{$hash_loop} ) ) ) { ?>' . | ||
| 47 | '[== $_ =]: [== $hash_loop->{$_} =]' . | ||
| 48 | '<?pl } ?>' . "\n", | ||
| 49 | records_loop_template => | ||
| 50 | '<?pl foreach ( @{$records_loop} ) { ?>' . | ||
| 51 | '[== $_->{name} =]: [== $_->{age} =]' . | ||
| 52 | '<?pl } ?>' . "\n", | ||
| 53 | constant_if_literal => | ||
| 54 | '<?pl if( 1 ) { ?>true<?pl } ?>' . "\n", | ||
| 55 | variable_if_literal => | ||
| 56 | '<?pl if( $variable_if ) { ?>true<?pl } ?>' . "\n", | ||
| 57 | constant_if_else_literal => | ||
| 58 | '<?pl if( 1 ) { ?>true<?pl } else { ?>false<?pl } ?>' . "\n", | ||
| 59 | variable_if_else_literal => | ||
| 60 | '<?pl if( $variable_if_else ) { ?>true<?pl } else { ?>' . | ||
| 61 | 'false<?pl } ?>' . "\n", | ||
| 62 | constant_if_template => | ||
| 63 | '<?pl if( 1 ) { ?>[== $template_if_true =]<?pl } ?>' . "\n", | ||
| 64 | variable_if_template => | ||
| 65 | '<?pl if( ${variable_if} ) { ?>[== $template_if_true =]' . | ||
| 66 | '<?pl } ?>' . "\n", | ||
| 67 | constant_if_else_template => | ||
| 68 | '<?pl if( 1 ) { ?>[== $template_if_true =]<?pl } else { ?>' . | ||
| 69 | '[== $template_if_false =]<?pl } ?>' . "\n", | ||
| 70 | variable_if_else_template => | ||
| 71 | '<?pl if( $variable_if_else ) { ?>' . | ||
| 72 | '[== $template_if_true =]<?pl } else { ?>' . | ||
| 73 | '[== $template_if_false =]<?pl } ?>' . "\n", | ||
| 74 | constant_expression => | ||
| 75 | '[== 10 + 12 =]', | ||
| 76 | variable_expression => | ||
| 77 | '[== $variable_expression_a * ' . | ||
| 78 | '$variable_expression_b =]', | ||
| 79 | complex_variable_expression => | ||
| 80 | '[== ( ( $variable_expression_a * ' . | ||
| 81 | '$variable_expression_b ) + ' . | ||
| 82 | '$variable_expression_a - ' . | ||
| 83 | '$variable_expression_b ) / ' . | ||
| 84 | '$variable_expression_b =]', | ||
| 85 | constant_function => | ||
| 86 | q{[== substr( 'this has a substring.', 11, 9 ) =]}, | ||
| 87 | variable_function => | ||
| 88 | '[== substr( $variable_function_arg, 4, 2 ) =]', | ||
| 89 | ); | ||
| 90 | |||
| 91 | sub syntax_type { return( 'embedded-perl' ); } | ||
| 92 | sub pure_perl { return( 1 ); } | ||
| 93 | |||
| 94 | sub benchmark_descriptions | ||
| 95 | { | ||
| 96 | return( { | ||
| 97 | Tenj => | ||
| 98 | "Tenjin ($Tenjin::VERSION)", | ||
| 99 | } ); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub benchmark_functions_for_uncached_string | ||
| 103 | { | ||
| 104 | my ( $self ) = @_; | ||
| 105 | |||
| 106 | return( undef ); | ||
| 107 | } | ||
| 108 | |||
| 109 | sub benchmark_functions_for_uncached_disk | ||
| 110 | { | ||
| 111 | my ( $self, $template_dir ) = @_; | ||
| 112 | |||
| 113 | my ( @template_dirs ); | ||
| 114 | |||
| 115 | @template_dirs = ( $template_dir ); | ||
| 116 | |||
| 117 | return( { | ||
| 118 | Tenj => | ||
| 119 | sub | ||
| 120 | { | ||
| 121 | my $t = Tenjin->new( { | ||
| 122 | path => \@template_dirs, | ||
| 123 | cache => 0, | ||
| 124 | } ); | ||
| 125 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 126 | }, | ||
| 127 | } ); | ||
| 128 | } | ||
| 129 | |||
| 130 | sub benchmark_functions_for_disk_cache | ||
| 131 | { | ||
| 132 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 133 | my ( @template_dirs ); | ||
| 134 | |||
| 135 | @template_dirs = ( $template_dir ); | ||
| 136 | |||
| 137 | return( { | ||
| 138 | Tenj => | ||
| 139 | sub | ||
| 140 | { | ||
| 141 | my $t = Tenjin->new( { | ||
| 142 | path => \@template_dirs, | ||
| 143 | } ); | ||
| 144 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 145 | }, | ||
| 146 | } ); | ||
| 147 | } | ||
| 148 | |||
| 149 | sub benchmark_functions_for_shared_memory_cache | ||
| 150 | { | ||
| 151 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 152 | |||
| 153 | return( undef ); | ||
| 154 | } | ||
| 155 | |||
| 156 | sub benchmark_functions_for_memory_cache | ||
| 157 | { | ||
| 158 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 159 | |||
| 160 | return( undef ); | ||
| 161 | } | ||
| 162 | |||
| 163 | # TODO: this seems suspiciously slow, not sure it's caching. | ||
| 164 | sub benchmark_functions_for_instance_reuse | ||
| 165 | { | ||
| 166 | my ( $self, $template_dir, $cache_dir ) = @_; | ||
| 167 | my ( $t, @template_dirs ); | ||
| 168 | |||
| 169 | @template_dirs = ( $template_dir ); | ||
| 170 | |||
| 171 | return( { | ||
| 172 | Tenj => | ||
| 173 | sub | ||
| 174 | { | ||
| 175 | $t = Tenjin->new( { | ||
| 176 | path => \@template_dirs, | ||
| 177 | } ) | ||
| 178 | unless $t; | ||
| 179 | \$t->render( $_[ 0 ], { %{$_[ 1 ]}, %{$_[ 2 ]} } ); | ||
| 180 | }, | ||
| 181 | } ); | ||
| 182 | } | ||
| 183 | |||
| 184 | 1; | ||
| 185 | |||
| 186 | __END__ | ||