I think we've all been down this path before and found our code wanting for a cleaner framework than nested if-elseif blocks. For this type of scenario, I would strongly recommend looking at CGI::Application (which I have reviewed previously here) - This module offers a very simple, but expansive object-orientated framework that provides some structured order to CGI scripts written in this manner.

The advantage which the CGI::Application interface offers is that individual "run-modes" and execution blocks can be defined, each correlating to a particular stage of your CGI interface. Using the CGI::Application "run-mode" interface, the code above could be re-written as follows - Note that some liberty has been taken with the subroutine names and the example code shortened to reflect only that snippet of code shown above:

sub setup { my $self = shift; $self->mode_param('action'); $self->run_modes({ 'AUTOLOAD' => 'action_dialog', 'add' => 'add_dialog', 'add_commit' => 'add_commit_dialog', 'modify' => 'modify_dialog', 'modify_commit' => 'modify_commit_dialog', 'remove' => 'remove_dialog', 'remove_commit' => 'remove_commit_dialog' }); }

Furthermore, the CGI::Application module implements methods to address the CGI and HTML::Template modules, facilitating powerfule methods for the construction of extensible web applications.

In short, I would strongly look into CGI::Application for this type of application or alternatively, some of the different web application frameworks reviewed by princepawn at Web Application Frameworks and their Templating Engines with a Comparative Study of Template and HTML::Template.

Good luck.

 


In reply to Re: CGI Design by rob_au
in thread CGI Design by Dogma

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.