Randy J. Ray ([EMAIL PROTECTED]) said something to this effect on 04/18/2001:
> I would like to have a PerlHandler that may be assigned to several
> different locations to initialize slightly differently based on the
> location. In my case, this is an XML-RPC server, and I want the location to
> be the means of controlling what procedures are published to clients. Thus,
> when I have something like:

<snip>

Please forgive the gratuitous quoting, but see
<URL:http://www.modperl.com/book/chapters/ch8.html#Configuration_Creation_and_Mergi>
(chapter 8 of the Eagle book):

#-------- BEGIN ------------

DIR_CREATE() 

    If the directive handler's class defines or inherits a
    DIR_CREATE() method, it will be invoked to create per-directory
    configuration structures. This object is the second argument
    passed to all directive handlers, which is normally used to store
    the configuration arguments. When no DIR_CREATE() method is
    found, mod_perl will construct the configuration object for you: 

       bless {}, $Class;

    You might use a DIR_CREATE() method to define various defaults or
    to use something other than a hash reference to store the
    configuration values. This example uses a blessed hash reference,
    and sets the value of TopLimit to a default value: package
    Apache::TrafficCop;

       sub new {
          return bless {}, shift;
       }

       sub DIR_CREATE {
           my $class = shift;
           my $self = $class->new;
           $self->{TopLimit} ||= 65;
           return $self;
       }

DIR_MERGE() 

    When the <Directory> or <Location> hierarchy contains
    configuration entries at multiple levels, the directory merger
    routine will be called on to merge all the directives into the
    current, bottom-most level. 

    When defining a DIR_MERGE() method, the parent configuration
    object is passed as the first argument, and the current object as
    the second. In the example DIR_MERGE() routine shown below, the
    keys of the current configuration will override any like-named
    keys in the parent. The return value should be a merged
    configuration object blessed into the module's class: 

       sub DIR_MERGE {
           my($parent, $current) = @_;
           my %new = (%$parent, %$current);
           return bless \%new, ref($parent);
       }

#-------- END ------------

So, DIR_CREATE and DIR_MERGE can be used to run code when a
specific Location or Directory directive is hit, and nothing
states that the code that runs has to only modify the data
structure that gets passed in (although that was the original
intent). You should be able to use this to perform
Location-specific customizations to your module.

Hope that's helpful. By the way, you'll probably need to read all
of chapter 8 pretty thoroughly, unless you've programmed Apache
in C before.

(darren)

-- 
To do nothing is to be nothing.

Reply via email to