[cgiapp] need a fresh WebApp instance with every request ?

Matthias Ferdinand mf+cgiapp at mfedv.net
Tue Nov 29 20:43:29 EST 2011


On Wed, Nov 30, 2011 at 11:01:04AM +1100, Ron Savage wrote:
> Hi Matthias
> 
> On Sun, 2011-11-27 at 17:24 +0100, Matthias Ferdinand wrote:
> 
> > I could not find in CGI::Application's docs if a single instance object
> > is capable of handling multiple requests (i.e. has run() invoked several
> > times) or not.
[...]

> So, don't do it that way. Just accept that you need a new instance obj
> each time.

Hi Ron, thanks for answering.

I can modify my server script accordingly, and if my app at some point
needs more caching urgently, I could create a different per-process
object that persists over multiple requests and hand its ref to the
single-request WebApp instances.

It is just that it is not mentioned in the docs, and I think it should
be. Could have saved me a day or two of debugging.

And definitely the pod of CGI::Application::Server should be fixed. It
uses the WebApp object in this multi-request way, and I copied my server
script from there.

OTOH, finding all the per-request variables should not be too hard.  As
for the plugins, that would indeed amount to a new design constraint.
CGI::Application could e.g. offer a new anon hash where plugins can move
their per-request variables to, like $self->{__CAP_PER_REQUEST}, and set
it to {} in run(). Instant cleanup with every new request :-)


> And for a persistent environment, I'd strongly suggest you switch to
> Plack.
Will sure look into this, thanks.


Regards
Matthias


More information about the cgiapp mailing list