Changeset 27051 for lang/perl/Text-MicroTemplate
- Timestamp:
- 12/19/08 11:04:19 (4 years ago)
- Location:
- lang/perl/Text-MicroTemplate/trunk
- Files:
-
- 3 modified
-
lib/Text/MicroTemplate.pm (modified) (8 diffs)
-
t/03-modes.t (modified) (2 diffs)
-
t/04-multiline.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Text-MicroTemplate/trunk/lib/Text/MicroTemplate.pm
r27003 r27051 25 25 comment_mark => '#', 26 26 expression_mark => '=', 27 raw_expression_mark => '=r',28 27 line_start => '?', 29 28 template => undef, … … 122 121 $lines[-1] .= "\$_MT_T = scalar $value; \$_MT .= ref \$_MT_T eq 'Text::MicroTemplate::EncodedString' ? \$\$_MT_T : $escape_func(\$_MT_T);"; 123 122 } 124 125 # Raw Expression126 if ($type eq 'raw_expr') {127 128 $lines[-1] .= "\$_MT_T = $value; \$_MT .= ref \$_MT_T eq q(Text::MicroTemplate::EncodedString) ? \$\$_MT_T : \$_MT_T;";129 }130 123 } 131 124 } … … 160 153 my $cmnt_mark = quotemeta $self->{comment_mark}; 161 154 my $expr_mark = quotemeta $self->{expression_mark}; 162 my $raw_expr_mark = quotemeta $self->{raw_expression_mark};163 155 164 156 # Tokenize … … 191 183 } 192 184 193 # Perl line with raw return value194 if ($line =~ /^$line_start$raw_expr_mark\s+(.+)$/) {195 push @{$self->{tree}}, [196 'raw_expr', $1,197 $newline ? ('text', "\n") : (),198 ];199 $multiline_expression = 0;200 next;201 }202 203 185 # Comment line, dummy token needed for line count 204 186 if ($line =~ /^$line_start$cmnt_mark\s+$/) { … … 231 213 for my $token (split / 232 214 ( 233 $tag_start$raw_expr_mark # Raw Expression234 |235 215 $tag_start$expr_mark # Expression 236 216 | … … 258 238 elsif ($token =~ /^$tag_start$cmnt_mark$/) { $state = 'cmnt' } 259 239 260 # Raw Expression261 elsif ($token =~ /^$tag_start$raw_expr_mark$/) {262 $state = 'raw_expr';263 }264 265 240 # Expression 266 241 elsif ($token =~ /^$tag_start$expr_mark$/) { … … 278 253 $state = 'code' if $multiline_expression; 279 254 $multiline_expression = 1 280 if $state eq 'expr' || $state eq 'raw_expr';255 if $state eq 'expr'; 281 256 282 257 # Store value … … 487 462 ?= $expr (per-line) 488 463 489 # output the result expression without escape (tag style)490 <?=r $raw_str ?>491 ?=r $raw_str492 493 464 # execute perl code (tag style) 494 465 <? foo() ?> -
lang/perl/Text-MicroTemplate/trunk/t/03-modes.t
r26831 r27051 1 1 use strict; 2 2 use warnings; 3 use Test::More tests => 8;3 use Test::More tests => 6; 4 4 use Text::MicroTemplate qw(:all); 5 5 … … 16 16 do { 17 17 is render_mt('<?= $_[0] ?>', 'foo<a')->as_string, 'foo<a'; 18 is render_mt('<?=r $_[0] ?>', 'foo<a')->as_string, 'foo<a';19 18 my $rs = encoded_string('foo<a'); 20 19 is render_mt('<?= $_[0] ?>', $rs)->as_string, 'foo<a'; 21 is render_mt('<?=r $_[0] ?>', $rs)->as_string, 'foo<a';22 20 }; 23 21 do { -
lang/perl/Text-MicroTemplate/trunk/t/04-multiline.t
r26831 r27051 1 1 use strict; 2 2 use warnings; 3 use Test::More tests => 7;3 use Test::More tests => 4; 4 4 use Text::MicroTemplate qw(:all); 5 5 … … 14 14 }; 15 15 16 # raw expr (expected behaviour from code)17 do {18 my $y;19 is render_mt(<<'...', sub { $y = 1 })->as_string, "abc 1 def\n", 'multiline rawexpr';20 abc <?=r 121 $_[0]->() ?> def22 ...23 ok $y;24 };25 26 16 # automatic semicolon insertion 27 17 is render_mt(<<'...')->as_string, "abc\n1\n-1\ndef\n", 'expr auto-sci'; … … 29 19 ?= 1 30 20 ?= -1 31 def32 ...33 is render_mt(<<'...')->as_string, "abc\n1\n-1\ndef\n", 'expr auto-sci';34 abc35 ?=r 136 ?=r -137 21 def 38 22 ...
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)