mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 12:41:07 +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
|
2.06 - added -SplitPolicy, -SplitDelimiter and -StoreDelimiter
|
||||||
- removed whitespace support in keys in the default parser
|
- removed whitespace support in keys in the default parser
|
||||||
SplitPolicy 'guess', which was introduced in 2.02. Now
|
SplitPolicy 'guess', which was introduced in 2.02. Now
|
||||||
|
|||||||
26
General.pm
26
General.pm
@@ -17,7 +17,7 @@ use strict;
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
$Config::General::VERSION = "2.06";
|
$Config::General::VERSION = "2.07";
|
||||||
|
|
||||||
use vars qw(@ISA @EXPORT);
|
use vars qw(@ISA @EXPORT);
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
@@ -67,6 +67,8 @@ sub new {
|
|||||||
|
|
||||||
CComments => 1, # by default turned on
|
CComments => 1, # by default turned on
|
||||||
|
|
||||||
|
StrictObjects => 1, # be strict on non-existent keys in OOP mode
|
||||||
|
|
||||||
parsed => 0
|
parsed => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,6 +190,7 @@ sub new {
|
|||||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ($configfile) {
|
||||||
# open the file and read the contents in
|
# open the file and read the contents in
|
||||||
$self->{configfile} = $configfile;
|
$self->{configfile} = $configfile;
|
||||||
# look if is is an absolute path and save the basename if it is absolute
|
# look if is is an absolute path and save the basename if it is absolute
|
||||||
@@ -196,6 +199,12 @@ sub new {
|
|||||||
# now, we parse immdediately, getall simply returns the whole hash
|
# now, we parse immdediately, getall simply returns the whole hash
|
||||||
$self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content});
|
$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});
|
$config_string = $this->_store(0,%{$config});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($config_string) {
|
||||||
print $fh $config_string;
|
print $fh $config_string;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# empty config for whatever reason, I don't care
|
||||||
|
print $fh "";
|
||||||
|
}
|
||||||
|
|
||||||
close $fh;
|
close $fh;
|
||||||
}
|
}
|
||||||
@@ -805,7 +820,7 @@ sub SaveConfig {
|
|||||||
croak "The second parameter must be a reference to a hash!";
|
croak "The second parameter must be a reference to a hash!";
|
||||||
}
|
}
|
||||||
else {
|
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
|
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.
|
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>
|
=item B<-SplitPolicy>
|
||||||
|
|
||||||
@@ -1671,7 +1691,7 @@ Thomas Linden <tom@daemon.de>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
2.06
|
2.07
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
@@ -242,8 +242,14 @@ sub AUTOLOAD {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ($this->{StrictObjects}) {
|
||||||
croak "\"$key\" does not exist within current object\n";
|
croak "\"$key\" does not exist within current object\n";
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
# be cool
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
@@ -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
|
<person> does not contain any subblock or multiple identical options(which will become
|
||||||
an array after parsing)!
|
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:
|
Of course you can use this kind of methods for writing data too:
|
||||||
|
|
||||||
$person->name("Neustein");
|
$person->name("Neustein");
|
||||||
|
|||||||
Reference in New Issue
Block a user