- 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 <dmitry@koteroff.ru>.

	 - applied patch by Danial Pearce <danial@infoxchange.net.au>
	   which adds the -BackslashEscape parameter to enable
	   general escaping of special characters using the 
	   backslash.

	 - fixed bug reported by Harold van Oostrom <cpan@lanceerplaats.nl>:
	   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 <eric@openthought.net>:
	   now block statements like this are allowed: "<directory blah/>"
	   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:
	      <directory blah>
	      </directory>

	 - fixed Makefile.PL: it cleans now files generated by 'make test'
	   properly. reported by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

	 - updated MANIFEST (in fact I did this some years ago the last time!)
	   also reported by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>


git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@51 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2009-10-10 16:30:01 +00:00
parent 2a0006a8d8
commit 8f517dd929
7 changed files with 126 additions and 27 deletions

View File

@@ -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 <dmitry@koteroff.ru>.
- applied patch by Danial Pearce <danial@infoxchange.net.au>
which adds the -BackslashEscape parameter to enable
general escaping of special characters using the
backslash.
- fixed bug reported by Harold van Oostrom <cpan@lanceerplaats.nl>:
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 <eric@openthought.net>:
now block statements like this are allowed: "<directory blah/>"
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:
<directory blah>
</directory>
- fixed Makefile.PL: it cleans now files generated by 'make test'
properly. reported by: Dagfinn Ilmari Manns<6E>ker <ilmari@ilmari.org>
- updated MANIFEST (in fact I did this some years ago the last time!)
also reported by: Dagfinn Ilmari Manns<6E>ker <ilmari@ilmari.org>
2.24 2.24
- fixed Bug #3869 (rt.cpan.org) reported by - fixed Bug #3869 (rt.cpan.org) reported by
"Mike Depot" <mdepot@comcast.net> "Mike Depot" <mdepot@comcast.net>

View File

