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 <sm@open.ch>, 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 <matthias@izb.net>, 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...


git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@34 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2009-10-10 16:24:01 +00:00
parent 41b311f7a0
commit e3ca417573
4 changed files with 73 additions and 28 deletions

View File

@@ -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 <sm@open.ch>, 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 <matthias@izb.net>, 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

View File

@@ -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*<<include (.+?)>>\s*$/i || (/^\s*include (.+?)\s*$/i && $this->{UseApacheInclude})) {
if (/^\s*<<include\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<AllowMutliOptions> in the B<new()> method to "no".
by setting the flag I<AllowMultiOptions> in the B<new()> 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 <tom@daemon.de>
=head1 VERSION
2.07
2.08
=cut

View File

@@ -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<http://www.perl.com/perl/misc/Artistic.html>
=head1 VERSION
1.4
1.5
=cut

7
README
View File

@@ -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
2.08