Properly abstracting and separating the different layers should help make this a lot easier to do. I've had very good results using HTML::Template in conjunction with mod_perl. Here's how I'd suggest breaking things down.

Top Level Handler
This is specific to either mod_perl or the CGI environment. Have it do all the work of talking to Apache / the browser. Parameter parsing, session management, DBI connections, etc, etc. Basically all the things that could be different between mod_perl and CGI.
Page or function level objects
Takes a list of parameters, session info, DBI handle, etc. and returns a data structure of some sort based on the input. One of these handles a particular page or function in your app. These do not contain any mod_perl, CGI or (insert template mechanism here ) specific things.
HTML suitable for which ever template mechanism you use
The benefits to keeping your HTML out of your code are very, very numerous.

So the chain of events goes kinda like this. The CGI or mod_perl handler, gets called for every page in your app. It does all the 'common stuff' that every CGI or mod_perl handler does. It then calls the appropriate page handling module passing along all the parameters. The page handling module does whatever processing you need for that page (database calls, generation of error message), and passes back a data structure of the results. The top level handler takes that structure, feeds it through the appropriate template and send the output to the client.

Here's some of the benefits.

Good luck, and I hope this helps.

/\/\averick


In reply to Re: Web framework under both mod_perl and CGI by maverick
in thread Web framework under both mod_perl and CGI by marvi

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.