julie wang wrote:

> I'm new to Modperl.  I been programming as a perl programmer (not the best,
> but I'm trying to improve) and been told to try and code using mod_perl.  I
> got ORA's book on Apache Modules and was reading about how to code using
> mod_perl.  Am I right to assume mod_perl is more Apache conf. than anything
> else?  (if using Apache::Registry) I been coding perl using the -w flag as
> well as "use strict".  I shouldn't need to alter how I code Perl, right?

Well, yes, you at least have to take care of some additionnal things.

The most important thing to know is that your code could be called a
number of time before being "reset", where a regular CGI script is
called only once and dies right after, which let you have some
sloppiness that you can no longer afford with mod_perl.

Imagine that this code:

my($var) = 0;

sub handler {
  my($r) = @_;

  $r->content_type('text/plain');
  $r->send_http_header;

  $var = $var + 1;
  print "\$var is $var\n";

  return OK;
}

What you'll have with this is that you'll basically get a random number
for every requests. If you want to start this script assuming that $var
is 0, then set $var to 0 at the beginning.

> Is there anyway to test if the server is running in mod_perl or not?  I know
> this is one of the FAQ questions, but I didn't really understand.  I am
> using exit(0); and exit; to terminate my perl scripts.  What should I
> replace that with if it is advise not to do so when using mod_perl??  The
> FAQ suggests using "goto" kind of statement.  I rather not use that.  What
> other alternatives do I have?  Thanks!

In Apache::Registry scripts, the environment variable GATEWAY_INTERFACE
is set to 'CGI-Perl/1.1'.

In recent enough mod_perl, 'exit' (with or without parameter) is
overridden and will not hurt the server, but the cleaner way to exit an
Apache::Registry handler is with 'return'. I *think* you can return
something like "return REDIRECT" or "return SERVER_ERROR" if you want,
but I'm not sure (I only use PerlHandler scripts, not Apache::Registry).

-- 
Pierre Phaneuf
http://www3.sympatico.ca/pphaneuf/

Reply via email to