FAQ
The "Apache Server Configuration Customization in Perl" page claims
that the following code can be used in the request handler to retrieve
configuration values:

my $dir_cfg = $self->get_config($s, $r->per_dir_config);

however, it isn't quite clear what $self refers to in the request
handler. AFAICT, the correct sample code should be

Apache2::Module::get_config('MyApache2::MyParameters', $s, $r->per_dir_config());

as is shown further down.

DES
--
Dag-Erling Smørgrav - des@des.no

Search Discussions

  • Frank Wiles at Feb 20, 2006 at 8:20 pm

    On Mon, 20 Feb 2006 21:09:44 +0100 des@des.no (Dag-Erling Smørgrav) wrote:

    The "Apache Server Configuration Customization in Perl" page claims
    that the following code can be used in the request handler to retrieve
    configuration values:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);

    however, it isn't quite clear what $self refers to in the request
    handler. AFAICT, the correct sample code should be

    Apache2::Module::get_config('MyApache2::MyParameters', $s,
    $r->per_dir_config());

    as is shown further down.
    The part of the docs with my $dir_config = $self->get_..... is
    for writing a callback to process the configuration information,
    not retrieve it in the handler.

    And yes, you're right. The proper way to retrieve it in your handler
    is what you found further down in the file.

    If you're only doing simple parameters you might want to look into
    using ModPerl::ParamBuilder as it makes the whole process very very
    easy.

    ---------------------------------
    Frank Wiles <frank@wiles.org>
    http://www.wiles.org
    ---------------------------------
  • Dag-Erling Smørgrav at Feb 20, 2006 at 8:32 pm

    Frank Wiles writes:
    des@des.no (Dag-Erling Smørgrav) wrote:
    The "Apache Server Configuration Customization in Perl" page claims
    that the following code can be used in the request handler to retrieve
    configuration values:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);

    however, it isn't quite clear what $self refers to in the request
    handler. AFAICT, the correct sample code should be [...]
    The part of the docs with my $dir_config = $self->get_..... is for
    writing a callback to process the configuration information, not
    retrieve it in the handler.
    To quote a slightly longer excerpt:
    This object can be later retrieved at request time via:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);
    which is clearly incorrect, unless "at request time" means something
    different to you than it does to me.

    This is in the "Directive Callback Subroutine" section, see
    http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine

    DES
    --
    Dag-Erling Smørgrav - des@des.no
  • Frank Wiles at Feb 20, 2006 at 8:49 pm

    On Mon, 20 Feb 2006 21:32:02 +0100 des@des.no (Dag-Erling Smørgrav) wrote:

    To quote a slightly longer excerpt:
    This object can be later retrieved at request time via:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);
    which is clearly incorrect, unless "at request time" means something
    different to you than it does to me.

    This is in the "Directive Callback Subroutine" section, see
    http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine
    Yes, that's exactly what I'm talking about. :) You are referencing
    the wrong section for how to use these configs in your sub handler().

    When using custom configuration directives there are essentially
    three steps involved:

    1) Define the directives via @directives and load it in.

    2) Write the callbacks that are used by Apache when reading in those
    config options. This is what you are reading about in "Directive
    Callback Subroutine". These callbacks are used to put the data
    into whatever data structure you want to save it under and/or
    validate the data when the config file is parsed.

    3) You use Apache2::Module::get_config() to actually retrieve the
    configuration *data* in your sub handler().

    Hopefully that is more clear.

    ---------------------------------
    Frank Wiles <frank@wiles.org>
    http://www.wiles.org
    ---------------------------------
  • Dag-Erling Smørgrav at Feb 21, 2006 at 8:09 am

    Frank Wiles writes:
    des@des.no (Dag-Erling Smørgrav) wrote:
    To quote a slightly longer excerpt:
    This object can be later retrieved at request time via:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);
    which is clearly incorrect, unless "at request time" means something
    different to you than it does to me.
    Yes, that's exactly what I'm talking about. :) You are referencing
    the wrong section for how to use these configs in your sub handler().
    [...]
    Hopefully that is more clear.
    No, it isn't. You didn't address my key point: what does "at request
    time" mean in the sentence I quoted?

    DES
    --
    Dag-Erling Smørgrav - des@des.no
  • Geoffrey Young at Feb 21, 2006 at 1:35 pm

    Dag-Erling Smørgrav wrote:
    Frank Wiles <frank@wiles.org> writes:
    des@des.no (Dag-Erling Smørgrav) wrote:
    To quote a slightly longer excerpt:
    This object can be later retrieved at request time via:

    my $dir_cfg = $self->get_config($s, $r->per_dir_config);
    which is clearly incorrect, unless "at request time" means something
    different to you than it does to me.
    Yes, that's exactly what I'm talking about. :) You are referencing
    the wrong section for how to use these configs in your sub handler().
    [...]
    Hopefully that is more clear.

    No, it isn't. You didn't address my key point: what does "at request
    time" mean in the sentence I quoted?
    "request time" means the time from the PerlPostReadRequestHandler through
    the PerlCleanupHandler. in essence, the time under which httpd is serving a
    request (as opposed to the time httpd spends configuring itself, for example).

    nevertheless, the syntax given above is wrong without additional perl foo
    (like adding Apache::Module to your @INC). I suspect that the example was
    lifted from the tests where that syntax is indeed used but get_config() is a
    wrapper function and not the official API. I'd suggest changing that example to

    Apache::Module::get_config(__PACKAGE__, $s, $r->per_dir_config);

    instead of $self.

    HTH

    --Geoff

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmodperl @
categoriesmodperl, perl
postedFeb 20, '06 at 8:10p
activeFeb 21, '06 at 1:35p
posts6
users3
websiteperl.apache.org

People

Translate

site design / logo © 2021 Grokbase