mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 20:21:01 +01:00
revision 1.16
date: 2000/08/03 16:54:58; author: jens; state: Exp; lines: +4 -1 An jedes File eine Sektion # Local Variables: *** # perl-master-file: ../../webmin/index.pl *** # End: *** rangehängt, damit ich mit C-c d das debugging von jedem File aus einschalten kann (siehe mein .emacs file) ---------------------------- revision 1.15 date: 2000/08/01 09:12:52; author: tom; state: Exp; lines: +57 -68 added comments to _open() and _parse() ---------------------------- revision 1.14 date: 2000/07/31 18:07:12; author: tom; state: Exp; lines: +44 -19 added <<include ... >> capability ---------------------------- revision 1.13 date: 2000/07/16 18:35:33; author: tom; state: Exp; lines: +135 -10 added here-doc and multi-line feature, updated perlpod ---------------------------- revision 1.12 date: 2000/07/14 14:56:09; author: tom; state: Exp; lines: +2 -2 bug fixed, it did not ignore options inside c-comments with a # comment @ the end of line ---------------------------- revision 1.11 date: 2000/07/14 11:26:04; author: tom; state: Exp; lines: +42 -6 added C-Style comments and allow also comments after a statement. ---------------------------- revision 1.10 date: 2000/07/12 14:04:51; author: tom; state: Exp; lines: +2 -1 i woas ned ---------------------------- revision 1.9 date: 2000/07/12 10:59:53; author: jens; state: Exp; lines: +5 -3 hehe :) ---------------------------- revision 1.8 date: 2000/07/12 10:43:20; author: tom; state: Exp; lines: +5 -2 fixed bug in getall(), which doubled %config if called more than onse. ---------------------------- revision 1.7 date: 2000/07/12 09:09:33; author: tom; state: Exp; lines: +22 -24 100% Apache Config complete ;-) it supports now "named blocks"! ---------------------------- revision 1.6 date: 2000/07/11 23:43:03; author: tom; state: Exp; lines: +72 -19 added named block support (<server holland>) ---------------------------- revision 1.5 date: 2000/07/11 20:49:47; author: tom; state: Exp; lines: +2 -2 typo in pod corrected ---------------------------- revision 1.4 date: 2000/07/11 17:07:04; author: tom; state: Exp; lines: +61 -7 a config file can now contain an option more than once and will be returned as array ---------------------------- revision 1.3 date: 2000/07/07 11:27:38; author: cvs; state: Exp; lines: +2 -2 folgende Parameterform geht jetzt auch: parameter= blabla vorher musste man parameter = blabla schreiben ---------------------------- revision 1.2 date: 2000/07/04 13:21:12; author: tom; state: Exp; lines: +9 -4 added better failurehandling in case of missing block start/end statements ---------------------------- revision 1.1 date: 2000/07/04 12:52:09; author: tom; state: Exp; implemented module and method getall, works as expected. git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@5 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
11
t/cfg.2
Normal file
11
t/cfg.2
Normal file
@@ -0,0 +1,11 @@
|
||||
# Nested block test
|
||||
<cops>
|
||||
<officer randall>
|
||||
name stein
|
||||
age 25
|
||||
</officer>
|
||||
<officer gordon>
|
||||
name bird
|
||||
age 31
|
||||
</officer>
|
||||
</cops>
|
||||
4
t/cfg.3
Normal file
4
t/cfg.3
Normal file
@@ -0,0 +1,4 @@
|
||||
# Array content test
|
||||
domain b0fh.org
|
||||
domain l0pht.com
|
||||
domain infonexus.com
|
||||
6
t/cfg.4
Normal file
6
t/cfg.4
Normal file
@@ -0,0 +1,6 @@
|
||||
# Here-document test
|
||||
message <<EOF
|
||||
yes. we are not here. you
|
||||
can reach us somewhere in
|
||||
outerspace.
|
||||
EOF
|
||||
5
t/cfg.5
Normal file
5
t/cfg.5
Normal file
@@ -0,0 +1,5 @@
|
||||
# Multiline option test
|
||||
command = ssh -f -g orphues.0x49.org \
|
||||
-l azrael -L:34777samir.okir.da.ru:22 \
|
||||
-L:31773:shane.sol1.rocket.de:22 \
|
||||
'exec sleep 99999990'
|
||||
10
t/cfg.6
Normal file
10
t/cfg.6
Normal file
@@ -0,0 +1,10 @@
|
||||
# Comment test
|
||||
user = tom # a comment right after a line
|
||||
/*
|
||||
* C-style comment (multiline)
|
||||
*/
|
||||
passwd = sakkra
|
||||
<db>
|
||||
/* oneline C-style comment */
|
||||
host = blah.blubber
|
||||
</db>
|
||||
27
t/cfg.7
Normal file
27
t/cfg.7
Normal file
@@ -0,0 +1,27 @@
|
||||
<cops>
|
||||
<officer randall>
|
||||
name stein
|
||||
age 25
|
||||
</officer>
|
||||
<officer gordon>
|
||||
name bird
|
||||
age 31
|
||||
</officer>
|
||||
</cops>
|
||||
domain b0fh.org
|
||||
domain l0pht.com
|
||||
domain infonexus.com
|
||||
message <<EOF
|
||||
yes. we are not here. you
|
||||
can reach us somewhere in
|
||||
outerspace.
|
||||
EOF
|
||||
command = ssh -f -g orphues.0x49.org \
|
||||
-l azrael -L:34777samir.okir.da.ru:22 \
|
||||
-L:31773:shane.sol1.rocket.de:22 \
|
||||
'exec sleep 99999990'
|
||||
user = tom
|
||||
passwd = sakkra
|
||||
<db>
|
||||
host = blah.blubber
|
||||
</db>
|
||||
26
t/cfg.out
Normal file
26
t/cfg.out
Normal file
@@ -0,0 +1,26 @@
|
||||
command ssh -f -g orphues.0x49.org -l azrael -L:34777samir.okir.da.ru:22 -L:31773:shane.sol1.rocket.de:22 'exec sleep 99999990'
|
||||
<cops>
|
||||
<officer>
|
||||
<gordon>
|
||||
age 31
|
||||
name bird
|
||||
</gordon>
|
||||
<randall>
|
||||
age 25
|
||||
name stein
|
||||
</randall>
|
||||
</officer>
|
||||
</cops>
|
||||
<db>
|
||||
host blah.blubber
|
||||
</db>
|
||||
domain b0fh.org
|
||||
domain l0pht.com
|
||||
domain infonexus.com
|
||||
message <<EOF
|
||||
yes. we are not here. you
|
||||
can reach us somewhere in
|
||||
outerspace.
|
||||
EOF
|
||||
passwd sakkra
|
||||
user tom
|
||||
66
t/run.t
Normal file
66
t/run.t
Normal file
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# testscript for Conf.pm by Thomas Linden
|
||||
# needs to be invoked using the command "make test" from
|
||||
# the Conf.pm source directory.
|
||||
# Under normal circumstances every test should run.
|
||||
|
||||
BEGIN { $| = 1; print "1..7\n";}
|
||||
use lib "blib/lib";
|
||||
use Config::General;
|
||||
print "ok\n";
|
||||
print STDERR "\n1 .. ok # loading Config::General\n";
|
||||
|
||||
foreach (2..6) {
|
||||
&p("t/cfg." . $_, $_);
|
||||
}
|
||||
|
||||
my $conf = new Config::General("t/cfg.7");
|
||||
my %hash = $conf->getall;
|
||||
$conf->save("t/cfg.out", %hash);
|
||||
|
||||
my $copy = new Config::General("t/cfg.out");
|
||||
my %copyhash = $copy->getall;
|
||||
|
||||
my $a = \%hash;
|
||||
my $b = \%copyhash;
|
||||
|
||||
# now see if the saved hash is still the same as the
|
||||
# one we got from cfg.7
|
||||
if (&comp($a,$b)) {
|
||||
print "ok\n";
|
||||
print STDERR "7 .. ok # Writing Config Hash to disk and compare with original\n";
|
||||
}
|
||||
else {
|
||||
print "7 not ok\n";
|
||||
print STDERR "7 .. not ok\n";
|
||||
}
|
||||
|
||||
|
||||
sub p {
|
||||
my($cfg, $t) = @_;
|
||||
open T, "<$cfg";
|
||||
my @file = <T>;
|
||||
close T;
|
||||
@file = map { chomp($_); $_} @file;
|
||||
my $fst = $file[0];
|
||||
my $conf = new Config::General($cfg);
|
||||
my %hash = $conf->getall;
|
||||
print "ok\n";
|
||||
print STDERR "$t .. ok $fst\n";
|
||||
}
|
||||
|
||||
sub comp {
|
||||
my($a, $b) = @_;
|
||||
foreach my $key (keys %{$a}) {
|
||||
if(ref($a->{$key}) eq "HASH") {
|
||||
&comp($a->{$key},$b->{$key});
|
||||
next;
|
||||
}
|
||||
elsif(ref($a->{$key}) eq "ARRAY") {
|
||||
# ignore arrays for simplicity
|
||||
next;
|
||||
}
|
||||
return 0 if($a->{$key} ne $b->{$key});
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user