![]() |
Home / Documentation / 2.0 / API / | ![]() |
||
![]() ![]() ![]() |
||||
Apache::Directive -- A 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'}; 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; } } }
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.
line_number()
$lineno = $node->line_number;
Returns the line number in filename
this $node
was created from
as_string()
print $tree->as_string();
Returns a string representation of the configuration tree, in httpd.conf format.
as_hash()
$config = $tree->as_hash();
Returns a hash representation of the configuration tree, in a format suitable for inclusion in the <Perl> sections.
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');
|
![]() |
![]() ![]() ![]() |