I think you have too many rules. And I think you are being too specific. Rules should generalise.

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)

#!/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) = @_; }
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.

Rules about style (e.g. FILEHANDLES uppercase) or object orientation or what have you can just be examples in the template.

Dingus


Enter any 47-digit prime number to continue.

In reply to Re: Perl Programming guidlines/rules by dingus
in thread Perl Programming guidelines/rules by hakkr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.