mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
1.32 - *argl* ... I forgot Interpolated.pm, don't know how that
could happen, in 1.29 it was "lost". However - I added it again now. - added patch by Peder Stray <peder@linpro.no> to the _store() method, which makes it possible to catch arrays of hashes to be stored correctly. - cleaned up the t/run.t testscript to reflect the changes (in fact I did not touch it since 1.18 or so). - added test number 16 to test variable interpolation using ::Interpolated in t/run.t. - fixed bug with new() parameter -AllowMultiOptions which generated a croak() if set to something other than "no". - changed Extended::save() to reflect the API change, it calls now save_file(). git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@21 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
15
Changelog
15
Changelog
@@ -1,3 +1,18 @@
|
||||
1.32 - *argl* ... I forgot Interpolated.pm, don't know how that
|
||||
could happen, in 1.29 it was "lost". However -
|
||||
I added it again now.
|
||||
- added patch by Peder Stray <peder@linpro.no> to
|
||||
the _store() method, which makes it possible to catch
|
||||
arrays of hashes to be stored correctly.
|
||||
- cleaned up the t/run.t testscript to reflect the
|
||||
changes (in fact I did not touch it since 1.18 or so).
|
||||
- added test number 16 to test variable interpolation
|
||||
using ::Interpolated in t/run.t.
|
||||
- fixed bug with new() parameter -AllowMultiOptions which
|
||||
generated a croak() if set to something other than "no".
|
||||
- changed Extended::save() to reflect the API change,
|
||||
it calls now save_file().
|
||||
|
||||
1.31: - i'm such a moron ... I forgot to do a make clean
|
||||
in 1.30, pf. So this is 1.31, which is clean.
|
||||
|
||||
|
||||
22
General.pm
22
General.pm
@@ -18,7 +18,7 @@ use strict;
|
||||
use Carp;
|
||||
use Exporter;
|
||||
|
||||
$Config::General::VERSION = "1.30";
|
||||
$Config::General::VERSION = "1.32";
|
||||
|
||||
use vars qw(@ISA @EXPORT);
|
||||
@ISA = qw(Exporter);
|
||||
@@ -47,6 +47,9 @@ sub new {
|
||||
$self->{NoMultiOptions} = 1;
|
||||
delete $conf{-AllowMultiOptions};
|
||||
}
|
||||
else {
|
||||
delete $conf{-AllowMultiOptions};
|
||||
}
|
||||
}
|
||||
if (exists $conf{-String} ) {
|
||||
if ($conf{-String}) {
|
||||
@@ -501,7 +504,7 @@ sub save {
|
||||
if ( (@two && $one) && ( (scalar @two) % 2 == 0) ) {
|
||||
# @two seems to be a hash
|
||||
my %h = @two;
|
||||
$this->Save($one, \%h);
|
||||
$this->save_file($one, \%h);
|
||||
}
|
||||
else {
|
||||
croak "The save() method is deprecated. Use the new save_file() method instead!";
|
||||
@@ -577,8 +580,17 @@ sub _store {
|
||||
foreach my $entry (sort keys %config) {
|
||||
if (ref($config{$entry}) eq "ARRAY") {
|
||||
foreach my $line (@{$config{$entry}}) {
|
||||
$line =~ s/#/\\#/g;
|
||||
$config_string .= $indent . $entry . " " . $line . "\n";
|
||||
# patch submitted by Peder Stray <peder@linpro.no> to catch
|
||||
# arrays of hashes.
|
||||
if (ref($line) eq "HASH") {
|
||||
$config_string .= $indent . "<" . $entry . ">\n";
|
||||
$config_string .= $this->_store($level + 1, %{$line});
|
||||
$config_string .= $indent . "</" . $entry . ">\n";
|
||||
}
|
||||
else {
|
||||
$line =~ s/#/\\#/g;
|
||||
$config_string .= $indent . $entry . " " . $line . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif (ref($config{$entry}) eq "HASH") {
|
||||
@@ -1425,7 +1437,7 @@ Thomas Linden <tom@daemon.de>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
1.30
|
||||
1.32
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use vars qw(@ISA);
|
||||
use strict;
|
||||
|
||||
|
||||
$Config::General::Extended::VERSION = "1.2";
|
||||
$Config::General::Extended::VERSION = "1.3";
|
||||
|
||||
|
||||
sub obj {
|
||||
@@ -172,8 +172,8 @@ sub save {
|
||||
if (!$file) {
|
||||
$file = $this->{configfile};
|
||||
}
|
||||
open $fh, ">$file" or croak "Could not open $file!($!)\n";
|
||||
$this->_store($fh, 0,%{$this->{config}});
|
||||
|
||||
$this->save_file($file);
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,9 @@ 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')
|
||||
|
||||
@@ -474,7 +476,7 @@ values under the given key will be overwritten.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (c) 2000-2001 Thomas Linden
|
||||
Copyright (c) 2000-2002 Thomas Linden
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the same terms as Perl itself.
|
||||
@@ -492,7 +494,7 @@ Thomas Linden <tom@daemon.de>
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
1.1
|
||||
1.3
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
15
t/cfg.16
Normal file
15
t/cfg.16
Normal file
@@ -0,0 +1,15 @@
|
||||
# variable interpolation test
|
||||
|
||||
<vars>
|
||||
base = /usr
|
||||
uid = 501
|
||||
</vars>
|
||||
|
||||
<etc>
|
||||
dir = $base/conf # $base should not be interpolated
|
||||
base = /usr/local # set $base to a new value in this scope
|
||||
log = ${base}/log/logfile # use braces
|
||||
<users>
|
||||
home = $base/home/max # $base should be interpolated
|
||||
</users>
|
||||
</etc>
|
||||
8
t/cfg.8
8
t/cfg.8
@@ -25,3 +25,11 @@ passwd = sakkra
|
||||
<db>
|
||||
host = blah.blubber
|
||||
</db>
|
||||
|
||||
<beta>
|
||||
user1 hans
|
||||
</beta>
|
||||
|
||||
<beta>
|
||||
user2 max
|
||||
</beta>
|
||||
|
||||
41
t/run.t
41
t/run.t
@@ -6,13 +6,17 @@
|
||||
#
|
||||
# Under normal circumstances every test should succeed.
|
||||
|
||||
BEGIN { $| = 1; print "1..15\n";}
|
||||
BEGIN { $| = 1; print "1..16\n";}
|
||||
use lib "blib/lib";
|
||||
use Config::General;
|
||||
use Config::General::Extended;
|
||||
use Config::General::Interpolated;
|
||||
use Data::Dumper;
|
||||
print "ok\n";
|
||||
print STDERR "\n1 .. ok # loading Config::General and Config::General::Extended\n";
|
||||
print STDERR " .. ok # loading:
|
||||
Config::General
|
||||
Config::General::Extended
|
||||
Config::General::Interpolated\n";
|
||||
|
||||
foreach (2..7) {
|
||||
&p("t/cfg." . $_, $_);
|
||||
@@ -32,7 +36,7 @@ my $b = \%copyhash;
|
||||
# one we got from cfg.8
|
||||
if (&comp($a,$b)) {
|
||||
print "ok\n";
|
||||
print STDERR "8 .. ok # Writing Config Hash to disk and compare with original\n";
|
||||
print STDERR " .. ok # Writing Config Hash to disk and compare with original\n";
|
||||
}
|
||||
else {
|
||||
print "8 not ok\n";
|
||||
@@ -44,7 +48,7 @@ else {
|
||||
|
||||
$conf = new Config::General::Extended("t/test.rc");
|
||||
print "ok\n";
|
||||
print STDERR "9 .. ok # Creating a new object from config file\n";
|
||||
print STDERR " .. ok # Creating a new object from config file\n";
|
||||
|
||||
|
||||
|
||||
@@ -55,28 +59,28 @@ my $conf2 = new Config::General::Extended(
|
||||
-AllowMultiOptions => "yes"
|
||||
);
|
||||
print "ok\n";
|
||||
print STDERR "10 .. ok # Creating a new object using the hash parameter way\n";
|
||||
print STDERR " .. ok # Creating a new object using the hash parameter way\n";
|
||||
|
||||
|
||||
|
||||
|
||||
my $domain = $conf->obj("domain");
|
||||
print "ok\n";
|
||||
print STDERR "11 .. ok # Creating a new object from a block\n";
|
||||
print STDERR " .. ok # Creating a new object from a block\n";
|
||||
|
||||
|
||||
|
||||
|
||||
my $addr = $domain->obj("bar.de");
|
||||
print "ok\n";
|
||||
print STDERR "12 .. ok # Creating a new object from a sub block\n";
|
||||
print STDERR " .. ok # Creating a new object from a sub block\n";
|
||||
|
||||
|
||||
|
||||
|
||||
my @keys = $conf->keys("domain");
|
||||
print "ok\n";
|
||||
print STDERR "13 .. ok # Getting values from the object\n";
|
||||
print STDERR " .. ok # Getting values from the object\n";
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +97,7 @@ if ($conf->is_hash("domain")) {
|
||||
}
|
||||
}
|
||||
print "ok\n";
|
||||
print STDERR "14 .. ok # Using keys() and values() \n";
|
||||
print STDERR " .. ok # Using keys() and values() \n";
|
||||
|
||||
# test AUTOLOAD methods
|
||||
my $conf3 = new Config::General::Extended( { name => "Moser", prename => "Hannes"}
|
||||
@@ -105,11 +109,26 @@ $conf3->prename("Max");
|
||||
$conf3->save("t/test.cfg");
|
||||
|
||||
print "ok\n";
|
||||
print STDERR "15 .. ok # Using AUTOLOAD methods\n";
|
||||
print STDERR " .. ok # Using AUTOLOAD methods\n";
|
||||
|
||||
|
||||
|
||||
|
||||
# testing variable interpolation
|
||||
my $conf16 = new Config::General::Interpolated("t/cfg.16");
|
||||
my %h16 = $conf16->getall();
|
||||
|
||||
if($h16{etc}->{log} eq "/usr/local/log/logfile") {
|
||||
print "ok\n";
|
||||
print STDERR " .. ok # Testing variable interpolation\n";
|
||||
}
|
||||
else {
|
||||
print "16 not ok\n";
|
||||
print STDERR "16 not ok\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub p {
|
||||
my($cfg, $t) = @_;
|
||||
open T, "<$cfg";
|
||||
@@ -120,7 +139,7 @@ sub p {
|
||||
my $conf = new Config::General($cfg);
|
||||
my %hash = $conf->getall;
|
||||
print "ok\n";
|
||||
print STDERR "$t .. ok $fst\n";
|
||||
print STDERR " .. ok $fst\n";
|
||||
}
|
||||
|
||||
sub comp {
|
||||
|
||||
Reference in New Issue
Block a user