diff --git a/Changelog b/Changelog index 95a1fec..bee4163 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,31 @@ + 2.08 - added option -StrictVars, which causes Interpolate.pm to + ignore undefined variables and replaces such occurences + with the emppty string. + + - applied patch by Stefan Moser , which fixes + some weird bevavior if -MergeDuplicateOptions was turned + on, the parser croaked regardless -MergeDuplicateBlocks + was set or not. Now the two options behave almost independent + from each other, which allows one to merge duplicate + blocks but duplicate options not. + + - changed behavior of setting -MergeDuplicateOptions which + implied in previous versions -AllowMultiOptions to be + false. Now this will only be done if the user does not + set -AllowMultiOptions by himself. This allows one to + have duplicate blocks which will be turned into an + array but duplicate options to be merged. + + - applied patch by Matthias Pitzl , which + fixes a bug at parsing apache-like include directive + (Include ...). It did not properly trim unnecessary whitespaces + so that the filename to be included became invalid. This + bug espessially occurred if one saved a hash containing + a key/value pair like this: "Include" => "/etc/grs.cfg", + which was then saved as "Include /etc/grs.cfg", the + parser returned " /etc/grs.cfg" which, of course, does + not exists. odd... + 2.07 - fixed cpan bugid #1351, SaveConfig contained a deprecated function call which caused the module to croak. - added feature request, if in extended mode (OOP turned diff --git a/General.pm b/General.pm index 5493b07..eee6323 100644 --- a/General.pm +++ b/General.pm @@ -17,7 +17,7 @@ use strict; use Carp; use Exporter; -$Config::General::VERSION = "2.07"; +$Config::General::VERSION = "2.08"; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @@ -69,6 +69,8 @@ sub new { StrictObjects => 1, # be strict on non-existent keys in OOP mode + StrictVars => 1, # be strict on undefined variables in Interpolate mode + parsed => 0 }; @@ -135,8 +137,10 @@ sub new { } if ($self->{MergeDuplicateOptions}) { - # override - $self->{AllowMultiOptions} = 0; + # override if not set by user + if (! exists $conf{-AllowMultiOptions}) { + $self->{AllowMultiOptions} = 0; + } } } elsif ($#param == 0) { @@ -357,7 +361,7 @@ sub _read { else { # look for include statement(s) my $incl_file; - if (/^\s*<>\s*$/i || (/^\s*include (.+?)\s*$/i && $this->{UseApacheInclude})) { + if (/^\s*<>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) { $incl_file = $1; if ($this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\//) { # include the file from within location of $this->{configfile} @@ -381,7 +385,6 @@ sub _read { - sub _parse { # # parse the contents of the file @@ -487,14 +490,14 @@ sub _parse { else { # calling myself recursively, end of $block reached, $block_level is 0 if ($blockname) { # a named block, make it a hashref inside a hash within the current node if (exists $config->{$block}->{$blockname}) { # the named block already exists, make it an array - if (! $this->{AllowMultiOptions}) { - croak "Named block \"<$block $blockname>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; + if ($this->{MergeDuplicateBlocks}) { + # just merge the new block with the same name as an existing one into + # this one. + $config->{$block}->{$blockname} = $this->_parse($config->{$block}->{$blockname}, \@newcontent); } else { - if ($this->{MergeDuplicateBlocks}) { - # just merge the new block with the same name as an existing one into - # this one. - $config->{$block}->{$blockname} = $this->_parse($config->{$block}->{$blockname}, \@newcontent); + if (! $this->{AllowMultiOptions}) { + croak "Named block \"<$block $blockname>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; } else { # preserve existing data my $savevalue = $config->{$block}->{$blockname}; @@ -517,14 +520,14 @@ sub _parse { } else { # standard block if (exists $config->{$block}) { # the block already exists, make it an array - if (! $this->{AllowMultiOptions}) { - croak "Block \"<$block>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; - } - else { - if ($this->{MergeDuplicateBlocks}) { - # just merge the new block with the same name as an existing one into - # this one. - $config->{$block} = $this->_parse($config->{$block}, \@newcontent); + if ($this->{MergeDuplicateBlocks}) { + # just merge the new block with the same name as an existing one into + # this one. + $config->{$block} = $this->_parse($config->{$block}, \@newcontent); + } + else { + if (! $this->{AllowMultiOptions}) { + croak "Block \"<$block>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; } else { my $savevalue = $config->{$block}; @@ -996,7 +999,9 @@ If set to a true value, then duplicate options will be merged. That means, if th same option occurs more than once, the last one will be used in the resulting config hash. -Setting this option implies B<-AllowMultiOptions == false>. +Setting this option implies B<-AllowMultiOptions == false> unless you set +B<-AllowMultiOptions> explicit to 'true'. In this case duplicate blocks are +allowed and put into an array but dupclicate options will be merged. =item B<-AutoTrue> @@ -1449,12 +1454,13 @@ this: As you can see, there is only one hash "dir->{blah}" containing multiple "user" entries. As you can also see, turning on B<-MergeDuplicateBlocks> -does not affect scalar options (i.e. "option = value"). +does not affect scalar options (i.e. "option = value"). In fact you can +tune merging of duplicate blocks and options independent from each other. If you don't want to allow more than one identical options, you may turn it off -by setting the flag I in the B method to "no". +by setting the flag I in the B method to "no". If turned off, Config::General will complain about multiple occuring options -whit identical names! +with identical names! @@ -1691,7 +1697,7 @@ Thomas Linden =head1 VERSION -2.07 +2.08 =cut diff --git a/General/Interpolated.pm b/General/Interpolated.pm index 34e4ff2..63450c4 100644 --- a/General/Interpolated.pm +++ b/General/Interpolated.pm @@ -1,5 +1,5 @@ package Config::General::Interpolated; -$Config::General::Interpolated::VERSION = "1.4"; +$Config::General::Interpolated::VERSION = "1.5"; use strict; use Carp; @@ -77,7 +77,13 @@ sub _vars { $con . $v; } else { - croak "Use of uninitialized variable \$" . $var . "\n"; + if ($this->{StrictVars}) { + croak "Use of uninitialized variable \$" . $var . "\n"; + } + else { + # be cool + $con; + } } }egx; } @@ -216,7 +222,7 @@ See L =head1 VERSION -1.4 +1.5 =cut diff --git a/README b/README index f626acd..9d27cee 100644 --- a/README +++ b/README @@ -88,6 +88,11 @@ COPYRIGHT This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. +HOMEPAGE + + The homepage of Config::General is located at: + + http://www.daemon.de/config-general/ BUGS make test does currently not catch all possible scenarios. @@ -98,4 +103,4 @@ AUTHOR VERSION - 2.07 \ No newline at end of file + 2.08 \ No newline at end of file