|
Revision 11644, 1.5 kB
(checked in by cho45, 8 months ago)
|
|
YAPC LT
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use Benchmark qw/:all/; |
|---|
| 7 | use Text::MicroMason; |
|---|
| 8 | use Template; |
|---|
| 9 | |
|---|
| 10 | sub unindent ($) { |
|---|
| 11 | my ($str) = @_; |
|---|
| 12 | my ($ws) = $str =~ /^(\s+)/; |
|---|
| 13 | $ws =~ s/\n//g; |
|---|
| 14 | $str =~ s/^$ws//gm; |
|---|
| 15 | $str; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | my $tt = Template->new(); |
|---|
| 19 | my $tm = Text::MicroMason->new(qw/-AllowGlobals/); |
|---|
| 20 | my $tms = Text::MicroMason->new(qw/-AllowGlobals -SafeServerPages/); |
|---|
| 21 | |
|---|
| 22 | cmpthese timethese(1000, { |
|---|
| 23 | "TT" => sub { |
|---|
| 24 | my $output; |
|---|
| 25 | $tt->process(\"[% foo %]", { |
|---|
| 26 | foo => "hogehoge" |
|---|
| 27 | }, \$output); |
|---|
| 28 | }, |
|---|
| 29 | |
|---|
| 30 | "Text::MicroMason" => sub { |
|---|
| 31 | $tm->set_globals( '$foo' => 'hogehoge' ); |
|---|
| 32 | $tm->execute(text => '<% $foo %>'); |
|---|
| 33 | }, |
|---|
| 34 | |
|---|
| 35 | "Text::MicroMason::SafeServerPages" => sub { |
|---|
| 36 | $tms->set_globals( '$foo' => 'hogehoge' ); |
|---|
| 37 | $tms->execute(text => '<%= $foo %>'); |
|---|
| 38 | } |
|---|
| 39 | }); |
|---|
| 40 | |
|---|
| 41 | print "\n\n"; |
|---|
| 42 | |
|---|
| 43 | cmpthese timethese(1000, { |
|---|
| 44 | "TT" => sub { |
|---|
| 45 | my $output; |
|---|
| 46 | $tt->process(\unindent q{ |
|---|
| 47 | <ul> |
|---|
| 48 | [% FOREACH i = items %] |
|---|
| 49 | <li>[% i %]</li> |
|---|
| 50 | [% END %] |
|---|
| 51 | </ul> |
|---|
| 52 | |
|---|
| 53 | [% foo %] |
|---|
| 54 | }, { |
|---|
| 55 | items => [qw/1 2 3 4 5 6 7 8 9 0/], |
|---|
| 56 | foo => "foo", |
|---|
| 57 | }, \$output); |
|---|
| 58 | }, |
|---|
| 59 | |
|---|
| 60 | "Text::MicroMason" => sub { |
|---|
| 61 | $tm->set_globals( |
|---|
| 62 | '$items' => [qw/1 2 3 4 5 6 7 8 9 0/], |
|---|
| 63 | '$foo' => "foo", |
|---|
| 64 | ); |
|---|
| 65 | $tm->execute(text => unindent q{ |
|---|
| 66 | <ul> |
|---|
| 67 | % for my $i ($items) { |
|---|
| 68 | <li><% $i %></li> |
|---|
| 69 | % } |
|---|
| 70 | </ul> |
|---|
| 71 | |
|---|
| 72 | <% $foo %> |
|---|
| 73 | }); |
|---|
| 74 | }, |
|---|
| 75 | |
|---|
| 76 | "Text::MicroMason::SafeServerPages" => sub { |
|---|
| 77 | $tms->set_globals( |
|---|
| 78 | '$items' => [qw/1 2 3 4 5 6 7 8 9 0/], |
|---|
| 79 | '$foo' => "foo", |
|---|
| 80 | ); |
|---|
| 81 | $tms->execute(text => unindent q{ |
|---|
| 82 | <ul> |
|---|
| 83 | <% for my $i ($items) { %> |
|---|
| 84 | <li><%= $i %></li> |
|---|
| 85 | <% } %> |
|---|
| 86 | </ul> |
|---|
| 87 | |
|---|
| 88 | <%= $foo %> |
|---|
| 89 | }); |
|---|
| 90 | }, |
|---|
| 91 | }); |
|---|