mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-16 12:11:02 +01:00
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:
43
General.pm
43
General.pm
@@ -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) {
|
||||
|
||||
@@ -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
1
t/notincluded.conf.not
Normal file
@@ -0,0 +1 @@
|
||||
honk=NONONO
|
||||
15
t/run.t
15
t/run.t
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user