diff --git a/Changelog b/Changelog index a03c3e8..2a80266 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,20 @@ + 2.02 - added patch by Jens Heunemann, which allows to use + whitespaces in option names. + + - changed the save() calls in the test script (t/run.t) + to save_file() + + - removed new() from ::Interpolated and ::Extended. + This may break existing code (they will need to + move to the flags of Config::General::new() ), but + this decision must be made. The problem was that + both the old way of directly using the subclasses + and the enw way did not work together. So, now + subclasses are only method holders and used by + Config::General on request. Direct use of subclasses + is prohibited. (you receive a warning if you do). + + 2.01 - added -ConfigFile (in replace for -file) and -ConfigHash (in replace for -hash) to get a consistent parameter naming scheme. The old names are still @@ -213,4 +230,85 @@ - comments inside here-documents will now remain in the here-doc value. - previous history logs are lost in space :-( +history logs 1.17+1.18 are lost in space :-( + +older history logs (stripped from CVS): + +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 <> 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 () +---------------------------- +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. + diff --git a/General.pm b/General.pm index 4fa474b..f49602f 100644 --- a/General.pm +++ b/General.pm @@ -17,7 +17,7 @@ use strict; use Carp; use Exporter; -$Config::General::VERSION = "2.01"; +$Config::General::VERSION = "2.02"; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @@ -350,7 +350,16 @@ sub _parse { $_ =~ s/^\s*//; # strip spaces @ end and begin $_ =~ s/\s*$//; - my ($option,$value) = split /\s*=\s*|\s+/, $_, 2; # option/value assignment, = is optional + # my ($option,$value) = split /\s*=\s*|\s+/, $_, 2; # option/value assignment, = is optional + + my ($option,$value); + if (/=/) { + ($option,$value) = split /\s*=\s*/, $_, 2; # option/value assignment, = is optional + } + else { + ($option,$value) = split /\s+/, $_, 2; # option/value assignment, = is optional + } + my $indichar = chr(182); # ¶, inserted by _open, our here-doc indicator $value =~ s/^$indichar// if($value); # a here-doc begin, remove indicator if ($value && $value =~ /^"/ && $value =~ /"$/) { @@ -956,7 +965,7 @@ Multiple flags can be used, separated by the pipe character |. Well, an example will clarify things: my $conf = new Config::General( - -file => "rcfile", + -ConfigFile => "rcfile", -FlagBits => { Mode => { CLEAR => 1, @@ -1417,7 +1426,7 @@ open included files from the directory, where the configfile resides. You need t the option B<-IncludeRelative> (see B) if you want that. An example: my $conf = Config::General( - -file => "/etc/crypt.d/server.cfg" + -ConfigFile => "/etc/crypt.d/server.cfg" -IncludeRelative => 1 ); @@ -1502,7 +1511,7 @@ allowed to the B method of the standard interface. Example: use Config::General; - my %config = ParseConfig(-file => "rcfile", -AutoTrue => 1); + my %config = ParseConfig(-ConfigFile => "rcfile", -AutoTrue => 1); =item B @@ -1526,7 +1535,7 @@ method B does. Example: use Config::General; - my %config = ParseConfig(-file => "rcfile"); + my %config = ParseConfig(-ConfigFile => "rcfile"); .. # change %config something my $content = SaveConfigString(\%config); @@ -1566,7 +1575,7 @@ Thomas Linden =head1 VERSION -2.01 +2.02 =cut diff --git a/General/Extended.pm b/General/Extended.pm index d180970..3d43fb4 100644 --- a/General/Extended.pm +++ b/General/Extended.pm @@ -24,7 +24,13 @@ use vars qw(@ISA @EXPORT); use strict; -$Config::General::Extended::VERSION = "1.6"; +$Config::General::Extended::VERSION = "1.7"; + + +sub new { + croak "Deprecated method Config::General::Extended::new() called.\n" + ."Use Config::General::new() instead and set the -ExtendedAccess flag.\n"; +} sub obj { @@ -36,14 +42,14 @@ sub obj { my($this, $key) = @_; if (exists $this->{config}->{$key}) { if (!$this->{config}->{$key}) { - return $this->new( () ); # empty object! + return $this->SUPER::new( -ExtendedAccess => 1, -ConfigHash => {} ); # empty object! } else { - return $this->new( $this->{config}->{$key} ); + return $this->SUPER::new( -ExtendedAccess => 1, -ConfigHash => $this->{config}->{$key} ); } } else { - return $this->new( $this->{config} ); + return $this->SUPER::new( -ExtendedAccess => 1, -ConfigHash => $this->{config} ); } } @@ -263,7 +269,7 @@ Config::General::Extended - Extended access to Config files use Config::General; $conf = new Config::General( - -file => 'configfile', + -ConfigFile => 'configfile', -ExtendedAccess => 1 ); @@ -490,7 +496,7 @@ Thomas Linden =head1 VERSION -1.6 +1.7 =cut diff --git a/General/Interpolated.pm b/General/Interpolated.pm index 129755c..5fc1131 100644 --- a/General/Interpolated.pm +++ b/General/Interpolated.pm @@ -1,5 +1,5 @@ package Config::General::Interpolated; -$Config::General::Interpolated::VERSION = "1.1"; +$Config::General::Interpolated::VERSION = "1.3"; use strict; use Carp; @@ -17,14 +17,9 @@ sub new { # overwrite new() with our own version # and call the parent class new() # - my $class = shift; - my $self = $class->SUPER::new(@_); - $self->{regex} = $self->_set_regex(); - - $self->{config} = $self->_vars($self->{config}, {}); - - return $self; + croak "Deprecated method Config::General::Interpolated::new() called.\n" + ."Use Config::General::new() instead and set the -InterPolateVars flag.\n"; } @@ -62,7 +57,7 @@ sub _vars { # collect values that don't need to be substituted first while (my ($key, $value) = each %{$config}) { $varstack{$key} = $value - unless ref($value) or $value =~ $this->{regex}; + unless ref($value) or $value =~ /$this->{regex}/; } my $sub_interpolate = sub { @@ -102,8 +97,10 @@ sub _vars { # traverse the hierarchy part while (my ($key, $value) = each %{$config}) { # this is not a scalar recursive call to myself - _vars($value, {%{$stack}, %varstack}) - if ref($value) eq 'HASH'; + if (ref($value) eq 'HASH') { + # called via Gonfig::General procedural + _vars($this, $value, {%{$stack}, %varstack}); + } } return $config; @@ -123,7 +120,7 @@ Config::General::Interpolated - Parse variables within Config files use Config::General; $conf = new Config::General( - -file => 'configfile', + -CinfigFile => 'configfile', -InterPolateVars => 1 ); @@ -213,7 +210,7 @@ See L =head1 VERSION -This document describes version 1.1 of B. +1.3 =cut diff --git a/README b/README index 1ad7986..89702ea 100644 --- a/README +++ b/README @@ -47,6 +47,36 @@ INSTALLATION t/cfg.* +UPDATE + + If you are updating from version 1.xx, you might be interested, + that some things in the API has changed, which might force you + to change your application code. These changes were necessary + to clean up the module interface. Now it has a consistent + "look and feel" and behaves more naturally. Therefore historic + remains were removed. + + Here is a short list: + + o it is no more possible to use Config::General::Extended + and Config::General::Interpolated directly. Instead use + Config::General and turn on -InterPolateVars and + -ExtendedAccess respectively. + + o the method NoMultiOptions() is deprecated. Set the parameter + -AllowMultiOptions to false when calling new() to create + a new Config::General object. + + o the method save() is deprecated. Use save_file() or + save_string() instead. + + o the parameter -file is deprecated. Use -ConfigFile instead. + + o the parameter -hash is deprecated. Use -ConfigHash instead. + + For a more detailed explanation of changes refer to the Changelog. + + COPYRIGHT Config::General Config::General::Extended @@ -68,4 +98,4 @@ AUTHOR VERSION - 2.01 + 2.02 diff --git a/t/cfg.16 b/t/cfg.16 index 79c5087..45bd29b 100644 --- a/t/cfg.16 +++ b/t/cfg.16 @@ -1,5 +1,6 @@ # variable interpolation test - +me=blah +pr=$me/blubber base = /usr uid = 501 diff --git a/t/run.t b/t/run.t index 7ccc73c..2323c2a 100644 --- a/t/run.t +++ b/t/run.t @@ -1,4 +1,4 @@ -# +# -*-perl-*- # testscript for Config::General Classes by Thomas Linden # # needs to be invoked using the command "make test" from @@ -9,14 +9,11 @@ BEGIN { $| = 1; print "1..18\n";} use lib "blib/lib"; use Config::General; -use Config::General::Extended; -use Config::General::Interpolated; use Data::Dumper; + print "ok\n"; -print STDERR " .. ok # loading: - Config::General - Config::General::Extended - Config::General::Interpolated\n"; +print STDERR " .. ok # loading Config::General\n"; + foreach (2..7) { &p("t/cfg." . $_, $_); @@ -24,7 +21,7 @@ foreach (2..7) { my $conf = new Config::General("t/cfg.8"); my %hash = $conf->getall; -$conf->save("t/cfg.out", %hash); +$conf->save_file("t/cfg.out"); my $copy = new Config::General("t/cfg.out"); my %copyhash = $copy->getall; @@ -46,7 +43,9 @@ else { ############## Extended Tests ################# -$conf = new Config::General::Extended("t/test.rc"); +$conf = new Config::General( + -ExtendedAccess => 1, + -ConfigFile => "t/test.rc"); print "ok\n"; print STDERR " .. ok # Creating a new object from config file\n"; @@ -54,10 +53,11 @@ print STDERR " .. ok # Creating a new object from config file\n"; # now test the new notation of new() -my $conf2 = new Config::General::Extended( - -file => "t/test.rc", - -AllowMultiOptions => "yes" - ); +my $conf2 = new Config::General( + -ExtendedAccess => 1, + -ConfigFile => "t/test.rc", + -AllowMultiOptions => "yes" + ); print "ok\n"; print STDERR " .. ok # Creating a new object using the hash parameter way\n"; @@ -99,14 +99,19 @@ if ($conf->is_hash("domain")) { print "ok\n"; print STDERR " .. ok # Using keys() and values() \n"; + + + # test AUTOLOAD methods -my $conf3 = new Config::General::Extended( { name => "Moser", prename => "Hannes"} -); +my $conf3 = new Config::General( + -ExtendedAccess => 1, + -ConfigHash => { name => "Moser", prename => "Hannes"} + ); my $n = $conf3->name; my $p = $conf3->prename; $conf3->name("Meier"); $conf3->prename("Max"); -$conf3->save("t/test.cfg"); +$conf3->save_file("t/test.cfg"); print "ok\n"; print STDERR " .. ok # Using AUTOLOAD methods\n"; @@ -115,9 +120,8 @@ print STDERR " .. ok # Using AUTOLOAD methods\n"; # testing variable interpolation -my $conf16 = new Config::General::Interpolated("t/cfg.16"); +my $conf16 = new Config::General(-ConfigFile => "t/cfg.16", -InterPolateVars => 1); my %h16 = $conf16->getall(); - if($h16{etc}->{log} eq "/usr/local/log/logfile") { print "ok\n"; print STDERR " .. ok # Testing variable interpolation\n"; @@ -157,7 +161,7 @@ my $conf18 = new Config::General( my %h18 = $conf18->getall(); if ($h18{home} eq "/home/users") { print "ok\n"; - print STDERR " .. ok # Testing value pre-setting using a hash\n"; + print STDERR " .. ok # Testing value pre-setting using a string\n"; } else { print "18 not ok\n";