mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
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
on with -ExtendedAccess => 1 access to non-existent keys
caused a croak. While this is still the default behavior
it is now possible to turn this off using -StrictObjects => 0.
- added this to the related pod section in ::Extended.
- fixed bug in new() which caused a couple of errors
if the ConfigFile parameter is not set, or is set to
undef. In this case it will now simply create an empty
object.
- fixed related bug in save_file() which will save "" to
a file now if the config is uninitialized (i.e. the case
mentioned below arrived).
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@33 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
15
Changelog
15
Changelog
@@ -1,3 +1,18 @@
|
||||
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
|
||||
on with -ExtendedAccess => 1 access to non-existent keys
|
||||
caused a croak. While this is still the default behavior
|
||||
it is now possible to turn this off using -StrictObjects => 0.
|
||||
- added this to the related pod section in ::Extended.
|
||||
- fixed bug in new() which caused a couple of errors
|
||||
if the ConfigFile parameter is not set, or is set to
|
||||
undef. In this case it will now simply create an empty
|
||||
object.
|
||||
- fixed related bug in save_file() which will save "" to
|
||||
a file now if the config is uninitialized (i.e. the case
|
||||
mentioned below arrived).
|
||||
|
||||
2.06 - added -SplitPolicy, -SplitDelimiter and -StoreDelimiter
|
||||
- removed whitespace support in keys in the default parser
|
||||
SplitPolicy 'guess', which was introduced in 2.02. Now
|
||||
|
||||
42
General.pm
42
General.pm
@@ -17,7 +17,7 @@ use strict;
|
||||
use Carp;
|
||||
use Exporter;
|
||||
|
||||
$Config::General::VERSION = "2.06";
|
||||
$Config::General::VERSION = "2.07";
|
||||
|
||||
use vars qw(@ISA @EXPORT);
|
||||
@ISA = qw(Exporter);
|
||||
@@ -67,6 +67,8 @@ sub new {
|
||||
|
||||
CComments => 1, # by default turned on
|
||||
|
||||
StrictObjects => 1, # be strict on non-existent keys in OOP mode
|
||||
|
||||
parsed => 0
|
||||
};
|
||||
|
||||
@@ -188,13 +190,20 @@ sub new {
|
||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
||||
}
|
||||
else {
|
||||
# open the file and read the contents in
|
||||
$self->{configfile} = $configfile;
|
||||
# look if is is an absolute path and save the basename if it is absolute
|
||||
($self->{configpath}) = $configfile =~ /^(\/.*)\//;
|
||||
$self->_open($self->{configfile});
|
||||
# now, we parse immdediately, getall simply returns the whole hash
|
||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
||||
if ($configfile) {
|
||||
# open the file and read the contents in
|
||||
$self->{configfile} = $configfile;
|
||||
# look if is is an absolute path and save the basename if it is absolute
|
||||
($self->{configpath}) = $configfile =~ /^(\/.*)\//;
|
||||
$self->_open($self->{configfile});
|
||||
# now, we parse immdediately, getall simply returns the whole hash
|
||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
||||
}
|
||||
else {
|
||||
# hm, no valid config file given, so try it as an empty object
|
||||
$self->{config} = {};
|
||||
$self->{parsed} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +669,13 @@ sub save_file {
|
||||
$config_string = $this->_store(0,%{$config});
|
||||
}
|
||||
|
||||
print $fh $config_string;
|
||||
if ($config_string) {
|
||||
print $fh $config_string;
|
||||
}
|
||||
else {
|
||||
# empty config for whatever reason, I don't care
|
||||
print $fh "";
|
||||
}
|
||||
|
||||
close $fh;
|
||||
}
|
||||
@@ -805,7 +820,7 @@ sub SaveConfig {
|
||||
croak "The second parameter must be a reference to a hash!";
|
||||
}
|
||||
else {
|
||||
(new Config::General($hash))->save($file);
|
||||
(new Config::General($hash))->save_file($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1100,6 +1115,11 @@ input. See L<Config::General::Interpolated> for more informations.
|
||||
If set to a true value, you can use object oriented (extended) methods to
|
||||
access the parsed config. See L<Config::General::Extended> for more informations.
|
||||
|
||||
=item B<-StrictObjects>
|
||||
|
||||
By default this is turned on, which causes Config::General to croak with an
|
||||
error if you try to access a non-existent key using the oop-way. If you turn
|
||||
B<-StrictObjects> off (by setting to 0 or "no") it will just return undef.
|
||||
|
||||
=item B<-SplitPolicy>
|
||||
|
||||
@@ -1671,7 +1691,7 @@ Thomas Linden <tom@daemon.de>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
2.06
|
||||
2.07
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
@@ -242,7 +242,13 @@ sub AUTOLOAD {
|
||||
}
|
||||
}
|
||||
else {
|
||||
croak "\"$key\" does not exist within current object\n";
|
||||
if ($this->{StrictObjects}) {
|
||||
croak "\"$key\" does not exist within current object\n";
|
||||
}
|
||||
else {
|
||||
# be cool
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,6 +472,10 @@ This notation supports only scalar values! You need to make sure, that the block
|
||||
<person> does not contain any subblock or multiple identical options(which will become
|
||||
an array after parsing)!
|
||||
|
||||
If you access a non-existent key this way, Config::General will croak an error.
|
||||
You can turn this behavior off by setting B<-StrictObjects> to 0 or "no". In
|
||||
this case undef will be returned.
|
||||
|
||||
Of course you can use this kind of methods for writing data too:
|
||||
|
||||
$person->name("Neustein");
|
||||
|
||||
Reference in New Issue
Block a user