From 61397677d352ab8bb70903c3576129b63c3e0d4a Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sat, 10 Oct 2009 16:43:18 +0000 Subject: [PATCH] 2.38 - fixed rt.cpan.org#31529 variable inheritance failed with multiple named blocks. - fixed rt.cpan.org#33447, regex to catch variable names were too strict, now - . + or : are allowed too. - fixed rt.cpan.org#33385 and #32978 - using arrayrefs as param to -String didn't work anymore (sic) - fixed rt.cpan.org#33216 - variable stack were not properly re-constructed for pre-existing variables if -MergeDuplicateOptions is turned on. git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@64 be1acefe-a474-0410-9a34-9b3221f2030f --- Changelog | 15 +++++++++++++++ General.pm | 37 ++++++++++++++++++++++++++++--------- General/Interpolated.pm | 4 ++-- README | 2 +- t/run.t | 9 ++++++++- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Changelog b/Changelog index ea0beb9..e7e7b32 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,18 @@ + 2.38 + - fixed rt.cpan.org#31529 variable inheritance failed + with multiple named blocks. + + - fixed rt.cpan.org#33447, regex to catch variable + names were too strict, now - . + or : are allowed too. + + - fixed rt.cpan.org#33385 and #32978 - using arrayrefs + as param to -String didn't work anymore (sic) + + - fixed rt.cpan.org#33216 - variable stack were not properly + re-constructed for pre-existing variables if + -MergeDuplicateOptions is turned on. + + 2.37 - "fixed" rt.cpan.org#30199 - check for invalid and unsupported structures, especially mixing blocks diff --git a/General.pm b/General.pm index a069139..13fac98 100644 --- a/General.pm +++ b/General.pm @@ -5,7 +5,7 @@ # config values from a given file and # return it as hash structure # -# Copyright (c) 2000-2007 Thomas Linden . +# Copyright (c) 2000-2008 Thomas Linden . # All Rights Reserved. Std. disclaimer applies. # Artificial License, same as perl itself. Have fun. # @@ -32,7 +32,7 @@ use Carp::Heavy; use Carp; use Exporter; -$Config::General::VERSION = 2.37; +$Config::General::VERSION = 2.38; use vars qw(@ISA @EXPORT_OK); use base qw(Exporter); @@ -65,6 +65,7 @@ sub new { false => '^(off|no|false|0)$', }, DefaultConfig => {}, + String => '', level => 1, InterPolateVars => 0, InterPolateEnv => 0, @@ -287,7 +288,8 @@ sub _prepare { # handle options which contains values we need (strings, hashrefs or the like) if (exists $conf{-String} ) { - if (ref(\$conf{-String}) eq 'SCALAR') { + #if (ref(\$conf{-String}) eq 'SCALAR') { + if (not ref $conf{-String}) { if ( $conf{-String}) { $self->{StringContent} = $conf{-String}; } @@ -295,14 +297,15 @@ sub _prepare { } # re-implement arrayref support, removed after 2.22 as _read were # re-organized - elsif(ref(\$conf{-String}) eq 'ARRAY') { - $self->{StringContent} = join '\n', @{$conf{-String}}; + # fixed bug#33385 + elsif(ref($conf{-String}) eq 'ARRAY') { + $self->{StringContent} = join "\n", @{$conf{-String}}; } else { - croak "Config::General: Parameter -String must be a SCALAR!\n"; + croak "Config::General: Parameter -String must be a SCALAR or ARRAYREF!\n"; } + delete $conf{-String}; } - if (exists $conf{-Tie}) { if ($conf{-Tie}) { $self->{Tie} = delete $conf{-Tie}; @@ -592,6 +595,7 @@ sub _read { } # remove the \ from all characters if BackslashEscape is turned on + # FIXME (rt.cpan.org#33218 if ($this->{BackslashEscape}) { s/\\(.)/$1/g; } @@ -770,6 +774,12 @@ sub _parse { if (exists $config->{$option}) { if ($this->{MergeDuplicateOptions}) { $config->{$option} = $this->_parse_value($config, $option, $value); + + # bugfix rt.cpan.org#33216 + if ($this->{InterPolateVars}) { + # save pair on local stack + $config->{__stack}->{$option} = $config->{$option}; + } } else { if (! $this->{AllowMultiOptions} ) { @@ -905,7 +915,16 @@ sub _parse { else { push @ar, $savevalue; } - push @ar, $this->_parse( $this->_hashref(), \@newcontent); + + # fixes rt#31529 + my $tmphash = $this->_hashref(); + if ($this->{InterPolateVars}) { + # inherit current __stack to new block + $tmphash->{__stack} = $config->{__stack}; + } + + push @ar, $this->_parse( $tmphash, \@newcontent); + $config->{$block} = \@ar; } } @@ -2390,7 +2409,7 @@ Thomas Linden =head1 VERSION -2.37 +2.38 =cut diff --git a/General/Interpolated.pm b/General/Interpolated.pm index 23e187f..36fdf48 100644 --- a/General/Interpolated.pm +++ b/General/Interpolated.pm @@ -8,7 +8,7 @@ # package Config::General::Interpolated; -$Config::General::Interpolated::VERSION = "2.09"; +$Config::General::Interpolated::VERSION = "2.10"; use strict; use Carp; @@ -47,7 +47,7 @@ sub _set_regex { # but can't begin with a '\' \$ # dollar sign (\{)? # $2: optional opening curly - ([a-zA-Z_]\w*) # $3: capturing variable name + ([a-zA-Z0-9_\-\.:\+,]+) # $3: capturing variable name (fix of #33447) ( ?(2) # $4: if there's the opening curly... \} # ... match closing curly diff --git a/README b/README index df55fe1..a0f6c8d 100644 --- a/README +++ b/README @@ -104,4 +104,4 @@ AUTHOR VERSION - 2.34 + 2.38 diff --git a/t/run.t b/t/run.t index c682846..965bf69 100644 --- a/t/run.t +++ b/t/run.t @@ -8,7 +8,7 @@ use Data::Dumper; -use Test::More tests => 43; +use Test::More tests => 45; #use Test::More qw(no_plan); ### 1 @@ -450,3 +450,10 @@ foreach my $pos (40 .. 43) { }; ok($@ =~ /^Config::General/, "$pos: Structural error checks"); } + +my $conf44; +eval { + $conf44 = new Config::General(-String => [ 'foo bar' ]); +}; +ok(! $@, "-String arrayref"); +is_deeply({ $conf44->getall }, { foo => 'bar' }, "-String arrayref contents");