mod_perl logo
perl icon







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


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











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
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

By Dave Rolsky, Ken Williams


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



TOP

conftree()

Returns the root of the configuration tree.

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


TOP

Object Methods



TOP

as_hash()

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

   $config_hash = $conftree->as_hash();


TOP

as_string()

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

   $string = $conftree->as_string();


TOP

lookup()

Returns node(s) matching a certain value.

  $node  = $conftree->lookup($directive, $args);
  @nodes = $conftree->lookup($directive, $args);

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

walk_config

META: Autogenerated - needs to be reviewed/completed

Walk a config tree and setup the server's internal structures

  $ret = $conftree->walk_config($cmdparms, $section_vector);


TOP

directive

Returns the name of the directive in $node.

  $name = $node->directive();


TOP

args

The arguments for the current directive, stored as a space separated list

  $args = $node->args();


TOP

next

The next directive node in the tree

  $next_node = $node->next();


TOP

first_child

The first child node of this directive

  $subtree = $node->first_child;


TOP

parent

META: Autogenerated - needs to be reviewed/completed

The parent node of this directive

  $parent_node = $node->parent();


TOP

data

META: Autogenerated - needs to be reviewed/completed

directive's module can store add'l data here

  $ret = $conftree->data($newval);


TOP

filename

Returns the filename the configuration node was created from

  $filename = $node->filename();


TOP

line_num

Returns the line number in filename this node was created from

  $lineno = $node->line_num();


TOP

See Also

mod_perl 2.0 documentation.



TOP

Copyright

mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 1.1.



TOP

Authors

The mod_perl development team and numerous contributors.







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