Perrin Harkins wrote:
> valerian wrote:
> 
>> So the weird thing is that it runs fine the first time, but when I
>> reload the page, it doesn't show the variable I imported from
>> My::Config
> 
> 
> Try changing this:
> 
> use My::Config;
> 
> to this:
> 
> require My::Config;
> import  My::Config;
> 
> BEGIN blocks are only run once in PerlRun/Registry, and PerlRun clears 
> the current namespace after each request, erasing the aliases created by 
> import.  
> Of course I can't explain why this worked for Stas.  Maybe there is 
> something about the specific versions of Perl/mod_perl that affects this.

I think I've had enough coffee. PerlRun recompiles the code on each 
request, meaning that it re-runs any BEGIN blocks on each request. 
Meaning that My::Config will re-import %CF afresh.

It's simply to check, add to your script:

BEGIN { warn "BEGIN was called\n"; }

you will see the message on every reload.

Since use is almost the same as: require+import. require won't be called 
because the module will be already in %INC, but import will be always 
called. Again it's simply to check. Add to My::Config:

sub import { warn "import was called" }

and don't inherit from Exporter. Again you will see import() called on 
each request.

 > In general, you'd be better off just avoiding aliases and
 > Exporter altogether, since they waste memory and can cause confusion.

Seconded. See 
http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Using_Global_Variables_and_Sharing_Them_Between_Modules_Packages
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Reply via email to