What I think you should specify is a CGI template with appropriate CGI::CARP etc. etc. and state that all CGIs should be based on template. You might want to have the template divided up in to phases (as I mentioned in Re: Checkbox Query Revisited) as this really helps debugging. here is a sample (you would need clearer breaks and more sample/template code for real)
Sticking to this kind of template makes it necessary to state what parameters you expect where and that you make it easy for others to follow the structure of the program and to get meaningful debug output at various points.#!/usr/bin/perl # use strict; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser set_message); use Data::Dumper; # other modules # error handler BEGIN { sub handle_errors { my $msg = shift; print "<h1>Script Error</h1> running".$ENV{'SCRIPT_NAME'}."<p><pre +>"; $msg =~ s/ (of )*\Q$0//g; print "$msg</pre><A HREF='/'>Email me this page</a>"; } set_message(\&handle_errors); } # main program starts here my $debug = 1; my $cgi = new CGI; #put authentication here if required my $phase = identify_phase() # $phase = 0 if just printing form otherwise 1 (for complex transactio +ns may return 2, 3 etc.) print_form() unless ($phase); # this routine probably does not return my $validref = validate_params() print $cgi->header, $cgi->pre(Dumper($validref)) if ($debug); # list example Dumper($validref) output to show what is OK unless ($validref{error}) { execute($phase, $validref ); } else { report_param_errors( $validref ); } exit; # subroutines # phase 0 if no posted paramters etc etc sub identify_phase() { } sub print_form() { } sub validate_params() { } sub report_param_errors( ) { my ($parmref) = @_; } sub execute() { my ($phase, $parmref) = @_; }
Rules about style (e.g. FILEHANDLES uppercase) or object orientation or what have you can just be examples in the template.
Dingus
In reply to Re: Perl Programming guidlines/rules
by dingus
in thread Perl Programming guidelines/rules
by hakkr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |