Is there a Mod_Perl Script Tester?

M

Market Mutant

Is there a mod_perl script tester which will tells me that if my script will
work in mod_perl the same as in none mod perl mode?

I would say it is easy to program, just check if all the veribles are reset
after the script or before the script, or check if any varible is defined
both when an if condition is met or not met.

Does this test exit?
 
S

Sherm Pendley

Is there a mod_perl script tester which will tells me that if my script will
work in mod_perl the same as in none mod perl mode?

Yes. It's called a programmer.

Seriously - there's more to it than simply making sure the script runs
without error. You also need to tune it to take good advantage of the
mod_perl environment. That's a creative process that needs human input.

For example, does your CGI use templates to produce its output? If so, you
can check the scalar that holds the template text, and if it's already
been read, re-use it instead of opening the template file and reading it
in again.
Does this test exit?

No. Calling exit() from mod_perl does Bad Things.

sherm--
 
G

Gunnar Hjalmarsson

Sherm said:
No. Calling exit() from mod_perl does Bad Things.

Does it?

If I have understood it correctly, that was true with older mod_perl
versions, while the latest versions are able to handle an exit() call
properly. Therefore, in a couple of programs I wrote for CGI, but that
can also be run under mod_perl, I'm using this:

sub myexit {
if ($ENV{MOD_PERL}) {
eval "use Apache";
Apache::exit() unless $@;
}
exit 1;
}

I'd appreciate a correction if that is an inappropriate solution.
 
S

Sherm Pendley

If I have understood it correctly, that was true with older mod_perl
versions, while the latest versions are able to handle an exit() call
properly.

I stand (sit, really) corrected. I've been out of work and haven't done
any mod_perl for a while - apparently I'm in need of a refresher.

sherm--
 
S

Sam Holden

Please note that I have a limited experience with CGI, mod_perl et
similia, and in particular I know next to nothing 'bout mod_perl, but
apart that exit() is now handled properly, what can be the benefit of
using it anyway?

To exit the script, say if you are a few subroutine calls deep and want
to exit *now*. Not uncommon by any means. Most commonly in subroutines
with names like report_and_exit().
 
M

Michele Dondi

Does it?

If I have understood it correctly, that was true with older mod_perl
versions, while the latest versions are able to handle an exit() call
properly. Therefore, in a couple of programs I wrote for CGI, but that
can also be run under mod_perl, I'm using this:

sub myexit {
if ($ENV{MOD_PERL}) {
eval "use Apache";
Apache::exit() unless $@;
}
exit 1;
}

Please note that I have a limited experience with CGI, mod_perl et
similia, and in particular I know next to nothing 'bout mod_perl, but
apart that exit() is now handled properly, what can be the benefit of
using it anyway?


Michele
 
G

Gunnar Hjalmarsson

Michele said:
I had thought exit() in the code snippet shown as an example was at
the end of a script, where many people "incorrectly" (or rather,
"unnecessarily" - if you know what I mean) put it.

The snippet was copied from an exception handling routine:

sub CFdie($) {
print "Content-type: text/html\n\n<h1>Error</h1>\n<tt>",
shift;
if ($ENV{MOD_PERL}) {
eval "use Apache";
Apache::exit() unless $@;
}
exit 1;
}
 
M

Michele Dondi

To exit the script, say if you are a few subroutine calls deep and want
to exit *now*. Not uncommon by any means. Most commonly in subroutines
with names like report_and_exit().

Damn! I *do* know what exit() is for. For some reason (that I do *not*
know!) I asked that stupid question: maybe I was misleaded by that
little I know about mod_perl (and its "persistence")... but to be
honest, I must admit that I had thought exit() in the code snippet
shown as an example was at the end of a script, where many people
"incorrectly" (or rather, "unnecessarily" - if you know what I mean)
put it.

Never again post when so tired... (Nah! How many times did I say so?)


Thanks,
Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top