The Basic of mod_perl Support

Dave Williss dwilliss at microimages.com
Mon Jun 19 14:37:50 UTC 2006


Another thing to keep in mind with mod_perl, is that the .cgi is also
only compiled once.  

Also, as Max said, things defined at a global scope with "my" are evil.
Things defined at a global scope without "my" end up having a global
scope across all instances.  This is also evil.  I have a tendency in my
perl and cgi scripts to assume that any variable I declare gets initialized
to an undefined state.  With mod_perl, this only happens on the first
instance.  So if you use an array or hash and assume it will start out 
empty and just keep adding things to it, you'll be surprised to find that
it keeps growing each time the cgi is called.

This can also be used in a good way though...

There are tables which could be read once and kept in memory rather
than having to do a query every time the cgi is run.  Of course, since
you've just spent a lot of effort go get rid of globals.pl, that may be
a step backwards :-)

----- Original Message ----- 
From: "Max Kanat-Alexander" <mkanat at bugzilla.org>
To: <developers at bugzilla.org>
Sent: Monday, June 19, 2006 8:26 AM
Subject: Re: The Basic of mod_perl Support


> On Mon, 2006-06-19 at 15:44 +0300, Dennis Melentyev wrote:
>> Could you please also tell us, what other things we should know to make
>> code compatible with mod_perl? I mostly mean common mistakes and good
>> code patterns/practices.
> 
> The rule I said below pretty much covers it. You just have to imagine
> that you're re-using the same compiled module over and over.
> 
> For example, let's pretend that your module looks like this:
> 
> package Foo;
> 
> my $user = Bugzilla->user;
> 
> First time you load the page, $user will be correct. Second time,
> somebody else loads the page, the $user variable won't even exist. Why?
> Because "my" puts something in the scope of the currently-running
> script.
> 
> In general, it's just not a good idea to ever have code execute outside
> of a subroutine, in a .pm file. If you follow that rule, you'll be safe.
> There are some exceptions, but don't worry about it unless you *reall*
> have to. Just put everything in a subroutine.
> 
>> Or, just point me to some good docs on mod_perl.
> 
> This is for mod_perl 1.x, and we're going to be using 2.x, but the
> ideas are basically the same:
> 
> http://perl.apache.org/docs/1.0/guide/porting.html
> 
> -Max
> -- 
> http://www.everythingsolved.com/
> Everything Solved: Competent, Friendly Bugzilla and Linux Services
> 
> -
> To view or change your list settings, click here:
> <http://bugzilla.org/cgi-bin/mj_wwwusr?user=dwilliss@microimages.com>



More information about the developers mailing list