1 #!/usr/bin/perl
 2 
 3 use strict;
 4 use lib '/lib/perlmodules';
 5 use CGI;
 6 use CGI::Carp qw( fatalsToBrowser );
 7 
 8 #------------------------------------------------------------------------#
 9 # Main
10 #------------------------------------------------------------------------#
11 
12 #
13 # Initialize the CGI Object
14 my $c = new CGI;
15 
16 #
17 # Set the $SCRIPT variable
18 my $SCRIPT = $c->url(-absolute=>1);
19 
20 #
21 # Dispatch Table
22 my %dispatch = (
23 	_DEFAULT_	=> \&default,
24 	display		=> \&display,
25 );
26 
27 #
28 # Determine the Action
29 my $action = $c->param('action');
30 
31 if( !exists $dispatch{$action} ) {
32 	$action = '_DEFAULT_';
33 }
34 
35 #
36 # Call the Dispatch
37 $dispatch{$action}->();
38 
39 
40 #------------------------------------------------------------------------#
41 # Functions
42 #------------------------------------------------------------------------#
43 
44 
45 #------------------------------------------------------------------------#
46 # Default Action
47 sub default {
48 
49 	my @TableRows = ();
50 	push @TableRows,
51 		$c->Tr(
52 			$c->th({-class=>'heading'}, q|Your Name:|),
53 			$c->td(
54 				$c->textfield(
55 					-name=>'yourname',
56 					-value=>'',
57 					-maxlength=>25,
58 					-size=>12,
59 					-class=>'userinput',
60 				)
61 			)
62 		),
63 		$c->Tr(
64 			$c->td({-colspan=>2},
65 				$c->submit(-name=>'submit', -value=>'Submit the Form')
66 			)
67 		);
68 
69 	print $c->header(),
70 		$c->start_html(
71 			-title=>'Simple CGI Demo',
72 			-author=>'Brad Lhotsky <lhotskyb@mail.nih.gov>',
73 		),
74 		$c->h1(q|Welcome to the Simple CGI Demonstration!|),
75 		$c->start_form(
76 			-method=>'POST',
77 			-action=>$SCRIPT,
78 		),
79 		$c->hidden( -name=>'action', -value=>'display' ),
80 		$c->table(
81 			\@TableRows
82 		),
83 		$c->end_form,
84 		$c->end_html;
85 }
86 
87 
88 #------------------------------------------------------------------------#
89 # Function to Display CGI Stuff
90 sub display {
91 	croak "Function Not Yet Defined!";
92 }


syntax highlighted by Code2HTML, v. 0.9.1