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
Node Status?
node history
Node Type: perlquestion [id://439482]
Approved by Tanktalus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-02-27 23:58 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (393 votes). Check out past polls.