1docs::api::Apache2::DirUescetrivCeo(n3t)ributed Perl Docduomcesn:t:aatpiio:n:Apache2::Directive(3)
2
3
4

NAME

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

Synopsis

10         use Apache2::Directive ();
11
12         my $tree = Apache2::Directive::conftree();
13
14         my $documentroot = $tree->lookup('DocumentRoot');
15
16         my $vhost = $tree->lookup('VirtualHost', 'localhost:8000');
17         my $servername = $vhost->{'ServerName'};
18
19         use Data::Dumper;
20         print Dumper $tree->as_hash;
21
22         my $node = $tree;
23         while ($node) {
24             print $node->as_string;
25
26             #do something with $node
27
28             my $directive = $node->directive;
29             my $args = $node->args;
30             my $filename = $node->filename;
31             my $line_num = $node->line_num;
32
33             if (my $kid = $node->first_child) {
34                 $node = $kid;
35             }
36             elsif (my $next = $node->next) {
37                 $node = $next;
38             }
39             else {
40                 if (my $parent = $node->parent) {
41                     $node = $parent->next;
42                 }
43                 else {
44                     $node = undef;
45                 }
46             }
47         }
48

Description

50       "Apache2::Directive" provides the Perl API for manipulating the Apache
51       configuration tree
52

API

54       "Apache2::Directive" provides the following functions and/or methods:
55
56   "args"
57       Get the arguments for the current directive:
58
59         $args = $node->args();
60
61       obj: $node ( "Apache2::Directive object" )
62       ret: $args ( string )
63           Arguments are separated by a whitespace in the string.
64
65       since: 2.0.00
66
67       For example, in httpd.conf:
68
69         PerlSwitches -M/opt/lib -M/usr/local/lib -wT
70
71       And later:
72
73         my $tree = Apache2::Directive::conftree();
74         my $node = $tree->lookup('PerlSwitches');
75         my $args = $node->args;
76
77       $args now contains the string "-M/opt/lib -M/usr/local/lib -wT"
78
79   "as_hash"
80       Get a hash representation of the configuration tree, in a format
81       suitable for inclusion in <Perl> sections.
82
83          $config_hash = $conftree->as_hash();
84
85       obj: $conftree ( "Apache2::Directive object" )
86           The config tree to stringify
87
88       ret: $config_hash ( HASH reference )
89       since: 2.0.00
90
91       For example: in httpd.conf:
92
93         <Location /test>
94           SetHandler perl-script
95           PerlHandler Test::Module
96         </Location>
97
98       And later:
99
100         my $tree = Apache2::Directive::conftree();
101         my $node = $tree->lookup('Location', '/test/');
102         my $hash = $node->as_hash;
103
104       $hash now is:
105
106         {
107           'SetHandler'  => 'perl-script',
108           'PerlHandler' => 'Test::Module',
109         }
110
111   "as_string"
112       Get a string representation of the configuration node, in httpd.conf
113       format.
114
115          $string = $node->as_string();
116
117       obj: $node ( "Apache2::Directive object" )
118           The config tree to stringify
119
120       ret: $string ( string )
121       since: 2.0.00
122
123       For example: in httpd.conf:
124
125         <Location /test>
126           SetHandler perl-script
127           PerlHandler Test::Module
128         </Location>
129
130       And later:
131
132         my $tree = Apache2::Directive::conftree();
133         my $node = $tree->lookup('Location', '/test/');
134         my $string = $node->as_string;
135
136       $string is now:
137
138         SetHandler perl-script
139         PerlHandler Test::Module
140
141   "conftree"
142       Get the root of the configuration tree:
143
144         $conftree = Apache2::Directive::conftree();
145
146       obj: "Apache2::Directive" ( class name )
147       ret: $conftree ( "Apache2::Directive object" )
148       since: 2.0.00
149
150   "directive"
151       Get the name of the directive in $node:
152
153         $name = $node->directive();
154
155       obj: $node ( "Apache2::Directive object" )
156       ret: $name ( string )
157       since: 2.0.00
158
159   "filename"
160       Get the filename the configuration node was created from:
161
162         $filename = $node->filename();
163
164       obj: $node ( "Apache2::Directive object" )
165       ret: $filename ( string )
166       since: 2.0.00
167
168       For example:
169
170         my $tree = Apache2::Directive::conftree();
171         my $node = $tree->lookup('VirtualHost', 'example.com');
172         my $filename = $node->filename;
173
174       $filename is now the full path to the httpd.conf that VirtualHost was
175       defined in.
176
177       If the directive was added with "add_config()", the filename will be
178       the path to the httpd.conf that trigerred that Perl code.
179
180   "first_child"
181       Get the first child node of this directive:
182
183         $child_node = $node->first_child;
184
185       obj: $node ( "Apache2::Directive object" )
186       ret: $child_node ( "Apache2::Directive object" )
187           Returns the first child node of $node, "undef" if there is none
188
189       since: 2.0.00
190
191   "line_num"
192       Get the line number in a filename this node was created at:
193
194         $lineno = $node->line_num();
195
196       obj: $node ( "Apache2::Directive object" )
197       arg1: $lineno (integer)
198       since: 2.0.00
199
200   "lookup"
201       Get the node(s) matching a certain value.
202
203         $node  = $conftree->lookup($directive, $args);
204         @nodes = $conftree->lookup($directive, $args);
205
206       obj: $conftree ( "Apache2::Directive object" )
207           The config tree to stringify
208
209       arg1: $directive ( string )
210           The name of the directive to search for
211
212       opt arg2: "args" ( string )
213           Optional args to the directive to filter for
214
215       ret: $string ( string / ARRAY of HASH refs )
216           In LIST context, it returns all matching nodes.
217
218           In SCALAR context, it returns only the first matching node.
219
220           If called with only $directive value, this method returns all nodes
221           from that directive. For example:
222
223             @Alias = $conftree->lookup('Alias');
224
225           returns all nodes for "Alias" directives.
226
227           If called with an extra $args argument, it returns only nodes where
228           both the directive and the args matched. For example:
229
230             $VHost = $tree->lookup('VirtualHost', '_default_:8000');
231
232       since: 2.0.00
233
234   "next"
235       Get the next directive node in the tree:
236
237         $next_node = $node->next();
238
239       obj: $node ( "Apache2::Directive object" )
240       ret: $next_node ( "Apache2::Directive object" )
241           Returns the next sibling of $node, "undef" if there is none
242
243       since: 2.0.00
244
245   "parent"
246       Get the parent node of this directive:
247
248         $parent_node = $node->parent();
249
250       obj: $node ( "Apache2::Directive object" )
251       ret: "parent_node" ( "Apache2::Directive object" )
252           Returns the parent of $node, "undef" if this node is the root node
253
254       since: 2.0.00
255

See Also

257       mod_perl 2.0 documentation.
258
260       mod_perl 2.0 and its core modules are copyrighted under The Apache
261       Software License, Version 2.0.
262

Authors

264       The mod_perl development team and numerous contributors.
265
266
267
268perl v5.36.0                      2022-07-21  docs::api::Apache2::Directive(3)
Impressum