mod_perl logo
perl icon







previous page: Apache::Const - Perl Interface for Apache Constantspage up: mod_perl APIsnext page: Apache::Filter -- A Perl API for Apache 2.0 Filtering


Apache::Directive -- A Perl API for manipulating Apache configuration tree











The mod_perl Developer's Cookbook

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Kobes
mod_perl Pocket Reference

mod_perl Pocket Reference

By Andrew Ford
Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

By Lincoln Stein, Doug MacEachern


Table of Contents

Synopsis

  use Apache::Directive;
  
  my $tree = Apache::Directive->conftree;
  
  my $documentroot = $tree->lookup('DocumentRoot');
  
  my $vhost = $tree->lookup('VirtualHost', 'localhost:8000');
  my $servername = $vhost->{'ServerName'};
  
  print $tree->as_string;
  
  use Data::Dumper;
  print Dumper($tree->as_hash);
  
  my $node = $tree;
  while ($node) {
  
      #do something with $node
  
      if (my $kid = $node->first_child) {
          $node = $kid;
      } 
      elsif (my $next = $node->next) {
          $node = $next;
      }
      else {
          if (my $parent = $node->parent) {
              $node = $parent->next;
          }
          else {
              $node = undef;
          }
      }  
  }


TOP

Description

Apache::Directive allows its users to search and navigate the internal Apache configuration.

Internally, this information is stored in a tree structure. Each node in the tree has a reference to its parent (if it's not the root), its first child (if any), and to its next sibling.



TOP

Class Methods

Function arguments (if any) and return values are shown in the function's synopsis.



TOP

conftree()

  $tree = Apache::Directive->conftree();

Returns the root of the configuration tree.



TOP

Object Methods

Function arguments (if any) and return values are shown in the function's synopsis.



TOP

next()

  $node = $node->next;

Returns the next sibling of $node, undef otherwise



TOP

first_child()

  $subtree = $node->first_child;

Returns the first child node of $node, undef otherwise



TOP

parent()

  $parent = $node->parent;

Returns the parent of $node, undef if this node is the root node



TOP

directive()

  $name = $node->directive;

Returns the name of the directive in $node.



TOP

args()

  $args = $node->args;

Returns the arguments to this $node



TOP

filename()

  $fname = $node->filename;

Returns the filename this $node was created from



TOP

line_number()

  $lineno = $node->line_number;

Returns the line number in filename this $node was created from



TOP

as_string()

   print $tree->as_string();

Returns a string representation of the configuration tree, in httpd.conf format.



TOP

as_hash()

   $config = $tree->as_hash();

Returns a hash representation of the configuration tree, in a format suitable for inclusion in the <Perl> sections.



TOP

lookup()

  lookup($directive, [$args])

Returns node(s) matching a certain value. In list context, it will return all matching nodes. In scalar context, it will return only the first matching node.

If called with only one $directive value, this will return all nodes from that directive:

  @Alias = $tree->lookup('Alias');

Would return all nodes for Alias directives.

If called with an extra $args argument, this will return only nodes where both the directive and the args matched:

  $VHost = $tree->lookup('VirtualHosts', '_default_:8000');


TOP

Authors



TOP

Copyright







TOP
previous page: Apache::Const - Perl Interface for Apache Constantspage up: mod_perl APIsnext page: Apache::Filter -- A Perl API for Apache 2.0 Filtering