diff --git a/Changelog b/Changelog index 0579269..36cca75 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,21 @@ + 2.29 + - applied patch by brian@kronos.com via rt.cpan.org + #11211. + + - applied patch by plasmaball@pchome.com.tw via + rt.cpan.org #5846 + + - added new files to MANIFEST file. + + - added example.cfg to show the config format. + + 2.28 + - fixed bug in save(), now blocks containing whitespaces + will be saved using quotes, in addition the parser observes + the quoting feature, added portion about this to the pod + doc. pointed out by Jeff Murphy . + - added internal list of files opened so far to avoid reading in the same file multiple times. Suggested by Michael Graham. diff --git a/General.pm b/General.pm index dfe3e07..64407eb 100644 --- a/General.pm +++ b/General.pm @@ -26,7 +26,7 @@ use Carp::Heavy; use Carp; use Exporter; -$Config::General::VERSION = "2.28"; +$Config::General::VERSION = "2.29"; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @@ -86,6 +86,7 @@ sub new { parsed => 0, # internal state stuff for variable interpolation upperkey => "", + upperkeys => [], lastkey => "", prevkey => " ", files => {}, # which files we have read, if any @@ -771,7 +772,7 @@ sub _parse { sub _savelast { my($this, $key) = @_; - $this->{upperkey} = $this->{lastkey}; + push(@{$this->{upperkeys}}, $this->{lastkey}); $this->{lastkey} = $this->{prevkey}; $this->{prevkey} = $key; } @@ -779,7 +780,7 @@ sub _savelast { sub _backlast { my($this, $key) = @_; $this->{prevkey} = $this->{lastkey}; - $this->{lastkey} = $this->{upperkey}; + $this->{lastkey} = pop(@{$this->{upperkeys}}); } sub _parse_value { @@ -2069,7 +2070,7 @@ Thomas Linden =head1 VERSION -2.28 +2.29 =cut diff --git a/General/Interpolated.pm b/General/Interpolated.pm index ee9acf1..23856d8 100644 --- a/General/Interpolated.pm +++ b/General/Interpolated.pm @@ -8,7 +8,7 @@ # package Config::General::Interpolated; -$Config::General::Interpolated::VERSION = "2.04"; +$Config::General::Interpolated::VERSION = "2.05"; use strict; use Carp; @@ -85,12 +85,13 @@ sub _interpolate { $value =~ s{$this->{regex}}{ my $con = $1; my $var = $3; + $var = lc($var) if $this->{LowerCaseNames}; if (exists $this->{stack}->{ $this->{level} }->{ $prevkey }->{$var}) { $con . $this->{stack}->{ $this->{level} }->{ $prevkey }->{$var}; } else { if ($this->{StrictVars}) { - croak "Use of uninitialized variable \$" . $var . "\n"; + croak "Use of uninitialized variable (\$$var) while loading config entry: $key = $value\n"; } else { # be cool @@ -114,15 +115,17 @@ sub _interpolate_hash { # my ($this, $config) = @_; - $this->{level} = 1; - $this->{upperkey} = ""; - $this->{lastkey} = ""; - $this->{prevkey} = " "; + $this->{level} = 1; + $this->{upperkey} = ""; + $this->{upperkeys} = []; + $this->{lastkey} = ""; + $this->{prevkey} = " "; $config = $this->_var_hash_stacker($config); $this->{level} = 1; $this->{upperkey} = ""; + $this->{upperkeys} = []; $this->{lastkey} = ""; $this->{prevkey} = " "; @@ -296,7 +299,7 @@ See L =head1 VERSION -2.04 +2.05 =cut diff --git a/MANIFEST b/MANIFEST index a4d9ec5..f08c7fb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,6 +8,12 @@ README t/cfg.16 t/cfg.17 t/cfg.19 +t/cfg.20.a +t/cfg.20.b +t/cfg.20.c +t/sub1/sub2/sub3/cfg.sub3 +t/sub1/sub2/cfg.sub2 +t/sub1/cfg.sub1 t/cfg.2 t/cfg.3 t/cfg.4 @@ -17,3 +23,4 @@ t/cfg.7 t/cfg.8 t/run.t t/test.rc +example.cfg diff --git a/README b/README index 57578c4..3168741 100644 --- a/README +++ b/README @@ -104,4 +104,4 @@ AUTHOR VERSION - 2.28 + 2.29 diff --git a/example.cfg b/example.cfg new file mode 100644 index 0000000..dd0cea3 --- /dev/null +++ b/example.cfg @@ -0,0 +1,74 @@ +# -*-sh-*- (ignore, this is just for my operation system, emacs, +# to function properly) +# +# This is an example of a config file supported by Config::General. +# It shows almost all features of the format and its flexibility. +# +# To try it, install Config::General as usual and execute the +# following perlscript: +# +# use Config::General; +# use Data::Dumper; +# my %conf = ParseConfig(-ConfigFile => "example.cfg", -InterPolateVars => 1); +# print Dumper(\%C);' +# +# This will parse the config and print out a stringified version +# of the hash it produces, which can be used in your program. +# + + +/* + * c-style comment + */ + +# variable assignment +option1 = blah +option2 blubber +option3 = "something special" # this is a comment + +option4 = parameters can be written on \ + multiple lines + +# duplicate options will be made into an array +huc = 12 +huc = 17 +huc = 133 + +# options can be organized in blocks too + + user = hans + server = mc200 + db = maxis + passwd = D3rf8d + + # nested blocks are no problem + + index int(100000) + name char(100) + prename char(100) + status int(10) + + + +# named blocks can also be used + + # block names containing whitespaces must be quoted + <"kyla cole"> + # blocks maybe empty + + + +# here-docs are fully supported +usage <