.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "docs::api::Apache2::Directive 3pm" .TH docs::api::Apache2::Directive 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Apache2::Directive \- Perl API for manipulating the Apache configuration tree .SH Synopsis .IX Header "Synopsis" .Vb 1 \& use Apache2::Directive (); \& \& my $tree = Apache2::Directive::conftree(); \& \& my $documentroot = $tree\->lookup(\*(AqDocumentRoot\*(Aq); \& \& my $vhost = $tree\->lookup(\*(AqVirtualHost\*(Aq, \*(Aqlocalhost:8000\*(Aq); \& my $servername = $vhost\->{\*(AqServerName\*(Aq}; \& \& 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; \& } \& } \& } .Ve .SH Description .IX Header "Description" \&\f(CW\*(C`Apache2::Directive\*(C'\fR provides the Perl API for manipulating the Apache configuration tree .SH API .IX Header "API" \&\f(CW\*(C`Apache2::Directive\*(C'\fR provides the following functions and/or methods: .ie n .SS """args""" .el .SS \f(CWargs\fP .IX Subsection "args" Get the arguments for the current directive: .PP .Vb 1 \& $args = $node\->args(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: $args ( string )" 4 .el .IP "ret: \f(CW$args\fR ( string )" 4 .IX Item "ret: $args ( string )" .PD Arguments are separated by a whitespace in the string. .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP For example, in \fIhttpd.conf\fR: .PP .Vb 1 \& PerlSwitches \-M/opt/lib \-M/usr/local/lib \-wT .Ve .PP And later: .PP .Vb 3 \& my $tree = Apache2::Directive::conftree(); \& my $node = $tree\->lookup(\*(AqPerlSwitches\*(Aq); \& my $args = $node\->args; .Ve .PP \&\f(CW$args\fR now contains the string "\-M/opt/lib \-M/usr/local/lib \-wT" .ie n .SS """as_hash""" .el .SS \f(CWas_hash\fP .IX Subsection "as_hash" Get a hash representation of the configuration tree, in a format suitable for inclusion in sections. .PP .Vb 1 \& $config_hash = $conftree\->as_hash(); .Ve .ie n .IP "obj: $conftree ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$conftree\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $conftree ( Apache2::Directive object )" The config tree to stringify .ie n .IP "ret: $config_hash ( HASH reference )" 4 .el .IP "ret: \f(CW$config_hash\fR ( HASH reference )" 4 .IX Item "ret: $config_hash ( HASH reference )" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example: in \fIhttpd.conf\fR: .PP .Vb 4 \& \& SetHandler perl\-script \& PerlHandler Test::Module \& .Ve .PP And later: .PP .Vb 3 \& my $tree = Apache2::Directive::conftree(); \& my $node = $tree\->lookup(\*(AqLocation\*(Aq, \*(Aq/test/\*(Aq); \& my $hash = $node\->as_hash; .Ve .PP \&\f(CW$hash\fR now is: .PP .Vb 4 \& { \& \*(AqSetHandler\*(Aq => \*(Aqperl\-script\*(Aq, \& \*(AqPerlHandler\*(Aq => \*(AqTest::Module\*(Aq, \& } .Ve .ie n .SS """as_string""" .el .SS \f(CWas_string\fP .IX Subsection "as_string" Get a string representation of the configuration node, in \&\fIhttpd.conf\fR format. .PP .Vb 1 \& $string = $node\->as_string(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" The config tree to stringify .ie n .IP "ret: $string ( string )" 4 .el .IP "ret: \f(CW$string\fR ( string )" 4 .IX Item "ret: $string ( string )" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example: in \fIhttpd.conf\fR: .PP .Vb 4 \& \& SetHandler perl\-script \& PerlHandler Test::Module \& .Ve .PP And later: .PP .Vb 3 \& my $tree = Apache2::Directive::conftree(); \& my $node = $tree\->lookup(\*(AqLocation\*(Aq, \*(Aq/test/\*(Aq); \& my $string = $node\->as_string; .Ve .PP \&\f(CW$string\fR is now: .PP .Vb 2 \& SetHandler perl\-script \& PerlHandler Test::Module .Ve .ie n .SS """conftree""" .el .SS \f(CWconftree\fP .IX Subsection "conftree" Get the root of the configuration tree: .PP .Vb 1 \& $conftree = Apache2::Directive::conftree(); .Ve .ie n .IP "obj: ""Apache2::Directive"" ( class name )" 4 .el .IP "obj: \f(CWApache2::Directive\fR ( class name )" 4 .IX Item "obj: Apache2::Directive ( class name )" .PD 0 .ie n .IP "ret: $conftree ( ""Apache2::Directive object"" )" 4 .el .IP "ret: \f(CW$conftree\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "ret: $conftree ( Apache2::Directive object )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .ie n .SS """directive""" .el .SS \f(CWdirective\fP .IX Subsection "directive" Get the name of the directive in \f(CW$node\fR: .PP .Vb 1 \& $name = $node\->directive(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: $name ( string )" 4 .el .IP "ret: \f(CW$name\fR ( string )" 4 .IX Item "ret: $name ( string )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .ie n .SS """filename""" .el .SS \f(CWfilename\fP .IX Subsection "filename" Get the \fIfilename\fR the configuration node was created from: .PP .Vb 1 \& $filename = $node\->filename(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: $filename ( string )" 4 .el .IP "ret: \f(CW$filename\fR ( string )" 4 .IX Item "ret: $filename ( string )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example: .PP .Vb 3 \& my $tree = Apache2::Directive::conftree(); \& my $node = $tree\->lookup(\*(AqVirtualHost\*(Aq, \*(Aqexample.com\*(Aq); \& my $filename = $node\->filename; .Ve .PP \&\f(CW$filename\fR is now the full path to the \fIhttpd.conf\fR that VirtualHost was defined in. .PP If the directive was added with \&\f(CWadd_config()\fR, the filename will be the path to the \fIhttpd.conf\fR that trigerred that Perl code. .ie n .SS """first_child""" .el .SS \f(CWfirst_child\fP .IX Subsection "first_child" Get the first child node of this directive: .PP .Vb 1 \& $child_node = $node\->first_child; .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: $child_node ( ""Apache2::Directive object"" )" 4 .el .IP "ret: \f(CW$child_node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "ret: $child_node ( Apache2::Directive object )" .PD Returns the first child node of \f(CW$node\fR, \f(CW\*(C`undef\*(C'\fR if there is none .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .ie n .SS """line_num""" .el .SS \f(CWline_num\fP .IX Subsection "line_num" Get the line number in a \fIfilename\fR this node was created at: .PP .Vb 1 \& $lineno = $node\->line_num(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "arg1: $lineno (integer)" 4 .el .IP "arg1: \f(CW$lineno\fR (integer)" 4 .IX Item "arg1: $lineno (integer)" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .ie n .SS """lookup""" .el .SS \f(CWlookup\fP .IX Subsection "lookup" Get the node(s) matching a certain value. .PP .Vb 2 \& $node = $conftree\->lookup($directive, $args); \& @nodes = $conftree\->lookup($directive, $args); .Ve .ie n .IP "obj: $conftree ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$conftree\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $conftree ( Apache2::Directive object )" The config tree to stringify .ie n .IP "arg1: $directive ( string )" 4 .el .IP "arg1: \f(CW$directive\fR ( string )" 4 .IX Item "arg1: $directive ( string )" The name of the directive to search for .ie n .IP "opt arg2: ""args"" ( string )" 4 .el .IP "opt arg2: \f(CWargs\fR ( string )" 4 .IX Item "opt arg2: args ( string )" Optional args to the directive to filter for .ie n .IP "ret: $string ( string / ARRAY of HASH refs )" 4 .el .IP "ret: \f(CW$string\fR ( string / ARRAY of HASH refs )" 4 .IX Item "ret: $string ( string / ARRAY of HASH refs )" In LIST context, it returns all matching nodes. .Sp In SCALAR context, it returns only the first matching node. .Sp If called with only \f(CW$directive\fR value, this method returns all nodes from that directive. For example: .Sp .Vb 1 \& @Alias = $conftree\->lookup(\*(AqAlias\*(Aq); .Ve .Sp returns all nodes for \f(CW\*(C`Alias\*(C'\fR directives. .Sp If called with an extra \f(CW$args\fR argument, it returns only nodes where both the directive and the args matched. For example: .Sp .Vb 1 \& $VHost = $tree\->lookup(\*(AqVirtualHost\*(Aq, \*(Aq_default_:8000\*(Aq); .Ve .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .ie n .SS """next""" .el .SS \f(CWnext\fP .IX Subsection "next" Get the next directive node in the tree: .PP .Vb 1 \& $next_node = $node\->next(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: $next_node ( ""Apache2::Directive object"" )" 4 .el .IP "ret: \f(CW$next_node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "ret: $next_node ( Apache2::Directive object )" .PD Returns the next sibling of \f(CW$node\fR, \f(CW\*(C`undef\*(C'\fR if there is none .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .ie n .SS """parent""" .el .SS \f(CWparent\fP .IX Subsection "parent" Get the parent node of this directive: .PP .Vb 1 \& $parent_node = $node\->parent(); .Ve .ie n .IP "obj: $node ( ""Apache2::Directive object"" )" 4 .el .IP "obj: \f(CW$node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "obj: $node ( Apache2::Directive object )" .PD 0 .ie n .IP "ret: ""parent_node"" ( ""Apache2::Directive object"" )" 4 .el .IP "ret: \f(CWparent_node\fR ( \f(CWApache2::Directive object\fR )" 4 .IX Item "ret: parent_node ( Apache2::Directive object )" .PD Returns the parent of \f(CW$node\fR, \f(CW\*(C`undef\*(C'\fR if this node is the root node .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .SH "See Also" .IX Header "See Also" mod_perl 2.0 documentation. .SH Copyright .IX Header "Copyright" mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. .SH Authors .IX Header "Authors" The mod_perl development team and numerous contributors.