Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Why CGI::Application?

by weierophinney (Pilgrim)
on May 07, 2004 at 00:29 UTC ( #351337=note: print w/replies, xml ) Need Help??

in reply to Why CGI::Application?

Like perl, CGI::Application makes the impossible things possible. It also abstracts CGI applications in such a way that you can focus on the actual programming at hand rather than how you're going to display things.

Let's say I have a simple application that should do the following:

  • Display a paginated list of my data
  • Allow me to search my data, and return the results in a paginated list
  • All paginated lists of data, filtered by a search or not, should be sortable by column
  • Allow me to view a single record at a time
  • Allow me to edit any given record
  • Allow me to delete any given record
  • Allow me to add new records
How do I go about doing this? In a traditional if-then-else way, this gets pretty hairy very fast. Even with dispatch tables, keeping track of all the parameters can be a bear. Then, on top of it all, there's the display issues. And, if you think about it, you're going to need sessions to keep track of the sorting and filtering (particularly if you want to return to the previously viewed list after an edit or record view).

How do I tie it all together?

What CGI::Application does is allow me to focus on the issue at hand: how do I retrieve my content? how do I determine what content to retrieve? Now, I can focus on one aspect at a time - one method per action, and calling related methods when necessary. I leave my display issues to templates, and simply assign the data I pull to the templates. I have session handling kept in a single superclass, along with my database connections. All I have to do is get my content; the rest is taken care of.

The CGI::App framework is setup in such a way that code reuse becomes not only easy, but the only way to effectively program. It enforces consistency, because you could be inheriting from any given module in order to extend it for further applications; because they all share the same framework, you don't have to worry about collisions in terminology when you mix and match.

On top of that, it allows you to setup an easy inheritance framework such that you can have multiple application modules inheriting from the same parent so that the same look and feel are inherited; this means that all of your site's applications can easily share the same look and feel, as well as have a common underlying structure.

And, if you want to, you can port your entire application to another site simply by changing the parameters you pass to it through the instatiation script -- new data stores, different group of templates, etc. Your reusability now extends not just to the current site, but to many sites.

Sure, you can "adjust your coding style" so that code is more reusable; what CGI::Application does is give you a ready-made, rigorously tested, framework for reusable code. Personally, I've had enough of hand-made frameworks; I want something that not only I can understand, but many other people can understand and have used.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://351337]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2017-06-27 16:14 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (611 votes). Check out past polls.