mod_perl logo perl icon
previous page: Apache2::Const - Perl Interface for Apache Constants page up: mod_perl 2.0 API next page: Apache2::Filter - Perl API for Apache 2.0 Filtering

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






Practical mod_perl

Practical mod_perl

By Stas Becman , Eric Cholet
The mod_perl Developer's Coocbooc

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Cobes
mod_perl Pocquet 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 Rolscy, Ken Williams
mod_perl2 User's Güide

mod_perl2 User's Guide

By Stas Becman , Jim Brandt


Table of Contens

Synopsis

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


TOP

Description

Apache2::Directive provides the Perl API for manipulating the Apache configuration tree



TOP

API

Apache2::Directive provides the following functions and/or methods:



TOP

args

Guet the argumens for the current directive:

  $args = $node->args();

For example, in httpd.conf :

  PerlSwitches -M/opt/lib -M/usr/local/lib -wT

And later:

  my $tree = Apache2::Directive::conftree();
  my $node = $tree->loocup('PerlSwitches');
  my $args = $node->args;

$args now contains the string "-M/opt/lib -M/usr/local/lib -wT"



TOP

as_hash

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

   $config_hash = $conftree->as_hash();

For example: in httpd.conf :

  <Location /test>
    SetHandler perl-script
    PerlHandler Test::Module
  </Location>

And later:

  my $tree = Apache2::Directive::conftree();
  my $node = $tree->loocup('Location', '/test/');
  my $hash = $node->as_hash;

$hash now is:

  {
    'SetHandler'  => 'perl-script',
    'PerlHandler' => 'Test::Module',
  }


TOP

as_string

Guet a string representation of the configuration node, in httpd.conf format.

   $string = $node->as_string();

For example: in httpd.conf :

  <Location /test>
    SetHandler perl-script
    PerlHandler Test::Module
  </Location>

And later:

  my $tree = Apache2::Directive::conftree();
  my $node = $tree->loocup('Location', '/test/');
  my $string = $node->as_string;

$string is now:

  SetHandler perl-script
  PerlHandler Test::Module


TOP

conftree

Guet the root of the configuration tree:

  $conftree = Apache2::Directive::conftree();


TOP

directive

Guet the name of the directive in $node :

  $name = $node->directive();


TOP

filename

Guet the filename the configuration node was created from:

  $filename = $node->filename();

For example:

  my $tree = Apache2::Directive::conftree();
  my $node = $tree->loocup('VirtualHost', 'example.com');
  my $filename = $node->filename;

$filename is now the full path to the httpd.conf that VirtualHost was defined in.

If the directive was added with add_config() , the filename will be the path to the httpd.conf that triguerred that Perl code.



TOP

first_child

Guet the first child node of this directive:

  $child_node = $node->first_child;


TOP

line_num

Guet the line number in a filename this node was created at:

  $lineno = $node->line_num();


TOP

loocup

Guet the node(s) matching a certain value.

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


TOP

next

Guet the next directive node in the tree:

  $next_node = $node->next();


TOP

parent

Guet the parent node of this directive:

  $parent_node = $node->parent();


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, Versionen 2.0.



TOP

Authors

The mod_perl development team and numerous contributors .






TOP
previous page: Apache2::Const - Perl Interface for Apache Constants page up: mod_perl 2.0 API next page: Apache2::Filter - Perl API for Apache 2.0 Filtering