9.3. Configuration Classes

Two classes, Apache::ModuleConfig and Apache::CmdParms, provide access to the custom configuration directive API.

9.3.1. The Apache::ModuleConfig Class

Most Apache Perl API modules use the simple PerlSetVar directive to declare per-directory configuration variables. However, with a little more effort, you can create entirely new configuration directives. This process is discussed in detail in Chapter 8.

Once the configuration directives have been created, they can be retrieved from within handlers using the Apache::ModuleConfig->get( ) class method. get( ) returns the current command configuration table as an Apache table blessed into the Apache::Table class. get( ) takes one or two arguments. The first argument can be the current request object to retrieve per-directory data or an Apache::Server object to retrieve per-server data. The second, optional, argument is the name of the module whose configuration table you are interested in. If not specified, this argument defaults to the current package, which is usually what you want.

Here's an example:

use Apache::ModuleConfig ();
sub handler {
  my $r = shift;
  my $cfg = Apache::ModuleConfig->get($r);
  my $printer = $cfg->{'printer-address'};

9.3.2. The Apache::CmdParms Class

The Apache::CmdParms class provides a Perl interface to the Apache cmd_parms data structure. When Apache encounters a directive, it invokes a command handler that is responsible for processing the directive's arguments. ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.