X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=samples%2Fmemory_template.pl;h=070c5054ee3c01c1e8ba72e6cf8167d42cd32e7f;hb=aa030874456c91d688e6c9b25e82d2bf9575ea6f;hp=28b17105331b72f6328abd0bb60894ba259827a8;hpb=4eee158dce82376f2f37de29d91c53f60a24aebe;p=chaz%2Fp5-CGI-Ex diff --git a/samples/memory_template.pl b/samples/memory_template.pl index 28b1710..070c505 100644 --- a/samples/memory_template.pl +++ b/samples/memory_template.pl @@ -10,30 +10,90 @@ my $swap = { }; my $txt = "[% one %][% two %][% three %][% hash.keys.join %] [% code(one).length %] [% hash.\$a_var %]\n"; +#$txt = hello2000(); ###----------------------------------------------------------------### my $module; +my $name; if (! fork) { $module = 'CGI::Ex::Template'; - $0 = "perl $module"; +} elsif (! fork) { + $module = 'CGI::Ex::Template::XS'; +} elsif (! fork) { + $module = 'Template'; } elsif (! fork) { $module = 'Template'; - $0 = "perl $module"; + $name = 'Template Stash::XS'; + require Template::Stash::XS; +} elsif (! fork) { + $module = 'HTML::Template'; +} elsif (! fork) { + $module = 'HTML::Template::Expr'; +} elsif (! fork) { + $module = 'HTML::Template::Compiled'; +} elsif (! fork) { + $module = 'Text::Tmpl'; +} elsif (! fork) { + $module = 'Template'; + $name = 'Template::Parser::CET'; + require Template::Parser::CET; + Template::Parser::CET->activate; } if ($module) { + $name ||= $module; + $0 = "$0 - $name"; + my $pm = "$module.pm"; $pm =~ s|::|/|g; require $pm; - my $t = $module->new(ABSOLUTE => 1); - my $out = ''; - $t->process(\$txt, $swap, \$out); - print $out; -} + if ($module =~ /HTML::Template/) { + my $t = eval { $module->new }; + } elsif ($module eq 'Text::Tmpl') { + my $t = eval { $module->new->parse_string($txt) }; + } else { -sleep 15; # go and check the 'ps fauwx|grep perl' + my $t = $module->new(ABSOLUTE => 1); + my $out = ''; + $t->process(\$txt, $swap, \$out); + print "$name $out"; + for (1..30) { my $out; $t->process(\$txt, $swap, \$out); }; + } +# print "$name $_\n" foreach sort keys %INC; + print "$name times: (@{[times]})\n"; + sleep 15; + exit; +} + +sleep 2; +print grep {/\Q$0\E/} `ps fauwx`; +#sleep 15; # go and check the 'ps fauwx|grep perl' +exit; ###----------------------------------------------------------------### + +sub hello2000 { + my $hello2000 = "[% title %] +[% array = [ \"Hello\", \"World\", \"2000\", \"Hello\", \"World\", \"2000\" ] %] +[% sorted = array.sort %] +[% multi = [ sorted, sorted, sorted, sorted, sorted ] %] + +[% FOREACH row = multi %] + + [% FOREACH col = row %] + + [% END %] + +[% END %] +
[% col %]
+[% param = integer %] +[% FOREACH i = [ 1 .. 10 ] %] + [% var = i + param %]" + .("\n [%var%] Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
"x20)." +[% END %] + +"; +}