Debian Codegraph @

examples/test.cgi

raw
1 #!/usr/local/bin/perl -T
2 #
3 # Author: Timm Murray <[email protected]>
4 # Name: test
5 # Description: Demonstates the use of a test template
6 #
7
8 =head1 COPYRIGHT
9
10 Copyright 2003, American Society of Agronomy. All rights reserved.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
14
15 a) the GNU General Public License as published by the Free Software
16 Foundation; either version 2, or (at your option) any later version, or
17
18 b) the "Artistic License" which comes with Perl.
19
20 =cut
21
22
23 use strict;
24 use warnings;
25
26 use constant DEBUG => 1;
27
28
29 {
30 my @FIELDS = qw( foo );
31 sub set_params
32 {
33 my $q = shift;
34 my %params = map { $_ => $q->param($_) || 0 } @FIELDS;
35 return \%params;
36 }
37 }
38
39 sub get_template
40 {
41 my $template_data;
42 while(my $line = <DATA>) { $template_data .= $line }
43
44 my $tmpl;
45 if(DEBUG) {
46 use HTML::Template::Dumper;
47 $tmpl = HTML::Template::Dumper->new(
48 scalarref => \$template_data,
49 );
50 }
51 else {
52 use HTML::Template;
53 $tmpl = HTML::Template->new(
54 scalarref => \$template_data,
55 );
56 }
57
58 return $tmpl;
59 }
60
61
62 {
63 use CGI;
64 my $q = CGI->new();
65 my $params = set_params($q);
66
67 my $tmpl = get_template();
68 $tmpl->param( bar => $params->{foo} + 1 );
69
70 print $q->header('text/html');
71 $tmpl->output( print_to => *STDOUT );
72 }
73
74
75 __DATA__
76
77 <html>
78 <head>
79 <title>Test Page</title>
80 </head>
81 <body bgcolor="#FFFFFF">
82 <pre>
83 <TMPL_VAR bar>
84 </pre>
85 </body>
86 </html>
87