Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've dabbled with a few ways of doing web applications now. From the cookbook methods, to CGI::Application, each one has certain limitations and problems.

In an idle moment, the following list was developed :
A good CGI framework should provide

  1. Template handling -- go TT2! Keeping templates divorced from code allows me to to farm out HTML and probably SQL, not to mention benefits of maintenance, etc.
  2. Data Validation/ Business Rules Validation -- Submitting a form should optionally invoke any validation I see fit.
  3. Pre/Post handling -- Allow things to occur before an HTML page is displayed, and allow them to happen after an HTML form is submitted. This step (i.e. post handling) should be separate from data validation to allow for database transactions, session management, etc.
  4. Parameter Management -- Each page reserves which parameters should be stateful. Parameters not on the list will not be preserved between invocations.
  5. Error-handling -- If validation fails, or if pre/post fails, do something specific to the page.
  6. Flow control -- once I've gotten a whiteboard sketch of how a site should run, it shouldn't take much to implement the same flow programmatically.
OK, that's a tall order. So what's the answer? I think it looks something like this

my %pages = ( page_one => {description =>"Sign on", nextpage =>"greeting", prevpage => undef, validator =>\&signon_validate, errorhandler =>\&signon_err, template =>'path\template.html', postsubmit =>\&signon_psub, params =>["username","password]}, );
Now, the only thing that I'm not happy with are the prevpage and nextpage. I think this method of flow control is pretty limiting -- I have some ideas for improvements; removing those keys, and adding something like traverse_list which would be an array of other pages, and traverse_sub which would determine which one you'd hit.

Right now, I've got a basic engine (which is ugly, and unrefined) that does what I want with the existing structure. I can take user input, query databases, write out, update databases and so on.
BUT. Before I continue, I want to sanity check things. Is this duplication of effort? I know there's at least 3 other CGI website management modules out there, but I don't think they do the same thing (maybe CGI::Application, since it's meant to be subclassed into oblivion). Secondly, does this approach make sense? I'd really appreciate any input before I begin the arduous quest of modularizing all of this only to be told "this does exactly what foo::bar does, only ugly."


In reply to Refining the CGI process through structure and templates by boo_radley

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (4)
    As of 2014-09-17 23:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (101 votes), past polls