Show Contents Previous Page Next Page Chapter 9 - Perl API Reference Guide In this section...
Two classes, Apache::ModuleConfig and Apache::CmdParms, provide access to the custom configuration directive API. The Apache::ModuleConfig Class Show Contents Go to Top Previous Page Next PageMost 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, Customizing the Apache Configuration Process. 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'}; ... }Show Contents Go to Top Previous Page Next Page 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. The Apache::CmdParms object is passed to the responsible handler and contains information that may be useful when processing these arguments. An example of writing a directive handler is given in Chapter 8. In this section, we just summarize the methods that Apache::CmdParms makes available.
path()
my $path = $parms->path;
server()
my $s = $parms->server;
cmd()
use Apache::Module (); ... my $name = $parms->cmd->name;
info()
my $info = $parms->info;
limited()
# httpd.conf <Limit GET POST> SomeDirective argument_1 argument_2 </Limit> # Perl module use Apache::Constants qw(:methods); sub SomeDirective ($$$$) { my($parms, $cfg, @args) = @_; my $method_mask = $parms->limited; if($method_mask & (1 << M_POST)) { ... } }
override()
use Apache::Constants qw(:override); my $override_mask = $parms->override; if($override_mask & OR_ALL) { #this directive is allowed anywhere in the configuration files }
getline()
<Container argument> .... </Container>
sub Container ($$$*) { my($parms, $cfg, $arg, $fh) = @_; $arg =~ s/>//; while($parms->getline($line)) { last if $line =~ m:</Container>:i; ... } }
sub Container ($$$*) { my($parms, $cfg, $arg, $fh) = @_; $arg =~ s/>//; while(defined(my $line = <$fh>)) { last if $line =~ m:</Container>:i; ... } }Show Contents Go to Top Previous Page Next Page Copyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |