mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 20:51:00 +01:00
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:
23
Changelog
23
Changelog
@@ -1,4 +1,25 @@
|
|||||||
1.32 - fixed bug in _parse_value() which caused perl to complain
|
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.
|
||||||
|
|
||||||
|
1.33 - fixed bug in _parse_value() which caused perl to complain
|
||||||
with "Use of uninitialized value in..." if a value was
|
with "Use of uninitialized value in..." if a value was
|
||||||
empty.
|
empty.
|
||||||
|
|
||||||
|
|||||||
89
General.pm
89
General.pm
@@ -583,39 +583,19 @@ sub _store {
|
|||||||
foreach my $entry (sort keys %config) {
|
foreach my $entry (sort keys %config) {
|
||||||
if (ref($config{$entry}) eq "ARRAY") {
|
if (ref($config{$entry}) eq "ARRAY") {
|
||||||
foreach my $line (@{$config{$entry}}) {
|
foreach my $line (@{$config{$entry}}) {
|
||||||
# patch submitted by Peder Stray <peder@linpro.no> to catch
|
if (ref($line) eq "HASH") {
|
||||||
# arrays of hashes.
|
$config_string .= $this->_write_hash($level, $entry, $line);
|
||||||
if (ref($line) eq "HASH") {
|
}
|
||||||
$config_string .= $indent . "<" . $entry . ">\n";
|
else {
|
||||||
$config_string .= $this->_store($level + 1, %{$line});
|
$config_string .= $this->_write_scalar($level, $entry, $line);
|
||||||
$config_string .= $indent . "</" . $entry . ">\n";
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
$line =~ s/#/\\#/g;
|
|
||||||
$config_string .= $indent . $entry . " " . $line . "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif (ref($config{$entry}) eq "HASH") {
|
elsif (ref($config{$entry}) eq "HASH") {
|
||||||
$config_string .= $indent . "<" . $entry . ">\n";
|
$config_string .= $this->_write_hash($level, $entry, $config{$entry});
|
||||||
$config_string .= $this->_store($level + 1, %{$config{$entry}});
|
|
||||||
$config_string .= $indent . "</" . $entry . ">\n";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# scalar
|
$config_string .= $this->_write_scalar($level, $entry, $config{$entry});
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
# 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
|
This method allows the user (or, the "maintainer" of the configfile for your
|
||||||
application) to set multiple pre-defined values for one option.
|
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.
|
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.
|
also parsed this way.
|
||||||
|
|
||||||
Values which are not defined in the hash-ref supplied to the parameter B<-FlagBits>
|
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
|
=head1 VERSION
|
||||||
|
|
||||||
1.33
|
1.34
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use vars qw(@ISA);
|
|||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
|
||||||
$Config::General::Extended::VERSION = "1.3";
|
$Config::General::Extended::VERSION = "1.4";
|
||||||
|
|
||||||
|
|
||||||
sub obj {
|
sub obj {
|
||||||
@@ -126,7 +126,7 @@ sub is_scalar {
|
|||||||
# returns true if the given key contains a scalar(or number)
|
# returns true if the given key contains a scalar(or number)
|
||||||
#
|
#
|
||||||
my($this, $key) = @_;
|
my($this, $key) = @_;
|
||||||
if (exists $this->{config}->{$key} && !ref(exists $this->{config}->{$key})) {
|
if (exists $this->{config}->{$key} && !ref($this->{config}->{$key})) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -162,6 +162,22 @@ sub keys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub delete {
|
||||||
|
#
|
||||||
|
# delete the given key from the config, if any
|
||||||
|
# and return what is deleted (just as 'delete $hash{key}' does)
|
||||||
|
#
|
||||||
|
my($this, $key) = @_;
|
||||||
|
if (exists $this->{config}->{$key}) {
|
||||||
|
return delete $this->{config}->{$key};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub save {
|
sub save {
|
||||||
#
|
#
|
||||||
# save the config back to disk
|
# save the config back to disk
|
||||||
@@ -437,6 +453,13 @@ config above you yould do that:
|
|||||||
|
|
||||||
You can use this method in B<foreach> loops as seen in an example above(obj() ).
|
You can use this method in B<foreach> loops as seen in an example above(obj() ).
|
||||||
|
|
||||||
|
|
||||||
|
=item delete ('key')
|
||||||
|
|
||||||
|
This method removes the given key and all associated data from the internal
|
||||||
|
hash structure. If 'key' contained data, then this data will be returned,
|
||||||
|
otherwise undef will be returned.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
||||||
@@ -494,7 +517,7 @@ Thomas Linden <tom@daemon.de>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
1.3
|
1.4
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
12
README
12
README
@@ -37,6 +37,7 @@ INSTALLATION
|
|||||||
to read the complete documentation, type:
|
to read the complete documentation, type:
|
||||||
perldoc Config::General
|
perldoc Config::General
|
||||||
perldoc Config::General::Extended
|
perldoc Config::General::Extended
|
||||||
|
perldoc Config::General::Interpolated
|
||||||
|
|
||||||
see some example config files which can
|
see some example config files which can
|
||||||
be parsed with Config::Genreal in the subdirectory
|
be parsed with Config::Genreal in the subdirectory
|
||||||
@@ -44,14 +45,19 @@ INSTALLATION
|
|||||||
|
|
||||||
|
|
||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
Copyright (c) 2000-2002 Thomas Linden
|
Config::General
|
||||||
|
Config::General::Extended
|
||||||
|
Copyright (c) 2000-2002 Thomas Linden <tom@daemon.de>
|
||||||
|
|
||||||
|
Config::General::Interpolated
|
||||||
|
Copyright (c) 2001 Wei-Hon Chen <plasmaball@pchome.com.tw>
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
none known yet.
|
make test does currently not catch all possible scenarios.
|
||||||
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
@@ -59,4 +65,4 @@ AUTHOR
|
|||||||
|
|
||||||
|
|
||||||
VERSION
|
VERSION
|
||||||
1.33
|
1.34
|
||||||
|
|||||||
Reference in New Issue
Block a user