RE: Global Variables - What is in Memory?
[prev]
[thread]
[next]
[Date index for 2004/11/05]
This clears things up.
Thanks for your help.
Justin
-----Original Message-----
From: Malcolm J Harwood [mailto:mjhlist-modperl@xxxxxxxxxxx.xxx]
Sent: Friday, November 05, 2004 9:22 AM
To: modperl@xxxx.xxxxxx.xxx
Subject: Re: Global Variables - What is in Memory?
On Friday 5 November 2004 11:50 am, Justin Luster wrote:
> > Apache::Registry should mangle scripts to seperate names so that
they
> > don't conflict. However if you are using the same package name in
each
> > case, the last definition to be loaded will be used. Ie. if both
> > one/MyAdmin.pl and two/MyAdmin.pl define admin:main(), whichever
file
> > loaded last will have it's definition used. (Check your error logs
for
> > "redefinition" warnings).
> I'm still not totally clear on this.
> So if I have two scripts:
> http://www.mysite.com/one/MyAdmin.pl
> and
> http://www.mysite.com/two/MyAdmin.pl
> are you saying that the latest one loaded will be used? So if
> http://www.mysite.com/two/MyAdmin.pl was loaded last then
> http://www.mysite.com/one/MyAdmin.pl would actually use the script
> contained in two/MyAdmin.pl?
No.
> The package part though does make sense. So the
> last "package" loaded stays in memory?
If you load a file with a package definition in it, then load another
file
that defines a package with the same name (which is what it looks like
you
are doing) you get a conflict. If you define a function in both package
definitions with the same name, then whichever one happens to be loaded
last
will override the previous definition. Usually this results in a
"Redefinition of package::functioname " message in your error log.
Normally Apache::Registry only loads packages that are requested using
"use
package" once (there's a package that will check for changes to package
files
and reload them if they change, but you have to explicitly use it).
However, you have your package definition in your scripts, which is
where the
problem occurs. Apache::Registry will load each script when it is first
encountered or when it changes, and if you are running multiprocess
apache
then each child will load your scripts in an arbitary order. So some
processes will have the definition from one/MyAdmin.pl and some from
two/MyAdmin.pl with no way of predicting which, or which process will
answer
a given request.
With your scripts, you end up with the following packages being known to
mod_perl:
package Apache::ROOT::webdir::one::MyAdminpl
package Apache::ROOT::webdir::two::MyAdminpl
package mylib
...
one/MyAdmin.pl contains the following package definitions:
package Apache::ROOT::webdir::one::MyAdminpl
package mylib
two/MyAdmin.pl contains the following package definitions:
package Apache::ROOT::webdir::two::MyAdminpl
package mylib
However the two definitions of "mylib" are different. You see the
problem?
--
"You heard Mr. Garibaldi. You did the right thing."
"Darling, I did the necessary thing. That is not always the same as
the right thing."
- Janice and Laura Rosen in Babylon 5:"The Quality of Mercy"
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html