@@ -5,7 +5,7 @@
# config values from a given file and # config values from a given file and
# return it as hash structure # return it as hash structure
# #
# Copyright (c) 2000-2003 Thomas Linden <tom@daemon.de>. # Copyright (c) 2000-2004 Thomas Linden <tom@daemon.de>.
# All Rights Reserved. Std. disclaimer applies. # All Rights Reserved. Std. disclaimer applies.
# Artificial License, same as perl itself. Have fun. # Artificial License, same as perl itself. Have fun.
# #
@@ -18,7 +18,7 @@ use strict;
use Carp; use Carp;
use Exporter; use Exporter;
$Config::General::VERSION = "2.24"; $Config::General::VERSION = "2.25";
use vars qw(@ISA @EXPORT); use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter); @ISA = qw(Exporter);
@@ -68,6 +68,8 @@ sub new {
CComments => 1, # by default turned on 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 StrictObjects => 1, # be strict on non-existent keys in OOP mode
StrictVars => 1, # be strict on undefined variables in Interpolate mode StrictVars => 1, # be strict on undefined variables in Interpolate mode
@@ -167,6 +169,9 @@ sub new {
elsif ($#param == 0) { elsif ($#param == 0) {
# use of the old style # use of the old style
$self->{ConfigFile} = $param[0]; $self->{ConfigFile} = $param[0];
if (ref($self->{ConfigFile}) eq "HASH") {
$self->{ConfigHash} = delete $self->{ConfigFile};
}
} }
else { else {
# this happens if $#param == -1,1 thus no param was given to new! # this happens if $#param == -1,1 thus no param was given to new!
@@ -336,6 +341,8 @@ sub _open {
sub _read { sub _read {
# #
# store the config contents in @content # store the config contents in @content
# and prepare it somewhat for easier parsing later
# (comments, continuing lines, and stuff)
# #
my($this, $fh, $flag) = @_; my($this, $fh, $flag) = @_;
my(@stuff, @content, $c_comment, $longline, $hier, $hierend, @hierdoc); my(@stuff, @content, $c_comment, $longline, $hier, $hierend, @hierdoc);
@@ -425,11 +432,34 @@ sub _read {
next if /^\s*$/; next if /^\s*$/;
# look for multiline option, indicated by a trailing backslash
my $extra = $this->{BackslashEscape} ? '(?<!\\\\)' : '';
if (/$extra\\$/) {
chop;
s/^\s*//;
$longline .= $_;
next;
}
# remove the \ char in front of masked "#", if any # remove the \ from all characters if BackslashEscape is turned on
s/\\#/#/g; if ($this->{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, "</${block}>";
next;
}
# look for here-doc identifier # 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 ### any "normal" config lines from now on
### ###
@@ -476,11 +496,16 @@ sub _read {
else { else {
# look for include statement(s) # look for include statement(s)
my $incl_file; 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*<<include\s+(.+?)>>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) { if (/^\s*<<include\s+(.+?)>>\s*$/i || (/^\s*include\s+(.+?)\s*$/i && $this->{UseApacheInclude})) {
$incl_file = $1; $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} # include the file from within location of $this->{configfile}
$this->_open( $incl_file ); $this->_open( catfile($path, $incl_file) );
} }
else { else {
# include the file from within pwd, or absolute # include the file from within pwd, or absolute
@@ -589,13 +614,15 @@ sub _parse {
$config->{$option} = $this->_parse_value($option, $value); $config->{$option} = $this->_parse_value($option, $value);
} }
else { 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 { 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 { else {
# the first occurence of this particular named block # 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); $config->{$block}->{$blockname} = $this->_parse($this->_hashref(), \@newcontent);
} }
$this->_backlast($blockname); $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. 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 =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:
<driver Apache>
</driver>
To save writing you can also write:
<driver Apache/>
which is the very same as above. This works for normal blocks and
for named blocks.
=head1 IDENTICAL OPTIONS =head1 IDENTICAL OPTIONS
You may have more than one line of the same option with different values. 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 =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 This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. modify it under the same terms as Perl itself.
@@ -1932,7 +1986,7 @@ Thomas Linden <tom@daemon.de>
=head1 VERSION =head1 VERSION
2.24 2.25
=cut =cut

View File

@@ -1,7 +1,7 @@
# #
# Config::General::Extended - special Class based on Config::General # Config::General::Extended - special Class based on Config::General
# #
# Copyright (c) 2000-2003 Thomas Linden <tom@daemon.de>. # Copyright (c) 2000-2004 Thomas Linden <tom@daemon.de>.
# All Rights Reserved. Std. disclaimer applies. # All Rights Reserved. Std. disclaimer applies.
# Artificial License, same as perl itself. Have fun. # Artificial License, same as perl itself. Have fun.
# #
@@ -522,7 +522,7 @@ values under the given key will be overwritten.
=head1 COPYRIGHT =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 This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. modify it under the same terms as Perl itself.

View File

@@ -278,7 +278,7 @@ L<Config::General>
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright 2001 by Wei-Hon Chen E<lt>plasmaball@pchome.com.twE<gt>. Copyright 2001 by Wei-Hon Chen E<lt>plasmaball@pchome.com.twE<gt>.
Copyright 2002 by Thomas Linden <tom@daemon.de>. Copyright 2002-2004 by Thomas Linden <tom@daemon.de>.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. modify it under the same terms as Perl itself.

View File

@@ -1,6 +1,19 @@
Changelog Changelog
General/Extended.pm General/Extended.pm
General/Interpolated.pm
General.pm General.pm
MANIFEST MANIFEST
Makefile.PL Makefile.PL
README 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

View File

@@ -2,6 +2,7 @@ use ExtUtils::MakeMaker;
WriteMakefile( WriteMakefile(
'NAME' => 'Config::General', 'NAME' => 'Config::General',
'VERSION_FROM' => 'General.pm', # finds $VERSION 'VERSION_FROM' => 'General.pm', # finds $VERSION
'clean' => { FILES => 't/cfg.out t/test.cfg *~ t/~' },
); );

2
README
View File

@@ -104,4 +104,4 @@ AUTHOR
VERSION VERSION
2.24 2.25