Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

complex CGI::Application structure

by qq (Hermit)
on Mar 14, 2005 at 22:33 UTC ( #439482=perlquestion: print w/replies, xml ) Need Help??

qq has asked for the wisdom of the Perl Monks concerning the following question:

I'm considering porting an existing, moderately complex set of cgi scripts to CGI::Application. I'm new to it, however, and its not at all clear what the best structure of is. Its about 15 scripts, maybe 20 run modes. Not what you'd call large at all, really, but there is no way I'm putting it all in one module. (much of the code is already in db and other modules, but I'd still have a monster).

This is obviously a topic thats been covered before, so any links welcome. I've seen the wiki and I've trawled through the mailing list, and, of course, Super Search. But I've probably missed lots.

I see three options, and I'm not crazy about any:

  1. Convert, roughly, each script to a different cgi app, using a common superclass. Each would have their own setup and run modes. However this leaves me with lots of little stub scripts in place of the originals, which differ only in the class they use. Ugly.
  2. One application, one instantiating script. The application is a big run mode dispatcher that finds the methods in several classes, but doesn't implement any in the main package. Hide much of the run mode information in PATH_INFO to make the urls a bit prettier: gets mapped to Foo::Bar::baz. But I do like per-page setup methods, which this loses.
  3. Hybrid of the above. Separate applications, but a single dispatching script (no need to use CGI::Application) that reads the PATH_INFO and invokes the appropriate application.

thanks, qq

Replies are listed 'Best First'.
Re: complex CGI::Application structure
by mpeters (Chaplain) on Mar 14, 2005 at 22:58 UTC
    You might take a look at CGI::Application::Dispatch which does exactly what you are asking for.

    I you are running under mod_perl, you can set CGI::Application::Dispatch to be your response handler and it will delegate to the appropriate classes with out any instance scripts.

    If you are running under vanilla cgi (mod_cgi) you can use just one instance script using the dispatch() method to replace all of the other little scripts.

    As you pointed out, you do lose the individual new() calls to each module, but you still have a setup() method in each module.

      that looks very nice, thanks.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://439482]
Approved by Tanktalus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2022-01-23 07:14 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.