On Tuesday 09 October 2001 12:30, Stas Bekman wrote:
> Is Apache->server or its variation planned, because I cannot find it in
> todo/. I realize that now we can have more than one server, so it
> probably should be different but at least how do I get to the main
> server's object from modperl code when you don't have $r
> I know that I can $r->server, but I need to get $s->dir_config at
> compile time, when I don't have $r.
>
> I was grepping around, but couldn't find anything.
>
> Basically what I want to do is:
> use constant DEBUG => defined
> Apache->server->dir_config('ModPerl::RegistryCooker::DEBUG') ?
> Apache->server->dir_config('ModPerl::RegistryCooker::DEBUG') : D_NOISE;
>
> So 'foo() if DEBUG' will be optimized away at compile time, rather than
> having $Debug as we had before. (D_NOISE actually is very noisy, but
> this is only during the initial development).

What I'm about to say is wildly tampered by my ignorance of the way modperl 
and Apache 2.0 work, but I think that the results of the above will depend on 
a variety of things.

Currently in 1.26, Apache->server will return the current vhost server if 
called from a vhost, or the main server otherwise (many thanks to a recent 
patch by Doug, previously it only returned the main server).

The problem is that if your code is inside the vhost and called at 
config-read time, merging will not have occured. For instance if you have:

PerlSetVar  ModPerl::RegistryCooker::DEBUG
<VirtualHost ...>
   # load the module that calls Stas' code in its BEGIN
   PerlModule ModPerl::RegistryCooker
</VirtualHost>

Then ModPerl::RegistryCooker will not see the PerlSetVar, whether or not it 
has access to $s->dir_config. That said PerlSetVar will only become available 
to that server object when </VirtualHost> is encountered, and server merge 
happens.

So (if I'm right in the above, which I may not be. Just trying to help ;-) in 
order for that work you'd need to either:

 1) delay execution of any Perl code (whether pulled in or in <Perl>) until 
the entire config is read and merged. This might not even cover all cases.

or

 2) provide a way for code running in an Apache that's in the process of 
reading its configuration to also have access to the parent server. That way 
one could do something along the lines of:

use constant DEBUG => 
        ( defined(Apache->server->dir_config('ModPerl::RegistryCooker::DEBUG')) or
              (Apache->server->is_virtual and
               defined(
                
Apache->server->main_server->dir_config('ModPerl::RegistryCooker::DEBUG') 
                ))
        ) ?
        Apache->server->dir_config('ModPerl::RegistryCooker::DEBUG') : D_NOISE;

Yeah it's ugly and could use a cleanup :) But I think that's the way out here 
(provided of course you also have dir_config available).

I hope I'm not off by too much, and helpful to some degree :-)

-- 
_______________________________________________________________________
Robin Berjon <[EMAIL PROTECTED]> -- CTO
k n o w s c a p e : // venture knowledge agency www.knowscape.com
-----------------------------------------------------------------------
Does the name Pavlov ring a bell?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to