diff --git a/Changelog b/Changelog index 2b78d7c..ba30cce 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,34 @@ + 2.25 + - fixed bug with not working -IncludeRelative setting when + including a config file. It were only included from the + location relative to the underlying config if it were + non-existent. reported by Dmitry Koteroff . + + - applied patch by Danial Pearce + which adds the -BackslashEscape parameter to enable + general escaping of special characters using the + backslash. + + - fixed bug reported by Harold van Oostrom : + according to the documentation one can call new() with + a hash-ref as its single parameter which would then + used as the config. This didn't work and were fixed. + + - added feature suggested by Eric Andreychek : + now block statements like this are allowed: "" + which is called an explicit empty block. This generates just + an empty hash-ref and saves writing. In fact, internally it + will be converted to: + + + + - fixed Makefile.PL: it cleans now files generated by 'make test' + properly. reported by: Dagfinn Ilmari Mannsåker + + - updated MANIFEST (in fact I did this some years ago the last time!) + also reported by: Dagfinn Ilmari Mannsåker + + 2.24 - fixed Bug #3869 (rt.cpan.org) reported by "Mike Depot" diff --git a/General.pm b/General.pm index 4a22a7f..ddafc43 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-2003 Thomas Linden . +# Copyright (c) 2000-2004 Thomas Linden . # All Rights Reserved. Std. disclaimer applies. # Artificial License, same as perl itself. Have fun. # @@ -18,7 +18,7 @@ use strict; use Carp; use Exporter; -$Config::General::VERSION = "2.24"; +$Config::General::VERSION = "2.25"; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @@ -68,6 +68,8 @@ sub new { CComments => 1, # by default turned on + BackslashEscape => 0, # by default turned off, allows escaping anything using the backslash + StrictObjects => 1, # be strict on non-existent keys in OOP mode StrictVars => 1, # be strict on undefined variables in Interpolate mode @@ -167,6 +169,9 @@ sub new { elsif ($#param == 0) { # use of the old style $self->{ConfigFile} = $param[0]; + if (ref($self->{ConfigFile}) eq "HASH") { + $self->{ConfigHash} = delete $self->{ConfigFile}; + } } else { # this happens if $#param == -1,1 thus no param was given to new! @@ -336,6 +341,8 @@ sub _open { sub _read { # # store the config contents in @content + # and prepare it somewhat for easier parsing later + # (comments, continuing lines, and stuff) # my($this, $fh, $flag) = @_; my(@stuff, @content, $c_comment, $longline, $hier, $hierend, @hierdoc); @@ -425,11 +432,34 @@ sub _read { next if /^\s*$/; + # look for multiline option, indicated by a trailing backslash + my $extra = $this->{BackslashEscape} ? '(?{BackslashEscape}) { + s/\\(.)/$1/g; + } + else { + # remove the \ char in front of masked "#", if any + s/\\#/#/g; + } + # transform explicit-empty blocks to conforming blocks + if (/^<([^\/]+?.*?)\/>$/) { + my $block = $1; + my $orig = $_; + $orig =~ s/\/>$/>/; + $block =~ s/\s\s*.*$//; + push @{$this->{content}}, $orig, ""; + next; + } # look for here-doc identifier @@ -451,16 +481,6 @@ sub _read { - # look for multiline option, indicated by a trailing backslash - if (/\\$/) { - chop; - s/^\s*//; - $longline .= $_; - next; - } - - - ### ### any "normal" config lines from now on ### @@ -476,11 +496,16 @@ sub _read { else { # look for include statement(s) my $incl_file; + my $path = ""; + if (defined($this->{ConfigPath})) { + # fetch pathname of base config file, assuming the 1st one is the path of it + $path = $this->{ConfigPath}->[0]; + } if (/^\s*<>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) { $incl_file = $1; - if ( $this->{IncludeRelative} && $this->{configpath} && !file_name_is_absolute($incl_file) ) { + if ( $this->{IncludeRelative} && $path && !file_name_is_absolute($incl_file) ) { # include the file from within location of $this->{configfile} - $this->_open( $incl_file ); + $this->_open( catfile($path, $incl_file) ); } else { # include the file from within pwd, or absolute @@ -589,13 +614,15 @@ sub _parse { $config->{$option} = $this->_parse_value($option, $value); } else { - push @{$config->{$option}}, $this->_parse_value($option, $value); # it's already an array, just push + # it's already an array, just push + push @{$config->{$option}}, $this->_parse_value($option, $value); } } } } else { - $config->{$option} = $this->_parse_value($option, $value); # standard config option, insert key/value pair into node + # standard config option, insert key/value pair into node + $config->{$option} = $this->_parse_value($option, $value); } } } @@ -646,7 +673,6 @@ sub _parse { } else { # the first occurence of this particular named block - #### $config->{$block}->{$blockname} = $this->_parse($config->{$block}->{$blockname}, \@newcontent); $config->{$block}->{$blockname} = $this->_parse($this->_hashref(), \@newcontent); } $this->_backlast($blockname); @@ -1408,6 +1434,14 @@ this feature off by setting B<-CComments> to a false value('no', 0, 'off'). By default B<-CComments> is turned on. + +=item B<-BackslashEscape> + +If you turn on this parameter, a backslash can be used to escape any special +character within configurations. + +By default it is turned off. + =back @@ -1625,6 +1659,26 @@ be stored in a hashref and therefore be overwritten if a block occurs once more. +=head1 EXPICIT EMPTY BLOCKS + +Beside the notation of blocks mentioned above it is possible to use +explicit empty blocks. + +Normally you would write this in your config to define an empty +block: + + + + +To save writing you can also write: + + + +which is the very same as above. This works for normal blocks and +for named blocks. + + + =head1 IDENTICAL OPTIONS You may have more than one line of the same option with different values. @@ -1915,7 +1969,7 @@ I recommend you to read the following documentations, which are supplied with pe =head1 COPYRIGHT -Copyright (c) 2000-2003 Thomas Linden +Copyright (c) 2000-2004 Thomas Linden This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -1932,7 +1986,7 @@ Thomas Linden =head1 VERSION -2.24 +2.25 =cut diff --git a/General/Extended.pm b/General/Extended.pm index 01f250c..7482c5d 100644 --- a/General/Extended.pm +++ b/General/Extended.pm @@ -1,7 +1,7 @@ # # Config::General::Extended - special Class based on Config::General # -# Copyright (c) 2000-2003 Thomas Linden . +# Copyright (c) 2000-2004 Thomas Linden . # All Rights Reserved. Std. disclaimer applies. # Artificial License, same as perl itself. Have fun. # @@ -522,7 +522,7 @@ values under the given key will be overwritten. =head1 COPYRIGHT -Copyright (c) 2000-2003 Thomas Linden +Copyright (c) 2000-2004 Thomas Linden This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/General/Interpolated.pm b/General/Interpolated.pm index a1839db..06db12e 100644 --- a/General/Interpolated.pm +++ b/General/Interpolated.pm @@ -278,7 +278,7 @@ L =head1 COPYRIGHT Copyright 2001 by Wei-Hon Chen Eplasmaball@pchome.com.twE. -Copyright 2002 by Thomas Linden . +Copyright 2002-2004 by Thomas Linden . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/MANIFEST b/MANIFEST index 2f1511e..a4d9ec5 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,6 +1,19 @@ Changelog General/Extended.pm +General/Interpolated.pm General.pm MANIFEST Makefile.PL README +t/cfg.16 +t/cfg.17 +t/cfg.19 +t/cfg.2 +t/cfg.3 +t/cfg.4 +t/cfg.5 +t/cfg.6 +t/cfg.7 +t/cfg.8 +t/run.t +t/test.rc diff --git a/Makefile.PL b/Makefile.PL index 78956ee..562d42d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -2,6 +2,7 @@ use ExtUtils::MakeMaker; WriteMakefile( - 'NAME' => 'Config::General', - 'VERSION_FROM' => 'General.pm', # finds $VERSION + 'NAME' => 'Config::General', + 'VERSION_FROM' => 'General.pm', # finds $VERSION + 'clean' => { FILES => 't/cfg.out t/test.cfg *~ t/~' }, ); diff --git a/README b/README index 281a0e4..0ea06af 100644 --- a/README +++ b/README @@ -104,4 +104,4 @@ AUTHOR VERSION - 2.24 + 2.25