Apache::Directive - Perl API for manipulating Apache configuration tree |
Apache::Directive - Perl API for manipulating Apache configuration tree
use Apache::Directive ();
my $tree = Apache::Directive->conftree;
my $documentroot = $tree->lookup('DocumentRoot');
my $vhost = $tree->lookup('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
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; } } }
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.
All these methods are read-only
Apache::Directive
provides the following functions and/or methods:
args
The arguments for the current directive, stored as a space separated list
$args = $node->args();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$args
( string )
as_hash
Returns a hash representation of the configuration tree, in a format suitable for inclusion in <Perl> sections.
$config_hash = $conftree->as_hash();
$conftree
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$config_hash
(HASH)
as_string
Returns a string representation of the configuration node, in httpd.conf format. This does not traverse down to sub-trees.
$string = $node->as_string();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$string
( string )
conftree
Returns the root of the configuration tree.
$tree = Apache::Directive->conftree();
Apache::Directive
(class name)$tree
( Apache::Directive object|docs::2.0::api::Apache::Directive
)
directive
Returns the name of the directive in $node
.
$name = $node->directive();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$directive
( string )
filename
Returns the filename the configuration node was created from
$filename = $node->filename();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$filename
( string )
first_child
The first child node of this directive
$subtree = $node->first_child;
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$child_node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$node
, undef
if there is none
line_num
Returns the line number in filename
this node was created from
$lineno = $node->line_num();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$lineno
(integer)
lookup
Returns node(s)
matching a certain value.
$node = $conftree->lookup($directive, $args); @nodes = $conftree->lookup($directive, $args);
$conftree
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$directive
( string )args
( string )$string
( string / ARRAY of HASHES )In scalar context, it will return only the first matching node.
If called with only $directive
value, this will return all nodes
from that directive. For example:
@Alias = $conftree->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. For example:
$VHost = $tree->lookup('VirtualHost', '_default_:8000');
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');
next
The next directive node in the tree
$next_node = $node->next();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$next_node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$node
, undef
if there is none
parent
The parent node of this directive
$parent_node = $node->parent();
$node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)parent_node
( Apache::Directive object|docs::2.0::api::Apache::Directive
)$node
, undef
if this node is the root node
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
The mod_perl development team and numerous contributors.
Apache::Directive - Perl API for manipulating Apache configuration tree |