| 1 | package Config::ApacheFormat; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | our $VERSION = '1.2'; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Config::ApacheFormat - use Apache format config files | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | Config files used with this module are in Apache's format: | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # comment here | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | RootDir /path/foo | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | LogDir /path/foo/log | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Colors red green orange blue \ | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | black teal | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | <Directory /path/foo> | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # override Colors inside block | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | Colors red blue black | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | </Directory> | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Code to use this config file might look like: | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | use Config::ApacheFormat; | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # load a conf file | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | my $config = Config::ApacheFormat->new(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $config->read("my.conf"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # access some parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $root_dir = $config->get("RootDir"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $log_dir = $config->get("LogDir"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | @colors = $config->get("colors"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # using the autoloaded methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $config->autoload_support(1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | $root_dir = $config->RootDir; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $log_dir = $config->logdir; | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # access parameters inside a block | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my $block = $config->block(Directory => "/path/foo"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | @colors = $block->get("colors"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $root_dir = $block->get("root_dir"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | This module is designed to parse a configuration file in the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | syntax used by the Apache web server (see http://httpd.apache.org for | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | details). This allows you to build applications which can be easily | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | managed by experienced Apache admins. Also, by using this module, | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | you'll benefit from the support for nested blocks with built-in | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | parameter inheritance. This can greatly reduce the amount or repeated | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | information in your configuration files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | A good reference to the Apache configuration file format can be found | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | here: | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | http://httpd.apache.org/docs-2.0/configuring.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | To quote from that document, concerning directive syntax: | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | Apache configuration files contain one directive per line. The | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | back-slash "\" may be used as the last character on a line to | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | indicate that the directive continues onto the next line. There must | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | be no other characters or white space between the back-slash and the | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | end of the line. | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | Directives in the configuration files are case-insensitive, but | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | arguments to directives are often case sensitive. Lines that begin | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | with the hash character "#" are considered comments, and are | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ignored. Comments may not be included on a line after a configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | directive. Blank lines and white space occurring before a directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | are ignored, so you may indent directives for clarity. | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | And block notation: | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Directives placed in the main configuration files apply to the entire | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | server. If you wish to change the configuration for only a part of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | server, you can scope your directives by placing them in <Directory>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | <DirectoryMatch>, <Files>, <FilesMatch>, <Location>, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | <LocationMatch> sections. These sections limit the application of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | directives which they enclose to particular filesystem locations or | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | URLs. They can also be nested, allowing for very fine grained | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | configuration. | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | This module will parse actual Apache configuration files, but you will need to set some options to non-default values. See L<"Parsing a Real Apache Config File">. | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =item $config = Config::ApacheFormat->new(opt => "value") | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | This method creates an object that can then be used to read configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | files. It does not actually read any files; for that, use the C<read()> | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | method below. The object supports the following attributes, all of which | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | may be set through C<new()>: | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =item inheritance_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | Set this to 0 to turn off the inheritance feature. Block inheritance | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | means that variables declared outside a block are available from | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | inside the block unless overriden. Defaults to 1. | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =item include_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | When this is set to 1, the directive "Include" will be treated | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | specially by the parser. It will cause the value to be treated as a | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | filename and that filename will be read in. If you use "Include" | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | with a directory, every file in that directory will be included. | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | This matches Apache's behavior and allows users to break up | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | configuration files into multiple, possibly shared, pieces. | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | Defaults to 1. | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =item autoload_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Set this to 1 and all your directives will be available as object | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | methods. So instead of: | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | $config->get("foo"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | You can write: | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | $config->foo; | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | Defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =item case_sensitive | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | Set this to 1 to preserve the case of directive names. Otherwise, all | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | names will be C<lc()>ed and matched case-insensitively. Defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =item fix_booleans | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | If set to 1, then during parsing, the strings "Yes", "On", and "True" | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | will be converted to 1, and the strings "No", "Off", and "False" will | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | be converted to 0. This allows you to more easily use C<get()> in | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | conditional statements. | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | For example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # httpd.conf | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | UseCanonicalName On | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | Then in Perl: | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | $config = Config::ApacheFormat->new(fix_booleans => 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | $config->read("httpd.conf"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | if ($config->get("UseCanonicalName")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # this will get executed if set to Yes/On/True | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | This option defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | =item expand_vars | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | If set, then you can use variable expansion in your config file by | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | prefixing directives with a C<$>. Hopefully this seems logical to you: | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | Website http://my.own.dom | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | JScript $Website/js | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | Images $Website/images | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | Undefined variables in your config file will result in an error. To | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | use a literal C<$>, simply prefix it with a C<\> (backslash). Like | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | in Perl, you can use brackets to delimit the variables more precisely: | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Nickname Rob | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | Fullname ${Nickname}ert | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Since only scalars are supported, if you use a multi-value, you will | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | only get back the first one: | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | Options Plus Minus "About the Same" | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | Values $Options | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | In this examples, "Values" will become "Plus". This is seldom a limitation | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | since in most cases, variable subsitution is used like the first example | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | shows. This option defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | =item setenv_vars | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | If this is set to 1, then the special C<SetEnv> directive will be set | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | values in the environment via C<%ENV>. Also, the special C<UnSetEnv> | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | directive will delete environment variables. | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | For example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # $ENV{PATH} = "/usr/sbin:/usr/bin" | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | SetEnv PATH "/usr/sbin:/usr/bin" | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # $ENV{MY_SPECIAL_VAR} = 10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | SetEnv MY_SPECIAL_VAR 10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # delete $ENV{THIS} | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | UnsetEnv THIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | This option defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | =item valid_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | If you provide an array of directive names then syntax errors will be | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | generated during parsing for invalid directives. Otherwise, any | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | directive name will be accepted. For exmaple, to only allow | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | directives called "Bar" and "Bif": | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | $config = Config::ApacheFormat->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | valid_directives => [qw(Bar Bif)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | =item valid_blocks | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | If you provide an array of block names then syntax errors will be | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | generated during parsing for invalid blocks. Otherwise, any block | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | name will be accepted. For exmaple, to only allow "Directory" and | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | "Location" blocks in your config file: | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | $config = Config::ApacheFormat->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | valid_blocks => [qw(Directory Location)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | =item include_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | This directive controls the name of the include directive. By default | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | it is C<< ['Include'] >>, but you can set it to any list of directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | names. | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | =item root_directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | This controls what the root directive is, if any. If you set this to | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | the name of a directive it will be used as a base directory for | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | C<Include> processing. This mimics the behavior of C<ServerRoot> in | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | real Apache config files, and as such you'll want to set it to | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 'ServerRoot' when parsing an Apache config. The default is C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | =item hash_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | This determines which directives (if any) should be parsed so that the | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | first value is actually a key into the remaining values. For example, | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | C<AddHandler> is such a directive. | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | AddHandler cgi-script .cgi .sh | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | AddHandler server-parsed .shtml | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | To parse this correctly, use: | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | $config = Config::ApacheFormat->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | hash_directives => [qw(AddHandler PerlSetVar)] | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | Then, use the two-argument form of C<get()>: | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | @values = $config->get(AddHandler => 'cgi-script'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | This allows you to access each directive individually, which is needed | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | to correctly handle certain special-case Apache settings. | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | =item duplicate_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | This option controls how duplicate directives are handled. By default, | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | if multiple directives of the same name are encountered, the last one | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | wins: | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | Port 8080 | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | Port 5053 | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | In this case, the directive C<Port> would be set to the last value, C<5053>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | This is useful because it allows you to include other config files, which | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | you can then override: | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # default setup | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | Include /my/app/defaults.conf | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # override port | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | Port 5053 | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | In addition to this default behavior, C<Config::ApacheFormat> also supports | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | the following modes: | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | last - the value from the last one is kept (default) | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | error - duplicate directives result in an error | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | combine - combine values of duplicate directives together | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | These should be self-explanatory. If set to C<error>, any duplicates | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | will result in an error. If set to C<last> (the default), the last | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | value wins. If set to C<combine>, then duplicate directives are | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | combined together, just like they had been specified on the same line. | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | All of the above attributes are also available as accessor methods. Thus, | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | this: | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | $config = Config::ApacheFormat->new(inheritance_support => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | include_support => 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | Is equivalent to: | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | $config = Config::ApacheFormat->new(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | $config->inheritance_support(0); | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | $config->include_support(1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 12 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 12 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 12 | ▶ | use Text::Balanced qw(extract_delimited extract_variable); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 12 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # this "placeholder" is used to handle escaped variables (\$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # if it conflicts with a define in your config file somehow, simply | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # override it with "$Config::ApacheFormat::PLACEHOLDER = 'whatever';" | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 12 | our $PLACEHOLDER = "~PLaCE_h0LDeR_$$~"; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # declare generated methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | use Class::MethodMaker | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 12 | ▶ | new_with_init => "new", | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | new_hash_init => "hash_init", | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | get_set => [ -noclear => qw/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | inheritance_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | include_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | autoload_support | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | case_sensitive | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | expand_vars | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | setenv_vars | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | valid_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | valid_blocks | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | duplicate_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | hash_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | fix_booleans | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | root_directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | include_directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | _parent | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | _data | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | _block_vals | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 12 | /]; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # setup defaults | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2267 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2267 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 2267 | my %args = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | inheritance_support => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | include_support => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | autoload_support => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | case_sensitive => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | expand_vars => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | setenv_vars => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | valid_directives => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | valid_blocks => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | duplicate_directives=> 'last', | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | include_directives => ['Include'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | hash_directives => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | fix_booleans => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | root_directive => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | _data => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | @_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # could probably use a few more of these... | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | croak("Invalid duplicate_directives option '$self->{duplicate_directives}' - must be 'last', 'error', or 'combine'") | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | unless $args{duplicate_directives} eq 'last' or | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | $args{duplicate_directives} eq 'error' or | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2267 | ▶ | $args{duplicate_directives} eq 'combine'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$args{"duplicate_directives"} eq "last" or $args{"duplicate_directives"} eq "error" or $args{"duplicate_directives"} eq "combine"
$args{"duplicate_directives"} eq "last" or $args{"duplicate_directives"} eq "error"
MC/DC0%0/3
$args{"duplicate_directives"} eq "last" or $args{"duplicate_directives"} eq "error" or $args{"duplicate_directives"} eq "combine"
$args{"duplicate_directives"} eq "last"
$args{"duplicate_directives"} eq "error"
$args{"duplicate_directives"} eq "combine"
Truth table25%1/4
A or B or C
A= $args{"duplicate_directives"} eq "last"B= $args{"duplicate_directives"} eq "error"C= $args{"duplicate_directives"} eq "combine"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 2267 | return $self->hash_init(%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =item $config->read("my.conf"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =item $config->read(\*FILE); | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | Reads a configuration file into the config object. You must pass | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | either the path of the file to be read or a reference to an open | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | filehandle. If an error is encountered while reading the file, this | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | method will die(). | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | Calling read() more than once will add the new configuration values | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | from another source, overwriting any conflicting values. Call clear() | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | first if you want to read a new set from scratch. | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # read the configuration file, optionally ending at block_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 119 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 119 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 119 | my @fstack; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # open the file if needed and setup file stack | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | my $fh; | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 119 | ▶ | if (ref $file) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | @fstack = { fh => $file, | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | filename => "", | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | line_num => 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 119 | ▶ | open($fh, "<", $file) or croak("Unable to open file '$file': $!"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 119 | @fstack = { fh => $fh, | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | line_num => 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 119 | return $self->_read(\@fstack); | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # underlying _read, called recursively an block name for | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # nested block objects | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2269 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=64 SCAR=43.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2269 | my ($self, $fstack, $block_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # pre-fetch for loop | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2269 | my $case_sensitive = $self->{case_sensitive}; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2269 | my $data = $self->{_data}; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # pre-compute lookups for validation lists, if they exists | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 2269 | my ($validate_blocks, %valid_blocks, | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | $validate_directives, %valid_directives); | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2269 | ▶ | if ($self->{valid_directives}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 5 | ▶ | %valid_directives = map { ($case_sensitive ? $_ : lc($_)), 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | @{$self->{valid_directives}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | $validate_directives = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 2269 | ▶ | if ($self->{valid_blocks}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 20 | ▶ | %valid_blocks = map { ($case_sensitive ? $_ : lc($_)), 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 8 | @{$self->{valid_blocks}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | 8 | $validate_blocks = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # pre-compute a regex to recognize the include directives | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | my $re = '^(?:' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 2269 | join('|', @{$self->{include_directives}}) . ')$'; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2269 | my $include_re; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2269 | ▶ | if ($self->{case_sensitive}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $include_re = qr/$re/; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2269 | $include_re = qr/$re/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # parse through the file, line by line | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 2269 | my ($name, $values, $line, $orig); | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | my ($fh, $filename) = | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 2269 | @{$fstack->[-1]}{qw(fh filename)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2269 | my $line_num = \$fstack->[-1]{line_num}; | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | LINE: | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 2269 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | # done with current file? | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 18593 | ▶ | if (eof $fh) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 120 | ▶ | last LINE if @$fstack == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 7 | pop @$fstack; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | ($fh, $filename) = | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 7 | @{$fstack->[-1]}{qw(fh filename)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | 7 | $line_num = \$fstack->[-1]{line_num}; | |||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # accumulate a full line, dealing with line-continuation | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 18480 | $line = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | 18480 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ s/\\$// and not eof $fh
MC/DC50%1/2
$line =~ s/\\$// and not eof $fh
$line =~ s/\\$//
not eof $fh
Truth table66%2/3
A and not(B)
A= $line =~ s/\\$//B= not eof $fh
| |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 12 | ▶ | no warnings 'uninitialized'; # blank warnings | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 18483 | $_ = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | 18483 | ${$line_num}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 18483 | s/^\s+//; # strip leading space | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 18483 | ▶ | next LINE if /^#/; # skip comments | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 18017 | s/\s+$//; # strip trailing space | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 18017 | $line .= $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | } while ($line =~ s/\\$// and not eof($fh)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # skip blank lines | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 18014 | ▶ | next LINE unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # parse line | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 16855 | ▶ | if ($line =~ /^<\/(\w+)>$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # end block | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 2149 | $orig = $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | 2149 | ▶ | $name = lc $name unless $case_sensitive; # lc($1) breaks on 5.6.1! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 2149 | ▶ | croak("Error in config file $filename, line $$line_num: " . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $block_name and $block_name eq $name
MC/DC50%1/2
defined $block_name and $block_name eq $name
defined $block_name
$block_name eq $name
Truth table66%2/3
A and B
A= defined $block_nameB= $block_name eq $name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | "Unexpected end to block '$orig' found" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | (defined $block_name ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | "\nI was waiting for </$block_name>\n" : "")) | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | unless defined $block_name and $block_name eq $name; | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # this is our cue to return | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2147 | last LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } elsif ($line =~ /^<(\w+)\s*(.*)>$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # open block | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 2151 | $orig = $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 2151 | $values = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 2151 | ▶ | $name = lc $name unless $case_sensitive; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | croak("Error in config file $filename, line $$line_num: " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | "block '<$orig>' is not a valid block name") | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | unless not $validate_blocks or | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2151 | ▶ | exists $valid_blocks{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $validate_blocks or exists $valid_blocks{$name}
MC/DC100%2/2
not $validate_blocks or exists $valid_blocks{$name}
not $validate_blocks
exists $valid_blocks{$name}
Truth table100%3/3
not(A) or B
A= not $validate_blocksB= exists $valid_blocks{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2150 | my $val = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 2150 | ▶ | $val = _parse_value_list($values) if $values; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # create new object for block, inheriting options from | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # this object, with this object set as parent (using | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # weaken() to avoid creating a circular reference that | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # would leak memory) | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2150 | my $parent = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2150 | weaken($parent); | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | my $block = ref($self)->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | inheritance_support => $self->{inheritance_support}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | include_support => $self->{include_support}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | autoload_support => $self->{autoload_support}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | case_sensitive => $case_sensitive, | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | expand_vars => $self->{expand_vars}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | setenv_vars => $self->{setenv_vars}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | valid_directives => $self->{valid_directives}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | valid_blocks => $self->{valid_blocks}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | duplicate_directives=> $self->{duplicate_directives}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | hash_directives => $self->{hash_directives}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | fix_booleans => $self->{fix_booleans}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | root_directive => $self->{root_directive}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | include_directives => $self->{include_directives}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2150 | ▶ | _parent => $parent, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | _block_vals => ref $val ? $val : [ $val ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # tell the block to read from $fh up to the closing tag | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # for this block | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2150 | $block->_read($fstack, $name); | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # store block for get() and block() | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2147 | push @{$data->{$name}}, $block; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } elsif ($line =~ /^(\w+)(?:\s+(.+))?$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 12554 | $orig = $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 12554 | $values = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | 12554 | ▶ | $values = 1 unless defined $values; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 12554 | ▶ | $name = lc $name unless $case_sensitive; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | croak("Error in config file $filename, line $$line_num: " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | "directive '$name' is not a valid directive name") | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | unless not $validate_directives or | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 12554 | ▶ | exists $valid_directives{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $validate_directives or exists $valid_directives{$name}
MC/DC100%2/2
not $validate_directives or exists $valid_directives{$name}
not $validate_directives
exists $valid_directives{$name}
Truth table100%3/3
not(A) or B
A= not $validate_directivesB= exists $valid_directives{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # parse out values, handling any strings or arrays | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 12553 | my @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 551 | 12553 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | 12553 | @val = _parse_value_list($values); | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 12553 | ▶ | croak("Error in config file $filename, line $$line_num: $@") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # expand_vars if set | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 12553 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | 12553 | ▶ | @val = $self->_expand_vars(@val) if $self->{expand_vars}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 12553 | ▶ | croak("Error in config file $filename, line $$line_num: $@") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # and then setenv too (allowing PATH "$BASEDIR/bin") | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 12553 | ▶ | if ($self->{setenv_vars}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 7 | ▶ | if ($name =~ /^setenv$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | ▶ | croak("Error in config file $filename, line $$line_num: ". | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | " can't use setenv_vars " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | "with malformed SetEnv directive") if @val != 2; | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | $ENV{"$val[0]"} = $val[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | } elsif ($name =~ /^unsetenv$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | ▶ | croak("Error in config file $filename, line $$line_num: ". | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | "can't use setenv_vars " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | "with malformed UnsetEnv directive") unless @val; | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 1 | delete $ENV{$_} for @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # Include processing | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # because of the way our inheritance works, we navigate multiple files in reverse | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 12553 | ▶ | if ($name =~ /$include_re/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 6 | for my $f (reverse @val) { | |||||||||||||||||||||||||||||||||||||||||||||
| 583 | # if they specified a root_directive (ServerRoot) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # it is defined, prefix that to relative paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | my $root = $self->{case_sensitive} ? $self->{root_directive} | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 7 | ▶ | : lc $self->{root_directive}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 7 | ▶ | if (! File::Spec->file_name_is_absolute($f) && exists $data->{$root}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not "File::Spec"->file_name_is_absolute($f) and exists $data->{$root}
MC/DC50%1/2
not "File::Spec"->file_name_is_absolute($f) and exists $data->{$root}
not "File::Spec"->file_name_is_absolute($f)
exists $data->{$root}
Truth table66%2/3
not(A) and B
A= not "File::Spec"->file_name_is_absolute($f)B= exists $data->{$root}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # looks odd; but only reliable method is construct UNIX-style | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # then deconstruct | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | my @parts = File::Spec->splitpath("$data->{$root}[0]/$f"); | |||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | $f = File::Spec->catpath(@parts); | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # this handles directory includes (i.e. will include all files in a directory) | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 7 | my @files; | |||||||||||||||||||||||||||||||||||||||||||||
| 596 | 7 | ▶ | if (-d $f) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | ▶ | opendir(INCD, $f) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | || croak("Cannot open include directory '$f' at $filename ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | "line $$line_num: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | @files = map { "$f/$_" } sort grep { -f "$f/$_" } readdir INCD; | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | 1 | closedir(INCD); | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 6 | @files = $f; | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 7 | for my $values (reverse @files) { | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | # just try to open it as-is | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 9 | my $include_fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | 9 | ▶ | unless (open($include_fh, "<", $values)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 4 | ▶ | if ($fstack->[0]{filename}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # try opening it relative to the enclosing file | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | # using File::Spec | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 4 | my @parts = File::Spec->splitpath($filename); | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 4 | $parts[-1] = $values; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 4 | ▶ | open($include_fh, "<", File::Spec->catpath(@parts)) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 616 | croak("Unable to open include file '$values' ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 617 | "at $filename line $$line_num: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | croak("Unable to open include file '$values' ", | |||||||||||||||||||||||||||||||||||||||||||||
| 620 | "at $filename line $$line_num: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # push a new record onto the @fstack for this file | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 8 | push(@$fstack, { fh => $fh = $include_fh, | |||||||||||||||||||||||||||||||||||||||||||||
| 626 | filename => $filename = $values, | ||||||||||||||||||||||||||||||||||||||||||||||
| 627 | line_number => 0 }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # hook up line counter | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 8 | $line_num = \$fstack->[-1]{line_num}; | |||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 5 | next LINE; | |||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # for each @val, "fix" booleans if so requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # do this *after* include processing so "include yes.conf" works | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 12547 | ▶ | if ($self->{fix_booleans}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 6 | for (@val) { | |||||||||||||||||||||||||||||||||||||||||||||
| 640 | 6 | ▶ | if (/^true$/i or /^on$/i or /^yes$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
/^true$/i or /^on$/i or /^yes$/i
/^true$/i or /^on$/i
MC/DC100%3/3
/^true$/i or /^on$/i or /^yes$/i
/^true$/i
/^on$/i
/^yes$/i
Truth table100%4/4
A or B or C
A= /^true$/iB= /^on$/iC= /^yes$/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | $_ = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | ▶ | } elsif (/^false$/i or /^off$/i or /^no$/i) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
/^false$/i or /^off$/i or /^no$/i
/^false$/i or /^off$/i
MC/DC0%0/3
/^false$/i or /^off$/i or /^no$/i
/^false$/i
/^off$/i
/^no$/i
Truth table75%3/4
A or B or C
A= /^false$/iB= /^off$/iC= /^no$/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 3 | $_ = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # how to handle repeated values | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | # this is complicated because we have to allow a semi-union of | ||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # the hash_directives and duplicate_directives options | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 12547 | ▶ | if ($self->{hash_directives} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"hash_directives"} and _member($orig, $self->{"hash_directives"}, $self->{"case_sensitive"})
MC/DC100%2/2
$self->{"hash_directives"} and _member($orig, $self->{"hash_directives"}, $self->{"case_sensitive"})
$self->{"hash_directives"}
_member($orig, $self->{"hash_directives"}, $self->{"case_sensitive"})
Truth table100%3/3
A and B
A= $self->{"hash_directives"}B= _member($orig, $self->{"hash_directives"}, $self->{"case_sensitive"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | && _member($orig, | ||||||||||||||||||||||||||||||||||||||||||||||
| 654 | $self->{hash_directives}, $self->{case_sensitive})){ | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 510 | my $k = shift @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 656 | 510 | ▶ | if ($self->{duplicate_directives} eq 'error') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # must check for a *specific* dup | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | croak "Duplicate directive '$orig $k' at $filename line $$line_num" | ||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | if $data->{$name}{$k}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | push @{$data->{$name}{$k}}, @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | elsif ($self->{duplicate_directives} eq 'last') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 510 | $data->{$name}{$k} = \@val; | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 665 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # push onto our struct to allow repeated declarations | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | push @{$data->{$name}{$k}}, @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 12037 | ▶ | if ($self->{duplicate_directives} eq 'error') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # not a hash_directive, so all dups are errors | ||||||||||||||||||||||||||||||||||||||||||||||
| 672 | croak "Duplicate directive '$orig' at $filename line $$line_num" | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | if $data->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | push @{$data->{$name}}, @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | elsif ($self->{duplicate_directives} eq 'last') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 12037 | $data->{$name} = \@val; | |||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # push onto our struct to allow repeated declarations | ||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | push @{$data->{$name}}, @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | croak("Error in config file $filename, line $$line_num: ". | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | "unable to parse line"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 2260 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # given a string returns a list of tokens, allowing for quoted strings | ||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # and otherwise splitting on whitespace | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 14596 | ▶ | sub _parse_value_list { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_value_list: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 14596 | my $values = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 14596 | my @val; | |||||||||||||||||||||||||||||||||||||||||||||
| 700 | 14596 | ▶ | if ($values !~ /['"\s]/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # handle the common case of a single unquoted string | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 7719 | @val = ($values); | |||||||||||||||||||||||||||||||||||||||||||||
| 703 | } elsif ($values !~ /['"]/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # strings without any quote characters can be parsed with split | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 6751 | @val = split /\s+/, $values; | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # break apart line, allowing for quoted strings with | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # escaping | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 126 | ▶ | while($values) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 212 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | 212 | ▶ | if ($values !~ /^["']/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 712 | # strip off a value and put it where it belongs | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 86 | ($val, $values) = $values =~ /^(\S+)\s*(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # starts with a quote, bring in the big guns | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 126 | $val = extract_delimited($values, q{"'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 126 | ▶ | die "value string '$values' not properly formatted\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | unless length $val; | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # remove quotes and fixup escaped characters | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 126 | $val = substr($val, 1, length($val) - 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | 126 | $val =~ s/\\(['"])/$1/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # strip off any leftover space | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 126 | $values =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 212 | push(@val, $val); | |||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 14596 | ▶ | die "no value found for directive\n" unless @val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 14596 | ▶ | return wantarray ? @val : \@val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # expand any $var stuff if expand_vars is set | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 23 | ▶ | sub _expand_vars { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_vars: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 738 | 23 | my @vals = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 739 | 23 | for (@vals) { | |||||||||||||||||||||||||||||||||||||||||||||
| 740 | 26 | local $^W = 0; # shuddup uninit | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | 26 | s/\\\$/$PLACEHOLDER/g; # kludge but works (Text::Balanced broken) | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 26 | s/\$\{?(\w+)\}?/ | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | 16 | my $var = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 744 | 16 | my $val = $self->get($var); | |||||||||||||||||||||||||||||||||||||||||||||
| 745 | 16 | ▶ | die "undefined variable '\$$var' seen\n" unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 16 | $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | /ge; | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 26 | s/$PLACEHOLDER/\$/g; # redo placeholders, removing escaping | |||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 23 | return @vals; | |||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 11751 | ▶ | sub _member { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_member: called CC=7 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # simple "in" style sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 11751 | my($name, $hdir, $case) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 756 | 11751 | ▶ | $name = lc $name unless $case; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 11751 | ▶ | return unless $hdir && ref $hdir eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hdir and ref $hdir eq "ARRAY"
MC/DC0%0/2
$hdir and ref $hdir eq "ARRAY"
$hdir
ref $hdir eq "ARRAY"
Truth table33%1/3
A and B
A= $hdirB= ref $hdir eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 11751 | for (@$hdir) { | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | 11751 | ▶ | $_ = lc $_ unless $case; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 11751 | ▶ | return 1 if $name eq $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 11241 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||
| 765 | =item C<< $value = $config->get("var_name") >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | =item C<< @vals = $config->get("list_name") >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | =item C<< $value = $config->get("hash_var_name", "key") >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||
| 771 | Returns values from the configuration file. If the directive contains | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | a single value, it will be returned. If the directive contains a list | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | of values then they will be returned as a list. If the directive does | ||||||||||||||||||||||||||||||||||||||||||||||
| 774 | not exist in the configuration file then nothing will be returned | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | (undef in scalar context, empty list in list context). | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | For example, given this confiuration file: | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||
| 779 | Foo 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | Bar bif baz bop | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | The following code would work as expected: | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | my $foo = $config->get("Foo"); # $foo = 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | my @bar = $config->get("Bar"); # @bar = ("bif", "baz", "bop") | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||
| 787 | If the name is the name of a block tag in the configuration file then | ||||||||||||||||||||||||||||||||||||||||||||||
| 788 | a list of available block specifiers will be returned. For example, | ||||||||||||||||||||||||||||||||||||||||||||||
| 789 | given this configuration file: | ||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | <Site big> | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | Size 10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 793 | </Site> | ||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||
| 795 | <Site small> | ||||||||||||||||||||||||||||||||||||||||||||||
| 796 | Size 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 797 | </Site> | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||
| 799 | This call: | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||
| 801 | @sites = $config->get("Site"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | Will return C<([ Site => "big"], [ Site => "small" ])>. These arrays | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | can then be used with the block() method described below. | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||
| 806 | If the directive was included in the file but did not have a value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1 is returned by get(). | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||
| 809 | Calling get() with no arguments will return the names of all available | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | directives. | ||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||
| 812 | Directives declared in C<hash_directives> require a key value: | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||
| 814 | $handler = $config->get("AddHandler", "cgi-script"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||
| 816 | C<directive()> is available as an alias for C<get()>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||
| 818 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # get a value from the config file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 12 | *directive = \&get; | |||||||||||||||||||||||||||||||||||||||||||||
| 822 | 205 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=15 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 205 | my ($self, $name, $srch) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # handle empty param call | ||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 205 | ▶ | return keys %{$self->{_data}} if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # lookup name in _data | ||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 203 | ▶ | $name = lc $name unless $self->{case_sensitive}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 203 | my $val = $self->{_data}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # Search through up the tree if inheritence is on and we have a | ||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # parent. Simulated recursion terminates either when $val is | ||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # found or when the root is reached and _parent is undef. | ||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 203 | ▶ | if (not defined $val and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $val and $self->{"_parent"} and $self->{"inheritance_support"}
not defined $val and $self->{"_parent"}
MC/DC33%1/3
not defined $val and $self->{"_parent"} and $self->{"inheritance_support"}
not defined $val
$self->{"_parent"}
$self->{"inheritance_support"}
Truth table50%2/4
not(A) and B and C
A= not defined $valB= $self->{"_parent"}C= $self->{"inheritance_support"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 836 | $self->{_parent} and | ||||||||||||||||||||||||||||||||||||||||||||||
| 837 | $self->{inheritance_support}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 3 | my $ptr = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 839 | do { | ||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 3 | $ptr = $ptr->{_parent}; | |||||||||||||||||||||||||||||||||||||||||||||
| 841 | 3 | $val = $ptr->{_data}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 842 | 3 | ▶ | } while (not defined $val and $ptr->{_parent}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $val and $ptr->{"_parent"}
MC/DC0%0/2
not defined $val and $ptr->{"_parent"}
not defined $val
$ptr->{"_parent"}
Truth table33%1/3
not(A) and B
A= not defined $valB= $ptr->{"_parent"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # didn't find it? | ||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 203 | ▶ | return unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # for blocks, return a list of valid block identifiers | ||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 203 | my $type = ref $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 850 | 203 | my @ret; # tmp to avoid screwing up $val | |||||||||||||||||||||||||||||||||||||||||||||
| 851 | 203 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 203 | ▶ | if ($type eq 'ARRAY' and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$type eq "ARRAY" and ref $val->[0] eq ref $self
MC/DC100%2/2
$type eq "ARRAY" and ref $val->[0] eq ref $self
$type eq "ARRAY"
ref $val->[0] eq ref $self
Truth table100%3/3
A and B
A= $type eq "ARRAY"B= ref $val->[0] eq ref $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 853 | ref($val->[0]) eq ref($self)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 1 | @ret = map { [ $name, @{$_->{_block_vals}} ] } @$val; | |||||||||||||||||||||||||||||||||||||||||||||
| 855 | 1 | $val = \@ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 856 | } elsif ($type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # hash_directive | ||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 1 | ▶ | if ($srch) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # return the specific one | ||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 1 | $val = $val->{$srch}; | |||||||||||||||||||||||||||||||||||||||||||||
| 861 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # return valid keys | ||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | $val = [ keys %$val ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # return all vals in list ctxt, or just the first in scalar | ||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 203 | ▶ | return wantarray ? @$val : $val->[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||
| 873 | =item $block = $config->block("BlockName") | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||
| 875 | =item $block = $config->block(Directory => "/foo/bar") | ||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||
| 877 | =item $block = $config->block(Directory => "~" => "^.*/bar") | ||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||
| 879 | This method returns a Config::ApacheFormat object used to access the | ||||||||||||||||||||||||||||||||||||||||||||||
| 880 | values inside a block. Parameters specified within the block will be | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | available. Also, if inheritance is turned on (the default), values | ||||||||||||||||||||||||||||||||||||||||||||||
| 882 | set outside the block that are not overwritten inside the block will | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | also be available. For example, given this file: | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||
| 885 | MaxSize 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||
| 887 | <Site "big"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 888 | Size 10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 889 | </Site> | ||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||
| 891 | <Site "small"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 892 | Size 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 893 | </Site> | ||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||
| 895 | this code: | ||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||
| 897 | print "Max: ", $config->get("MaxSize"), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||
| 899 | $block = $config->block(Site => "big"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 900 | print "Big: ", $block->get("Size"), " / ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 901 | $block->get("MaxSize"), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||
| 903 | $block = $config->block(Site => "small"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 904 | print "Small: ", $block->get("Size"), " / ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 905 | $block->get("MaxSize"), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||
| 907 | will print: | ||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||
| 909 | Max: 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| 910 | Big: 10 / 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| 911 | Small: 1 / 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||
| 913 | Note that C<block()> does not require any particular number of | ||||||||||||||||||||||||||||||||||||||||||||||
| 914 | parameters. Any number will work, as long as they uniquely identify a | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | block in the configuration file. To get a list of available blocks, | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | use get() with the name of the block tag. | ||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||
| 918 | This method will die() if no block can be found matching the specifier | ||||||||||||||||||||||||||||||||||||||||||||||
| 919 | passed in. | ||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||
| 921 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||
| 923 | # get object for a given block specifier | ||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 10 | ▶ | sub block { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
block: called CC=12 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | ▶ | my($name, @vals) = ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 10 | ▶ | $name = lc $name unless $self->{case_sensitive}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 10 | my $data = $self->{_data}; | |||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # make sure we have at least one block named $name | ||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 10 | my $block_array; | |||||||||||||||||||||||||||||||||||||||||||||
| 932 | croak("No such block named '$name' in config file") | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 10 | ▶ | unless ($block_array = $data->{$name} and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$block_array = $data->{$name} and ref $block_array eq "ARRAY" and ref $block_array->[0] eq ref $self
$block_array = $data->{$name} and ref $block_array eq "ARRAY"
MC/DC0%0/3
$block_array = $data->{$name} and ref $block_array eq "ARRAY" and ref $block_array->[0] eq ref $self
$block_array = $data->{$name}
ref $block_array eq "ARRAY"
ref $block_array->[0] eq ref $self
Truth table25%1/4
A and B and C
A= $block_array = $data->{$name}B= ref $block_array eq "ARRAY"C= ref $block_array->[0] eq ref $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 934 | ref($block_array) eq 'ARRAY' and | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | ref($block_array->[0]) eq ref($self)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # find a block matching @vals. If Perl supported arbitrary | ||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # structures as hash keys this could be more efficient. | ||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 10 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 940 | BLOCK: | ||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 10 | foreach my $block (@{$block_array}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 942 | 170 | ▶ | if (@vals == @{$block->{_block_vals}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 156 | ▶ | for (local $_ = 0; $_ < @vals; $_++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 289 | ▶ | next BLOCK unless $vals[$_] eq $block->{_block_vals}[$_]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 127 | ▶ | return $block unless wantarray; # saves time | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 118 | push @ret, $block; | |||||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 1 | ▶ | return @ret if @ret; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||
| 952 | # redispatch to get() if just given block type ($config->block('location')) | ||||||||||||||||||||||||||||||||||||||||||||||
| 953 | #return $self->get(@_) unless @vals; | ||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||
| 955 | croak("No such block named '$name' with values ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | join(', ', map { "'$_'" } @vals), " in config file"); | |||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||
| 959 | =item $config->clear() | ||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||
| 961 | Clears out all data in $config. Call before re-calling | ||||||||||||||||||||||||||||||||||||||||||||||
| 962 | $config->read() for a fresh read. | ||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||
| 964 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | delete $self->{_data}; | |||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | $self->{_data} = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||
| 972 | =item $config->dump() | ||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||
| 974 | This returns a dumped copy of the current configuration. It can be | ||||||||||||||||||||||||||||||||||||||||||||||
| 975 | used on a block object as well. Since it returns a string, you should | ||||||||||||||||||||||||||||||||||||||||||||||
| 976 | say: | ||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||
| 978 | print $config->dump; | ||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||
| 980 | Or: | ||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||
| 982 | for ($config->block(VirtualHost => '10.1.65.1')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 983 | print $_->dump; | ||||||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||
| 986 | If you want to see any output. | ||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||
| 988 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | return Data::Dumper::Dumper($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||
| 997 | # handle autoload_support feature | ||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 14 | ▶ | sub DESTROY { 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 4 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 4 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 4 | my ($name) = $AUTOLOAD =~ /([^:]+)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 1004 | croak(qq(Can't locate object method "$name" via package ") . | ||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | ref($self) . '"') | ||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 4 | ▶ | unless $self->{autoload_support}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 4 | return $self->get($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1013 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||