[cgiapp] Persistence

Cees Hek ceeshek at gmail.com
Tue Feb 5 08:18:39 EST 2008


On Feb 5, 2008 10:59 PM, Mark Knoop <mark at rawcane.net> wrote:
> > Hi
> >
> > I'm new to CGI::Application.

Welcome

> > I like the way it makes me organize the script but I guess I could do it
> > in this way without CGI:Application so I just want to be sure I fully
> > understand the benefits.
> >
> > Given that I am not running it under mod_perl at this stage is each
> > instance request a completely seperate event or does CGI::Application
> > somehow keep track of something between one user's calls to the same
> > instance?

No, CGI::Application by itself does not offer any persistance.  Each
request will create a new CGI::Application object.  You can use
mod_perl or FastCGI to make the code persistent, but it will still
create a new CGI::Application object on each request.

> > If not then does CGI::Application offer any other benefits than helping
> > one to organize ones code better?

If you look at the source code for CGI::Application you will see that
it is not very big and not very complex.  So yes you are correct in
thinking that you can probably structure your code that way without
using CGI::Application itself.

The benefit in using it is that you are using a module that has been
tried and tested over many years by thousands of people.  These people
all structure their apps in a very similar way (ie the
CGI::Application way), which means you can benefit from several thing:

Code re-use
- many people have spent time building lots of extensions to
CGI::Application that make life for a web developer much easier.  By
using CGI::Application as your base you can benefit from all this work
(search CPAN for CGI::Application::Plugin to see what is publicly
available).

Lower your Technical Debt
- Building your own application code structure and rebuilding your own
version of all the plugins that are available means you have to
maintain all that extra code.  And the person that takes over your
project in the future has to maintain and understand what you have
built.  Using well supported modules and best practices lowers your
technical debt for the future.  It also gives future maintainers a
starting place to look for help and documentation.

Help from your peers
- this mailing list has many people that may be able to help you if
you run into problems, but only if you use CGI::Application.  Building
it all yourself means you are less likely to find someone that can (or
is willing to) help you.


> Ok... have made some progress. It seems I can use the
> CGI::Application::Plugin::Session  for the persistence side of things. But
> still feel like I am missing a trick.... will persevere and see if things
> become clearer.

So it looks like you have already found some of the plugins :)  The
Session plugin will allow you to maintain state variables across
requests.  So if all you want to do is store some info for a user
between requests (like an authentication token, or maybe their
language preference, etc...) then the Session plugin will definately
do that for you.

If you still feel you are missing something, then explain to us what
you are trying to do, and what you are expecting an application
framework like CGI::Application to do for you.

Cheers,

Cees Hek


More information about the cgiapp mailing list