mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
i 2.00 - fixed a bug in the ::Extended::keys() method, which
caused a beloved "use of uninitialized ..." message. Reported by Danial Pearce <danial@infoxchange.net.au>. - Removed all deprecated methods (in fact, they are still there for shouting out a warn that its deprecated. But the pod sections are removed. These are NoMultiOptions() and save(). - added two new parameters to new(): -InterPolateVars and -ExtendedAccess, which allows one to use the functionalites of the supplied submodules without the need to decide for one of them. This makes it possible to use variable interpolation and oop access in the same time. Suggested by Jared Rhine <jared@wordzoo.com>. - added new parameter -BaseHash which makes it possible to supply your own hash which stores the parsed contents of the config. This can be a tied hash o the like. Suggested by Jared Rhine <jared@wordzoo.com> too. - switched to release 2.00 because the above is a major change. git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@26 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
@@ -14,15 +14,17 @@ use Config::General 1.18;
|
||||
|
||||
use FileHandle;
|
||||
use Carp;
|
||||
use vars qw(@ISA);
|
||||
use Exporter ();
|
||||
use vars qw(@ISA @EXPORT);
|
||||
|
||||
# inherit new() and so on from Config::General
|
||||
@ISA = qw(Config::General);
|
||||
@ISA = qw(Config::General Exporter);
|
||||
@EXPORT = qw(obj value hash array is_hash is_array is_scalar exists keys delete configfile);
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
$Config::General::Extended::VERSION = "1.5";
|
||||
$Config::General::Extended::VERSION = "1.6";
|
||||
|
||||
|
||||
sub obj {
|
||||
@@ -154,12 +156,12 @@ sub keys {
|
||||
# it contains keys (so it must be a hash!)
|
||||
#
|
||||
my($this, $key) = @_;
|
||||
if (exists $this->{config}->{$key} && ref($this->{config}->{$key}) eq "HASH") {
|
||||
return map { $_ } keys %{$this->{config}->{$key}};
|
||||
}
|
||||
elsif (!$key) {
|
||||
if (!$key) {
|
||||
return map { $_ } keys %{$this->{config}};
|
||||
}
|
||||
elsif (exists $this->{config}->{$key} && ref($this->{config}->{$key}) eq "HASH") {
|
||||
return map { $_ } keys %{$this->{config}->{$key}};
|
||||
}
|
||||
else {
|
||||
return ();
|
||||
}
|
||||
@@ -181,19 +183,21 @@ sub delete {
|
||||
}
|
||||
|
||||
|
||||
sub save {
|
||||
#
|
||||
# save the config back to disk
|
||||
#
|
||||
my($this,$file) = @_;
|
||||
my $fh = new FileHandle;
|
||||
|
||||
if (!$file) {
|
||||
$file = $this->{configfile};
|
||||
}
|
||||
|
||||
$this->save_file($file);
|
||||
}
|
||||
#
|
||||
# removed, use save() of General.pm now
|
||||
# sub save {
|
||||
# #
|
||||
# # save the config back to disk
|
||||
# #
|
||||
# my($this,$file) = @_;
|
||||
# my $fh = new FileHandle;
|
||||
#
|
||||
# if (!$file) {
|
||||
# $file = $this->{configfile};
|
||||
# }
|
||||
#
|
||||
# $this->save_file($file);
|
||||
# }
|
||||
|
||||
|
||||
sub configfile {
|
||||
@@ -253,63 +257,27 @@ sub DESTROY {
|
||||
|
||||
Config::General::Extended - Extended access to Config files
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Config::General::Extended;
|
||||
$conf = new Config::General::Extended("rcfile");
|
||||
# or
|
||||
$conf = new Config::General::Extended(\%somehash);
|
||||
use Config::General;
|
||||
|
||||
$conf = new Config::General(
|
||||
-file => 'configfile',
|
||||
-ExtendedAccess => 1
|
||||
);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module is a subclass of B<Config::General>. You can use it if
|
||||
you want OO access to parts of your config file. The following methods
|
||||
are directly inherited from Config::General: B<new() getall()>.
|
||||
This is an internal module which makes it possible to use object
|
||||
oriented methods to access parts of your config file.
|
||||
|
||||
Please refer to the L<Config::General>, if you want to learn about the usage
|
||||
of the two methods mentioned above. The possible format of config files supported
|
||||
by this module is also well described in L<Config::General>.
|
||||
Normally you don't call it directly.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=over
|
||||
|
||||
=item new(filename) or new(\%somehash)
|
||||
|
||||
This method returns a B<Config::General> object (a hash blessed into "Config::General::Extended"
|
||||
namespace. All further methods must be used from that returned object. see below.
|
||||
|
||||
Read a more detailed discussion on how to use the new() method in L<Config::General>.
|
||||
|
||||
|
||||
=item NoMultiOptions()
|
||||
|
||||
This method only exists for compatibility reasons.
|
||||
Now you should set the new() flag B<-AllowMultiOptions>
|
||||
to "no".
|
||||
|
||||
Refer to L<Config::General> for details about this method.
|
||||
|
||||
=item getall()
|
||||
|
||||
Returns a hash structure which represents the whole config.
|
||||
|
||||
If you use this method, then it would be probably
|
||||
better to use the simpler module B<Config::General>. It is just mentioned here
|
||||
for completeness.
|
||||
|
||||
|
||||
=item save()
|
||||
|
||||
|
||||
Writes the current config hash back to the harddisk.
|
||||
It takes an optional argument: B<filename>. If you omit a filename, save() will
|
||||
use the filename configured by the method B<configfile()> or B<new()> (see below).
|
||||
|
||||
B<Important>: the method save() is now superseded by B<save_file()> and B<save_string()>.
|
||||
Refer to L<Config::General> for details. You can use these new methods to save
|
||||
a config either to a string or to a file.
|
||||
|
||||
=item configfile('filename')
|
||||
|
||||
Set the filename to be used by B<save> to "filename". It returns the current
|
||||
@@ -522,7 +490,7 @@ Thomas Linden <tom@daemon.de>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
1.5
|
||||
1.6
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
Reference in New Issue
Block a user