On Mon, 12 Mar 2001, Khachaturov, Vassilii wrote:
> Read it. It still doesn't address my questions
> - why this stopped working with
> the new mod_perl+apache. From the docs, rather, I'd expect a
> routine or a variable defined in one <Perl> section persist to the other.
> While I can't use global vars (they try to get tied to the non-existing
> config. params), and lexicals remain scoped within the same <Perl>
> section, I had to use a sub before, which I was able to access in
> the other Perl section. Now I am not. The docs say, however, I
> am eval-ed in Apache::ReadConfig - o.k., so the subs should get
> defined there and then remain there, as long as the same config
> file is read?
<Perl>
$Apache::Config::foo = "bar";
</Perl>
<Perl>
warn "\$foo = $Apache::Config::foo";
</Perl>
prints:
$foo = bar at /....
since there is no strict imposed, this does as well:
<Perl>
$foo = "bar";
</Perl>
<Perl>
warn "\$foo = $foo";
</Perl>
This works too:
<Perl>
use constant FOO => "bar";
</Perl>
<Perl>
warn "\$foo = ".FOO;
</Perl>
And indeed this doesn't work:
<Perl>
sub FOO {"bar"};
</Perl>
<Perl>
warn "\$foo = ".FOO();
</Perl>
We need to look at the code to see why subs get scoped like lexicals.
> I didn't want to use too heavy stuff (PerlSetVar or the module recently
> discussed here - was it Apache::Storage?)
> because I just wanted some shortcuts for the scope of the .conf file
> only. It was better to cut-n-paste them in the worst case than carve
> them in Apache brains, stealing the precious memory
> from mod_perl :-).
> -----Original Message-----
> From: Stas Bekman [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 12, 2001 8:39 PM
> To: Khachaturov, Vassilii
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: <Perl> incompat. with apache/mod_perl upgrade
>
> ...
> > <Perl>
> > sub WWW_DIR () { $ENV{'HOME'} . '/www' ; } # this sub will persist to next
> > <Perl>
> > ... more code, using WWW_DIR sometimes
> > </Perl>
> >
> > .. more plain apache conf stuff here
> >
> > <Perl>
> > $AxCacheDir = WWW_DIR . '/htdocs/x/cache';
> > </Perl>
> >
> > While this worked before, it now generates an undef sub called at the
> second
> ...
> > Was this change intentionally done (why?!), or is it a by-product of some
> > other code advances?
> > What is the correct way of passing Perl stuff from one <Perl> section to
> > another?
>
> Please read
> http://perl.apache.org/guide/config.html#Apache_Configuration_in_Perl
> and you will understand how C<Perl> sections work.
>
> I also don't understand why are you trying to use sub to define a
> variable, which is pretty useless, since you use it only during
> configuration. Also use the constant pragma.
>
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/