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

@@ -22,7 +22,7 @@ use vars qw(@ISA);
use strict;
$Config::General::Extended::VERSION = "1.3";
$Config::General::Extended::VERSION = "1.4";
sub obj {
@@ -126,7 +126,7 @@ sub is_scalar {
# returns true if the given key contains a scalar(or number)
#
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;
@@ -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 {
#
# 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() ).
=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
@@ -494,7 +517,7 @@ Thomas Linden <tom@daemon.de>
=head1 VERSION
1.3
1.4
=cut