add support for apache's IncludeOptional feature

git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@104 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2015-10-11 18:37:08 +00:00
parent 4484d60098
commit 6b154a6254
4 changed files with 46 additions and 15 deletions

View File

@@ -432,13 +432,13 @@ sub _open {
# applied patch by AlexK fixing rt.cpan.org#41030
if ( !@include && defined $this->{ConfigPath} ) {
foreach my $dir (@{$this->{ConfigPath}}) {
my ($volume, $path, undef) = splitpath($basefile);
if ( -d catfile( $dir, $path ) ) {
push @include, grep { -f $_ } bsd_glob(catfile($dir, $basefile), GLOB_BRACE | GLOB_QUOTE);
last;
}
}
foreach my $dir (@{$this->{ConfigPath}}) {
my ($volume, $path, undef) = splitpath($basefile);
if ( -d catfile( $dir, $path ) ) {
push @include, grep { -f $_ } bsd_glob(catfile($dir, $basefile), GLOB_BRACE | GLOB_QUOTE);
last;
}
}
}
if (@include == 1) {
@@ -722,12 +722,29 @@ sub _read {
# bugfix rt.cpan.org#38635: support quoted filenames
if ($this->{UseApacheInclude}) {
if (/^\s*include\s*(["'])(.*?)(?<!\\)\1$/i) {
$incl_file = $2;
}
elsif (/^\s*include\s+(.+?)\s*$/i) {
$incl_file = $1;
}
my $opt = '';
if (/^\s*(include|includeoptional)\s*(["'])(.*?)(?<!\\)\2$/i) {
$incl_file = $3;
$opt = $1;
}
elsif (/^\s*(include|includeoptional)\s+(.+?)\s*$/i) {
$incl_file = $2;
$opt = $1;
}
if ($incl_file) {
if ($this->{IncludeGlob} && $opt =~ /opt/i && $incl_file !~ /[*?\[\{\\]/) {
# fix rt#107108
# glob enabled && optional include && file is not already a glob:
# turn it into a singular matching glob, like:
# "file" => "[f][i][l][e]" and:
# "dir/file" => "dir/[f][i][l][e]"
# which IS a glob but only matches that particular file. if it
# doesn't exist, it will be ignored by _open(), just what
# we'd like to have when using IncludeOptional.
my ($vol,$dirs,$file) = splitpath( $incl_file );
$incl_file = catpath($vol, $dirs, join '', map { "[$_]" } split //, $file);
}
}
}
else {
if (/^\s*<<include\s+(["'])(.+?)>>\\s*$/i) {

View File

@@ -581,7 +581,7 @@ at the bottom if it exists. You can also search partway down the tree
and ->find should return where you left off.
For example, given the values B<find (qw (A B C))> and the following
tree (</end> tags ommitted for brevity):
tree (</end> tags omitted for brevity):
<A>
<FOO>

1
t/notincluded.conf.not Normal file
View File

@@ -0,0 +1 @@
honk=NONONO

15
t/run.t
View File

@@ -8,7 +8,7 @@
use Data::Dumper;
use Test::More tests => 72;
use Test::More tests => 73;
#use Test::More qw(no_plan);
# ahem, we deliver the test code with a local copy of
@@ -462,6 +462,19 @@ is_deeply( \%C38, { bit => { one => { honk=>'bonk' },
two => { honk=>'bonk' }
} }, "Apache-style include" );
# verify fix for rt#107108, test support for IncludeOptional
my $conf38n = Config::General->new( -ConfigFile => "t/apache-include-opt.conf",
-IncludeAgain => 1, -IncludeGlob => 1,
-UseApacheInclude => 1 );
my %C38n = $conf38n->getall;
is_deeply( \%C38n, { bit => { one => { nink=>'ack' },
two => { honk=>'bonk' }
} }, "Apache-style IncludeOptional" );
#### 39 verifies bug rt#27225
# testing variable scope.
# a variable shall resolve to the value defined in the current