in reply to Re: Model-View-Controller: Template Toolkit vs. XSLT
in thread Model-View-Controller: Template Toolkit vs. XSLT

I've never seen the point of CGI::Application. What, exactly, does it do that a giant if/elsif/else statement doesn't? Nothing, from what I can tell, aside from introducing another dependency, like what you criticise Maypole for.
  • Comment on Re^2: Model-View-Controller: Template Toolkit vs. XSLT

Replies are listed 'Best First'.
Re^3: Model-View-Controller: Template Toolkit vs. XSLT
by Joost (Canon) on Oct 15, 2004 at 10:59 UTC
Re^3: Model-View-Controller: Template Toolkit vs. XSLT
by weierophinney (Pilgrim) on Oct 15, 2004 at 18:33 UTC
    CGI::Application does many other things than "a giant if/elsif/else statement" -- and it doesn't even really do that. (It implements a hash-based dispatch table that maps a query string to a method; if no match is found, it uses a default as specified.)

    What does CGI::Application do?

    • It provides a framework for developing re-usable, customizable application classes. Simply use the class, pass some metadata (in the form of a hash) to the constructor, and run() it
    • It provides a sane framework for developing applications; each screen gets a run mode, and each run mode gets a method -- CGI::Application-based classes are incredibly consistent and easy to debug because it's easy to determine what piece of code is executed when (look at the dispatch table instead of trying to scan through "a giant if/elsif/else statement").
    • It provides a means for wrapping a number of applications under a site-umbrella, through it's various cgiapp_*() hook methods. Using these, you can create a superclass that does security checks, places final application content in a sitewide template, and creates customized navigation and sidebars -- but still retain the flexibility of developing only a single application suite at a time.
    If used correctly, CGI::Application can be used as a very good Controller for an MVC setup -- have it simply do the work of validating and sanitizing input, passing it to the Model, and piping the Model's return values to the View (a templating system).

    What I like most about it is that, at it's core, it's a very slim piece of code that simply stays the heck out of my way as I build my applications -- no extraneous doodads or geegaws are loaded unless I specifically do so myself.

    Yes, it's another dependency, but it has very little overhead and benefits that outweigh the dependency a thousandfold.