1.34 - Danial Pearce <danial@infoxchange.net.au> reported a bug

in _store(), which caused the module to create scalar
	   entries even if the entry contained newlines. While
	   Danial supplied a patch to fix this - thx(TM) - I
	   did not apply it, because I "outsourced" this kind of
	   stuff to the subroutine _write_scalar(), see next.

         - added internal methods _write_scalar() and _write_hash()
	   to simplify _store(), which did the same thing more
	   than once, which is a good time to create a sub which
	   does the job.

         - fixed cut'n paste bug in General/Extended.pm reported by
	   Danial Pearce <danial@infoxchange.net.au>, which caused
	   Config::General::Extended::is_scalar() to return true even
	   when the key you pass in is an array.

         - added new method Config::General::Extended::delete() suggested
	   by Danial Pearce <danial@infoxchange.net.au>, which deletes
	   the given key from the config.


git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@23 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2009-10-10 16:18:02 +00:00
parent 0073500add
commit 31144f9e4f
4 changed files with 115 additions and 38 deletions

View File

@@ -583,39 +583,19 @@ sub _store {
foreach my $entry (sort keys %config) {
if (ref($config{$entry}) eq "ARRAY") {
foreach my $line (@{$config{$entry}}) {
# patch submitted by Peder Stray <peder@linpro.no> to catch
# arrays of hashes.
if (ref($line) eq "HASH") {
$config_string .= $indent . "<" . $entry . ">\n";
$config_string .= $this->_store($level + 1, %{$line});
$config_string .= $indent . "</" . $entry . ">\n";
}
else {
$line =~ s/#/\\#/g;
$config_string .= $indent . $entry . " " . $line . "\n";
}
if (ref($line) eq "HASH") {
$config_string .= $this->_write_hash($level, $entry, $line);
}
else {
$config_string .= $this->_write_scalar($level, $entry, $line);
}
}
}
elsif (ref($config{$entry}) eq "HASH") {
$config_string .= $indent . "<" . $entry . ">\n";
$config_string .= $this->_store($level + 1, %{$config{$entry}});
$config_string .= $indent . "</" . $entry . ">\n";
$config_string .= $this->_write_hash($level, $entry, $config{$entry});
}
else {
# scalar
if ($config{$entry} =~ /\n/) {
# it is a here doc
my @lines = split /\n/, $config{$entry};
$config_string .= $indent . $entry . " <<EOF\n";
foreach my $line(@lines) {
$config_string .= $indent . $line . "\n";
}
$config_string .= $indent . "EOF\n";
}
else {
$config{$entry} =~ s/#/\\#/g;
$config_string .= $indent . $entry . " " . $config{$entry} . "\n";
}
$config_string .= $this->_write_scalar($level, $entry, $config{$entry});
}
}
@@ -623,6 +603,53 @@ sub _store {
}
sub _write_scalar {
#
# internal sub, which writes a scalar
# it returns it, in fact
#
my($this, $level, $entry, $line) = @_;
my $indent = " " x $level;
my $config_string;
if ($line =~ /\n/) {
# it is a here doc
my @lines = split /\n/, $line;
$config_string .= $indent . $entry . " <<EOF\n";
foreach (@lines) {
$config_string .= $indent . $_ . "\n";
}
$config_string .= $indent . "EOF\n";
}
else {
# a simple stupid scalar entry
$line =~ s/#/\\#/g;
$config_string .= $indent . $entry . " " . $line . "\n";
}
return $config_string;
}
sub _write_hash {
#
# internal sub, which writes a hash (block)
# it returns it, in fact
#
my($this, $level, $entry, $line) = @_;
my $indent = " " x $level;
my $config_string;
$config_string .= $indent . "<" . $entry . ">\n";
$config_string .= $this->_store($level + 1, %{$line});
$config_string .= $indent . "</" . $entry . ">\n";
return $config_string
}
#
# Procedural interface
@@ -881,9 +908,9 @@ The resulting config structure would look like this after parsing:
This method allows the user (or, the "maintainer" of the configfile for your
application) to set multiple pre-defined values for one option.
Please beware, that all occurences of thos variables will be handled this
Please beware, that all occurencies of those variables will be handled this
way, there is no way to distinguish between variables in different scopes.
That means, that if "Mode" would also occur inside a named block, it would
That means, if "Mode" would also occur inside a named block, it would
also parsed this way.
Values which are not defined in the hash-ref supplied to the parameter B<-FlagBits>
@@ -1440,7 +1467,7 @@ Thomas Linden <tom@daemon.de>
=head1 VERSION
1.33
1.34
=cut