]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - samples/memory_template.pl
CGI::Ex 2.14
[chaz/p5-CGI-Ex] / samples / memory_template.pl
index 28b17105331b72f6328abd0bb60894ba259827a8..070c5054ee3c01c1e8ba72e6cf8167d42cd32e7f 100644 (file)
@@ -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 = "<html><head><title>[% title %]</title></head><body>
+[% array = [ \"Hello\", \"World\", \"2000\", \"Hello\", \"World\", \"2000\" ] %]
+[% sorted = array.sort %]
+[% multi = [ sorted, sorted, sorted, sorted, sorted ] %]
+<table>
+[% FOREACH row = multi %]
+  <tr bgcolor=\"[% loop.count % 2 ? 'gray' : 'white' %]\">
+  [% FOREACH col = row %]
+    <td align=\"center\"><font size=\"+1\">[% col %]</font></td>
+  [% END %]
+  </tr>
+[% END %]
+</table>
+[% 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 <br/>"x20)."
+[% END %]
+</body></html>
+";
+}
This page took 0.021829 seconds and 4 git commands to generate.