Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: In CGI::Application cgiapp_prerun vs. cgiapp_init?

by Anonymous Monk
on Jul 18, 2012 at 01:21 UTC ( #982356=note: print w/replies, xml ) Need Help??

in reply to Re^2: In CGI::Application cgiapp_prerun vs. cgiapp_init?
in thread In CGI::Application cgiapp_prerun vs. cgiapp_init?

Summary: they're both called on every request. Not sure if it's a change since this thread was posted but the information here doesn't seem to be correct.

Its neither, its a matter scoping :)

If this is your mod_perl application

sub handler { my $app = MyCGIAppSubclass->new; $app->run; }

cgiapp_init is going to get called with every request, obviously, because you're creating a new object each time -- this is typical Apache::Registry/ModPerl::Registry, running unmodified .cgi's under mod_perl

But if your mod_perl application is

my $app = MyCGIAppSubclass->new; sub handler { $app->run; }

Then init/setup is only done once, and only run is done upon every request.

So nothing changed, this are working as designed, as they always have.

See Understanding the application flow of CGI::Application and CGI::Application::Loop

See also the source of CGI::Application::FastCGI

package CGI::Application::FastCGI; use strict; use base qw (CGI::Application); use FCGI; use CGI; our $VERSION = '0.02'; sub run { my $self = shift; my $request = FCGI::Request(); $self->fastcgi($request); while ($request->Accept >= 0) { $self->reset_query; $self->SUPER::run; } } sub reset_query { my $self = shift; CGI::_reset_globals(); $self->{__QUERY_OBJ} = $self->cgiapp_get_query; } sub fastcgi { my $self = shift; @_ ? $self->{__FASTCGI} = shift : $self->{__FASTCGI}; } 1;

If you want to run CGI::Application as mod_perl handlers as I've shown above with persistent object, you will have to reset query, just like CGI::Application::FastCGI

Replies are listed 'Best First'.
Re^4: In CGI::Application cgiapp_prerun vs. cgiapp_init?
by saberworks (Curate) on Aug 01, 2012 at 22:48 UTC
    Ah, it's so blindingly obvious when you point it out, thanks for this. Of course I'm doing exactly what your first example shows, but not for long.

      Well, apparently, (I guesstimate) since (some time around) CGI::Application 3.x it is no longer recommended to reuse CGI::Application objects, no longer recommended to call run repeatedly, as Bug #72909 for CGI-Application: persistence issues says CGI::Application is designed to have a new object created on each request. which is an assumption various ::Plugins and extensions make, so its best to play along and not reuse an object and not ->run ->run ->run

      You probably discovered this on your own :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://982356]
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2017-03-23 05:35 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (282 votes). Check out past polls.