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:
- 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.
- 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: admin.pl/foo/bar/baz gets mapped to Foo::Bar::baz. But I do like per-page setup methods, which this loses.
- 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.