mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 04:31:00 +01:00
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:
28
Changelog
28
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 <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
|
2.07 - fixed cpan bugid #1351, SaveConfig contained a deprecated
|
||||||
function call which caused the module to croak.
|
function call which caused the module to croak.
|
||||||
- added feature request, if in extended mode (OOP turned
|
- added feature request, if in extended mode (OOP turned
|
||||||
|
|||||||
54
General.pm
54
General.pm
@@ -17,7 +17,7 @@ use strict;
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
$Config::General::VERSION = "2.07";
|
$Config::General::VERSION = "2.08";
|
||||||
|
|
||||||
use vars qw(@ISA @EXPORT);
|
use vars qw(@ISA @EXPORT);
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
@@ -69,6 +69,8 @@ sub new {
|
|||||||
|
|
||||||
StrictObjects => 1, # be strict on non-existent keys in OOP mode
|
StrictObjects => 1, # be strict on non-existent keys in OOP mode
|
||||||
|
|
||||||
|
StrictVars => 1, # be strict on undefined variables in Interpolate mode
|
||||||
|
|
||||||
parsed => 0
|
parsed => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,8 +137,10 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($self->{MergeDuplicateOptions}) {
|
if ($self->{MergeDuplicateOptions}) {
|
||||||
# override
|
# override if not set by user
|
||||||
$self->{AllowMultiOptions} = 0;
|
if (! exists $conf{-AllowMultiOptions}) {
|
||||||
|
$self->{AllowMultiOptions} = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($#param == 0) {
|
elsif ($#param == 0) {
|
||||||
@@ -357,7 +361,7 @@ sub _read {
|
|||||||
else {
|
else {
|
||||||
# look for include statement(s)
|
# look for include statement(s)
|
||||||
my $incl_file;
|
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;
|
$incl_file = $1;
|
||||||
if ($this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\//) {
|
if ($this->{IncludeRelative} && $this->{configpath} && $incl_file !~ /^\//) {
|
||||||
# include the file from within location of $this->{configfile}
|
# include the file from within location of $this->{configfile}
|
||||||
@@ -381,7 +385,6 @@ sub _read {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub _parse {
|
sub _parse {
|
||||||
#
|
#
|
||||||
# parse the contents of the file
|
# parse the contents of the file
|
||||||
@@ -487,14 +490,14 @@ sub _parse {
|
|||||||
else { # calling myself recursively, end of $block reached, $block_level is 0
|
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 ($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 (exists $config->{$block}->{$blockname}) { # the named block already exists, make it an array
|
||||||
if (! $this->{AllowMultiOptions}) {
|
if ($this->{MergeDuplicateBlocks}) {
|
||||||
croak "Named block \"<$block $blockname>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n";
|
# 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 {
|
else {
|
||||||
if ($this->{MergeDuplicateBlocks}) {
|
if (! $this->{AllowMultiOptions}) {
|
||||||
# just merge the new block with the same name as an existing one into
|
croak "Named block \"<$block $blockname>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n";
|
||||||
# this one.
|
|
||||||
$config->{$block}->{$blockname} = $this->_parse($config->{$block}->{$blockname}, \@newcontent);
|
|
||||||
}
|
}
|
||||||
else { # preserve existing data
|
else { # preserve existing data
|
||||||
my $savevalue = $config->{$block}->{$blockname};
|
my $savevalue = $config->{$block}->{$blockname};
|
||||||
@@ -517,14 +520,14 @@ sub _parse {
|
|||||||
}
|
}
|
||||||
else { # standard block
|
else { # standard block
|
||||||
if (exists $config->{$block}) { # the block already exists, make it an array
|
if (exists $config->{$block}) { # the block already exists, make it an array
|
||||||
if (! $this->{AllowMultiOptions}) {
|
if ($this->{MergeDuplicateBlocks}) {
|
||||||
croak "Block \"<$block>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n";
|
# just merge the new block with the same name as an existing one into
|
||||||
}
|
# this one.
|
||||||
else {
|
$config->{$block} = $this->_parse($config->{$block}, \@newcontent);
|
||||||
if ($this->{MergeDuplicateBlocks}) {
|
}
|
||||||
# just merge the new block with the same name as an existing one into
|
else {
|
||||||
# this one.
|
if (! $this->{AllowMultiOptions}) {
|
||||||
$config->{$block} = $this->_parse($config->{$block}, \@newcontent);
|
croak "Block \"<$block>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $savevalue = $config->{$block};
|
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
|
same option occurs more than once, the last one will be used in the resulting
|
||||||
config hash.
|
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>
|
=item B<-AutoTrue>
|
||||||
@@ -1449,12 +1454,13 @@ this:
|
|||||||
|
|
||||||
As you can see, there is only one hash "dir->{blah}" containing multiple
|
As you can see, there is only one hash "dir->{blah}" containing multiple
|
||||||
"user" entries. As you can also see, turning on B<-MergeDuplicateBlocks>
|
"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
|
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
|
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
|
=head1 VERSION
|
||||||
|
|
||||||
2.07
|
2.08
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package Config::General::Interpolated;
|
package Config::General::Interpolated;
|
||||||
$Config::General::Interpolated::VERSION = "1.4";
|
$Config::General::Interpolated::VERSION = "1.5";
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Carp;
|
use Carp;
|
||||||
@@ -77,7 +77,13 @@ sub _vars {
|
|||||||
$con . $v;
|
$con . $v;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
croak "Use of uninitialized variable \$" . $var . "\n";
|
if ($this->{StrictVars}) {
|
||||||
|
croak "Use of uninitialized variable \$" . $var . "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# be cool
|
||||||
|
$con;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}egx;
|
}egx;
|
||||||
}
|
}
|
||||||
@@ -216,7 +222,7 @@ See L<http://www.perl.com/perl/misc/Artistic.html>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
1.4
|
1.5
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
7
README
7
README
@@ -88,6 +88,11 @@ COPYRIGHT
|
|||||||
This library is free software; you can redistribute it
|
This library is free software; you can redistribute it
|
||||||
and/or modify it under the same terms as Perl itself.
|
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
|
BUGS
|
||||||
make test does currently not catch all possible scenarios.
|
make test does currently not catch all possible scenarios.
|
||||||
@@ -98,4 +103,4 @@ AUTHOR
|
|||||||
|
|
||||||
|
|
||||||
VERSION
|
VERSION
|
||||||
2.07
|
2.08
|
||||||
Reference in New Issue
Block a user