[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Teardown cleanup


something like this on top of teardown

local $| = 1;
print;

That seems to work! The "local $| = 1" causes the page to be displayed by the browser immediately while "sleep(5)" executes. (The print doesn't seem
to affect it either way.) The browser spins during that 5 seconds.

Using CGI, you cannot avoid that. The browser will spin until the server closes the connection,
which does not happen before your script exits.

Using mod_perl you could do it by putting the "teardown" code outside of the request handling phase of the server and into a cleanup phase. However, this is not where the CGI::Application "teardown" method is executed, if you use the usual CGI-emulating wrappers (like Apache::Registry). So, if you really want to do this, you have to write mod_perl specific handlers.
Unless your teardown really takes a lot of time, I would not bother.


If this process runs under mod_perl, will the "$|" value persist? Do I need
to change the value back? "Local" takes care of this for me, right?

mod_perl or not, local will restore the old value once you leave the current block
(in this case your "teardown" method).

A related question. In my packages (which are based on cgi::application), I
declare and initialize "our" variables at the top. They are visible to
everything in the file.

"my" variables are visible to the entire file (if they are declared on the top level).

"our" variables belong to the current package, are visible within that package without a prefix,
and also from other packages by prefixing the package name.
It does not matter what file you declare them in.


 (I pass them by reference to subroutines in the .pl
library.) That makes them class data (not accesible as object data)?

You can think of them as class data, yes.
They belong to the package ("class") not to individual objects.


If this is correct, won't mod_perl execute
cgiapp_init multiple times? My variables will be re-initialized when that
may not be what I want?

Yes, cgiapp_init is run for every request.
Using plain CGI that makes no difference, but using mod_perl you probably do not want to re-open DB connections, or read config files all the time.

So what I usually do here is make packages that handle stuff I want to set up once and then persist.
For example:

package MyDB;
use DBI;
our $_conn;
sub conn(){
	return $_conn if $_conn;
	return $_conn = DBI->connect ( ..... );
}

With this code, I can just call MyDB::conn() whenever I need a database connection. It will be established only once, and then reused. And this code runs unmodified (and does the right thing) under CGI, mod_perl or in command line tools.



Thilo



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.