=head1 NAME Apache2::Directive - Perl API for manipulating the Apache configuration tree =head1 Synopsis use Apache2::Directive (); my $tree = Apache2::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 my $directive = $node->directive; my $args = $node->args; my $filename = $node->filename; my $line_num = $node->line_num; 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; } } } =head1 Description C provides the Perl API for manipulating the Apache configuration tree =head1 API C provides the following functions and/or methods: =head2 C Get the arguments for the current directive: $args = $node->args(); =over 4 =item obj: C<$node> ( C> ) =item ret: C<$args> ( string ) Arguments are separated by a whitespace in the string. =item since: 2.0.00 =back For example, in F: PerlSwitches -M/opt/lib -M/usr/local/lib -wT And later: my $tree = Apache2::Directive::conftree(); my $node = $tree->lookup('PerlSwitches'); my $args = $node->args; C<$args> now contains the string "-M/opt/lib -M/usr/local/lib -wT" =head2 C Get a hash representation of the configuration tree, in a format suitable for inclusion in EPerlE sections. $config_hash = $conftree->as_hash(); =over 4 =item obj: C<$conftree> ( C> ) The config tree to stringify =item ret: C<$config_hash> ( HASH reference ) =item since: 2.0.00 =back For example: in F: SetHandler perl-script PerlHandler Test::Module And later: my $tree = Apache2::Directive::conftree(); my $node = $tree->lookup('Location', '/test/'); my $hash = $node->as_hash; C<$hash> now is: { 'SetHandler' => 'perl-script', 'PerlHandler' => 'Test::Module', } =head2 C Get a string representation of the configuration node, in F format. $string = $node->as_string(); =over 4 =item obj: C<$node> ( C> ) The config tree to stringify =item ret: C<$string> ( string ) =item since: 2.0.00 =back For example: in F: SetHandler perl-script PerlHandler Test::Module And later: my $tree = Apache2::Directive::conftree(); my $node = $tree->lookup('Location', '/test/'); my $string = $node->as_string; C<$string> is now: SetHandler perl-script PerlHandler Test::Module =head2 C Get the root of the configuration tree: $conftree = Apache2::Directive::conftree(); =over 4 =item obj: C ( class name ) =item ret: C<$conftree> ( C> ) =item since: 2.0.00 =back =head2 C Get the name of the directive in C<$node>: $name = $node->directive(); =over 4 =item obj: C<$node> ( C> ) =item ret: C<$name> ( string ) =item since: 2.0.00 =back =head2 C Get the F the configuration node was created from: $filename = $node->filename(); =over 4 =item obj: C<$node> ( C> ) =item ret: C<$filename> ( string ) =item since: 2.0.00 =back For example: my $tree = Apache2::Directive::conftree(); my $node = $tree->lookup('VirtualHost', 'example.com'); my $filename = $node->filename; C<$filename> is now the full path to the F that VirtualHost was defined in. If the directive was added with C>, the filename will be the path to the F that trigerred that Perl code. =head2 C Get the first child node of this directive: $child_node = $node->first_child; =over 4 =item obj: C<$node> ( C> ) =item ret: C<$child_node> ( C> ) Returns the first child node of C<$node>, C if there is none =item since: 2.0.00 =back =head2 C Get the line number in a F this node was created at: $lineno = $node->line_num(); =over 4 =item obj: C<$node> ( C> ) =item arg1: C<$lineno> (integer) =item since: 2.0.00 =back =head2 C Get the node(s) matching a certain value. $node = $conftree->lookup($directive, $args); @nodes = $conftree->lookup($directive, $args); =over 4 =item obj: C<$conftree> ( C> ) The config tree to stringify =item arg1: C<$directive> ( string ) The name of the directive to search for =item opt arg2: C ( string ) Optional args to the directive to filter for =item ret: C<$string> ( string / ARRAY of HASH refs ) In LIST context, it returns all matching nodes. In SCALAR context, it returns only the first matching node. If called with only C<$directive> value, this method returns all nodes from that directive. For example: @Alias = $conftree->lookup('Alias'); returns all nodes for C directives. If called with an extra C<$args> argument, it returns only nodes where both the directive and the args matched. For example: $VHost = $tree->lookup('VirtualHost', '_default_:8000'); =item since: 2.0.00 =back =head2 C Get the next directive node in the tree: $next_node = $node->next(); =over 4 =item obj: C<$node> ( C> ) =item ret: C<$next_node> ( C> ) Returns the next sibling of C<$node>, C if there is none =item since: 2.0.00 =back =head2 C Get the parent node of this directive: $parent_node = $node->parent(); =over 4 =item obj: C<$node> ( C> ) =item ret: C ( C> ) Returns the parent of C<$node>, C if this node is the root node =item since: 2.0.00 =back =head1 See Also L. =head1 Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. =head1 Authors L. =cut