]> Dogcows Code - chaz/p5-CGI-Ex/blob - samples/memory_template.pl
CGI::Ex 2.12
[chaz/p5-CGI-Ex] / samples / memory_template.pl
1 #!/usr/bin/perl -w
2
3 my $swap = {
4 one => "ONE",
5 two => "TWO",
6 three => "THREE",
7 a_var => "a",
8 hash => {a => 1, b => 2},
9 code => sub {"($_[0])"},
10 };
11
12 my $txt = "[% one %][% two %][% three %][% hash.keys.join %] [% code(one).length %] [% hash.\$a_var %]\n";
13 #$txt = hello2000();
14
15 ###----------------------------------------------------------------###
16
17 my $module;
18 my $name;
19 if (! fork) {
20 $module = 'CGI::Ex::Template';
21 } elsif (! fork) {
22 $module = 'CGI::Ex::Template::XS';
23 } elsif (! fork) {
24 $module = 'Template';
25 } elsif (! fork) {
26 $module = 'Template';
27 $name = 'Template Stash::XS';
28 require Template::Stash::XS;
29 } elsif (! fork) {
30 $module = 'HTML::Template';
31 } elsif (! fork) {
32 $module = 'HTML::Template::Expr';
33 } elsif (! fork) {
34 $module = 'Template';
35 $name = 'Template::Parser::CET';
36 require Template::Parser::CET;
37 Template::Parser::CET->activate;
38 }
39
40 if ($module) {
41 $name ||= $module;
42 $0 = "$0 - $name";
43
44 my $pm = "$module.pm";
45 $pm =~ s|::|/|g;
46 require $pm;
47
48 if ($module =~ /HTML::Template/) {
49 my $t = eval { $module->new };
50
51 } else {
52
53 my $t = $module->new(ABSOLUTE => 1);
54 my $out = '';
55 $t->process(\$txt, $swap, \$out);
56 print "$name $out";
57 for (1..30) { my $out; $t->process(\$txt, $swap, \$out); };
58 }
59
60 # print "$name $_\n" foreach sort keys %INC;
61 print "$name times: (@{[times]})\n";
62 sleep 15;
63 exit;
64 }
65
66 sleep 2;
67 print grep {/\Q$0\E/} `ps fauwx`;
68 #sleep 15; # go and check the 'ps fauwx|grep perl'
69 exit;
70
71 ###----------------------------------------------------------------###
72
73 sub hello2000 {
74 my $hello2000 = "<html><head><title>[% title %]</title></head><body>
75 [% array = [ \"Hello\", \"World\", \"2000\", \"Hello\", \"World\", \"2000\" ] %]
76 [% sorted = array.sort %]
77 [% multi = [ sorted, sorted, sorted, sorted, sorted ] %]
78 <table>
79 [% FOREACH row = multi %]
80 <tr bgcolor=\"[% loop.count % 2 ? 'gray' : 'white' %]\">
81 [% FOREACH col = row %]
82 <td align=\"center\"><font size=\"+1\">[% col %]</font></td>
83 [% END %]
84 </tr>
85 [% END %]
86 </table>
87 [% param = integer %]
88 [% FOREACH i = [ 1 .. 10 ] %]
89 [% var = i + param %]"
90 .("\n [%var%] Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World <br/>"x20)."
91 [% END %]
92 </body></html>
93 ";
94 }
This page took 0.034816 seconds and 4 git commands to generate.