mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 04:31:00 +01:00
1.22: - added a new option to new(): -LowerCaseNames, which
lowercases all option-names (feature request) git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@10 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
51
General.pm
51
General.pm
@@ -6,10 +6,14 @@
|
||||
# given file and return it as hash
|
||||
# structure
|
||||
#
|
||||
# Copyright (c) 2000 Thomas Linden <tom@daemon.de>.
|
||||
# Copyright (c) 2000-2001 Thomas Linden <tom@daemon.de>.
|
||||
# All Rights Reserved. Std. disclaimer applies.
|
||||
# Artificial License, same as perl itself. Have fun.
|
||||
#
|
||||
# Changes from 1.21: - added a new option to new(): -LowerCaseNames, which
|
||||
# lowercases all option-names (feature request)
|
||||
# Changes from 1.20: - lines with just one "#" became an option array named
|
||||
# "#" with empty entries, very weird, fixed
|
||||
# Changes from 1.19: - added an if(exists... to new() for checking of the
|
||||
# existence of -AllowMultiOptions.
|
||||
# - use now "local $_" because it caused weird results
|
||||
@@ -26,7 +30,7 @@ use FileHandle;
|
||||
use strict;
|
||||
use Carp;
|
||||
|
||||
$Config::General::VERSION = "1.20";
|
||||
$Config::General::VERSION = "1.22";
|
||||
|
||||
sub new {
|
||||
#
|
||||
@@ -50,6 +54,11 @@ sub new {
|
||||
$self->{NoMultiOptions} = 1;
|
||||
}
|
||||
}
|
||||
if (exists $conf{-LowerCaseNames}) {
|
||||
if ($conf{-LowerCaseNames}) {
|
||||
$self->{LowerCaseNames} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ($#param == 0) {
|
||||
# use of the old style
|
||||
@@ -210,6 +219,7 @@ sub _parse {
|
||||
if ($blockname) {
|
||||
$block = $grab;
|
||||
}
|
||||
$block = lc($block) if $this->{LowerCaseNames}; # only for blocks lc(), if configured via new()
|
||||
undef @newcontent;
|
||||
next;
|
||||
}
|
||||
@@ -217,6 +227,7 @@ sub _parse {
|
||||
croak "EndBlock \"<\/$1>\" has no StartBlock statement (level: $this->{level}, chunk $chunk)!\n";
|
||||
}
|
||||
else { # insert key/value pair into actual node
|
||||
$option = lc($option) if $this->{LowerCaseNames};
|
||||
if ($this->{NoMultiOptions}) { # configurable via special method ::NoMultiOptions()
|
||||
if (exists $config->{$option}) {
|
||||
croak "Option $config->{$option} occurs more than once (level: $this->{level}, chunk $chunk)!\n";
|
||||
@@ -244,7 +255,7 @@ sub _parse {
|
||||
}
|
||||
elsif (/^<\/(.+?)>$/) {
|
||||
if ($block_level) { # this endblock is not the one we are searching for, decrement and push
|
||||
$block_level--; # if it is 0 the the endblock was the one we searched for, see below
|
||||
$block_level--; # if it is 0, then the endblock was the one we searched for, see below
|
||||
push @newcontent, $_; # push onto new content stack
|
||||
}
|
||||
else { # calling myself recursively, end of $block reached, $block_level is 0
|
||||
@@ -386,8 +397,9 @@ Possible ways to call B<new()>:
|
||||
$conf = new Config::General(\%somehash);
|
||||
|
||||
$conf = new Config::General(
|
||||
-file => "rcfile",
|
||||
-file => "rcfile",
|
||||
-AllowMultiOptions => "no"
|
||||
-LowerCaseNames => "yes"
|
||||
);
|
||||
|
||||
$conf = new Config::General(
|
||||
@@ -410,6 +422,9 @@ still supported. Possible parameters are:
|
||||
-hash - a hash reference.
|
||||
-AllowMultiOptions - if the value is "no", then multiple
|
||||
identical options are disallowed.
|
||||
-LowerCaseNames - if true (1 or "yes") then all options found
|
||||
in the config will be converted to lowercase.
|
||||
This allows you to provide case-in-sensitive configs
|
||||
|
||||
|
||||
=item NoMultiOptions()
|
||||
@@ -542,6 +557,32 @@ The hash which the method B<getall> returns look like that:
|
||||
'user' => 'hans'
|
||||
};
|
||||
|
||||
If you have turned on B<-LowerCaseNames> (see new()) then blocks as in the
|
||||
following example:
|
||||
|
||||
<Dir>
|
||||
<AttriBUTES>
|
||||
Owner root
|
||||
</attributes>
|
||||
</dir>
|
||||
|
||||
would produce the following hash structure:
|
||||
|
||||
$VAR1 = {
|
||||
'dir' => {
|
||||
'attributes' => {
|
||||
'owner => "root",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
As you can see, the keys inside the config hash are normalized.
|
||||
|
||||
Please note, that the above config block would result in a
|
||||
valid hash structure, even if B<-LowerCaseNames> is not set!
|
||||
This is because I<Config::General> does not
|
||||
use the blocknames to check if a block ends, instead it uses an internal
|
||||
state counter, which indicates a block end.
|
||||
|
||||
If the module cannot find an end-block statement, then this block will be ignored.
|
||||
|
||||
@@ -740,7 +781,7 @@ Thomas Linden <tom@daemon.de>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
1.20
|
||||
1.22
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
Reference in New Issue
Block a user