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

See Also

268       mod_perl 2.0 documentation.
269
271       mod_perl 2.0 and its core modules are copyrighted under The Apache
272       Software License, Version 2.0.
273

Authors

275       The mod_perl development team and numerous contributors.
276
277
278
279perl v5.8.8                       2006-11-19  docs::api::Apache2::Directive(3)
Impressum