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