diff -rubN Config-General-2.33/General.pm Config-General-2.33-PG/General.pm
--- Config-General-2.33/General.pm 2007-04-17 14:50:43.000000000 -0400
+++ Config-General-2.33-PG/General.pm 2007-08-21 20:38:35.000000000 -0400
@@ -57,6 +57,7 @@
IncludeRelative => 0,
IncludeDirectories => 0,
IncludeGlob => 0,
+ IncludeAgain => 0,
AutoLaunder => 0,
AutoTrue => 0,
AutoTrueFlags => {
@@ -448,9 +449,10 @@
}
}
elsif (-e _) {
- if (exists $this->{files}->{$configfile} ) {
+ if (exists $this->{files}->{$configfile} and not $this->{IncludeAgain} ) {
# do not read the same file twice, just return
# FIXME: should we croak here, when some "debugging" is enabled?
+ warn "File $configfile already loaded. Use -IncludeAgain to load it again.\n";
return;
}
else {
@@ -1378,6 +1380,18 @@
is often more desirable than including a directory with B<-IncludeDirectories>.
+=item B<-IncludeAgain>
+
+If set to a true value, you will be able to include a sub-configfile
+multiple times. With the default, false, you will get a warning about
+duplicate includes and only the first include will succeed.
+
+Reincluding a configfile can be useful if it contains data that you want to
+be present in multiple places in the data tree. See the example under
+L</INCLUDES>.
+
+Note, however, that there is currently no check for include recursion.
+
=item B<-ConfigPath>
As mentioned above, you can use this variable to specify a search path for relative
@@ -2164,7 +2178,32 @@
Include statements will be ignored within C-Comments and here-documents.
+By default, a config file will only be included the first time it is
+referenced. If you wish to include a file in multiple places, set
+</-IncludeAgain> to true.
+
+Example:
+
+ # main.cfg
+ <object billy>
+ class=Some::Class
+ <printers>
+ include printers.cfg
+ </printers>
+ # ...
+ </object>
+ <object bob>
+ class=Another::Class
+ <printers>
+ include printers.cfg
+ </printers>
+ # ...
+ </object>
+
+Now C<printers.cfg> will be include in both the C<billy> and C<bob> objects.
+You will have to be careful to not recursively include a file. Behaviour
+in this case is undefined.
=head1 COMMENTS
diff -rubN Config-General-2.33/MANIFEST Config-General-2.33-PG/MANIFEST
--- Config-General-2.33/MANIFEST 2007-02-23 17:12:30.000000000 -0500
+++ Config-General-2.33-PG/MANIFEST 2007-08-21 20:25:47.000000000 -0400
@@ -26,8 +26,11 @@
t/cfg.20.b
t/cfg.20.c
t/run.t
-t/test.rc.out
t/cfg.34
+t/apache-include.conf
+t/dual-include.conf
+t/include.t
+t/included.conf
MANIFEST
example.cfg
Makefile.PL
diff -rubN Config-General-2.33/t/apache-include.conf Config-General-2.33-PG/t/apache-include.conf
--- Config-General-2.33/t/apache-include.conf 1969-12-31 19:00:00.000000000 -0500
+++ Config-General-2.33-PG/t/apache-include.conf 2007-08-21 20:14:12.000000000 -0400
@@ -0,0 +1,6 @@
+<bit one>
+ include t/included.conf
+</bit>
+<bit two>
+ include t/included.conf
+</bit>
diff -rubN Config-General-2.33/t/dual-include.conf Config-General-2.33-PG/t/dual-include.conf
--- Config-General-2.33/t/dual-include.conf 1969-12-31 19:00:00.000000000 -0500
+++ Config-General-2.33-PG/t/dual-include.conf 2007-08-21 20:08:23.000000000 -0400
@@ -0,0 +1,6 @@
+<bit one>
+ <<include t/included.conf>>
+</bit>
+<bit two>
+ <<include t/included.conf>>
+</bit>
diff -rubN Config-General-2.33/t/include.t Config-General-2.33-PG/t/include.t
--- Config-General-2.33/t/include.t 1969-12-31 19:00:00.000000000 -0500
+++ Config-General-2.33-PG/t/include.t 2007-08-21 20:15:26.000000000 -0400
@@ -0,0 +1,52 @@
+# -*-perl-*-
+# testscript for Config::General's -IncludeAgain
+#
+# needs to be invoked using the command "make test" from
+# the Config::General source directory.
+#
+# Under normal circumstances every test should succeed.
+
+
+use Data::Dumper;
+use Test::More tests => 8;
+#use Test::More qw(no_plan);
+
+### 1
+BEGIN { use_ok "Config::General"};
+require_ok( 'Config::General' );
+
+
+### Include both
+my $conf = Config::General->new( -ConfigFile => "t/dual-include.conf",
+ -IncludeAgain => 1 );
+ok( $conf, "Loaded the config file" );
+
+my %C = $conf->getall;
+is_deeply( \%C, { bit => { one => { honk=>'bonk' },
+ two => { honk=>'bonk' }
+ } }, "Included twice" );
+
+
+
+### Include once
+diag "\nPlease ignore the following message about IncludeAgain";
+$conf = Config::General->new( "t/dual-include.conf" );
+ok( $conf, "Loaded the config file" );
+
+%C = $conf->getall;
+
+is_deeply( \%C, { bit => { one => { honk=>'bonk' },
+ two => {}
+ } }, "Included once-only" );
+
+### apache-style Include
+$conf = Config::General->new( -ConfigFile => "t/apache-include.conf",
+ -IncludeAgain => 1,
+ -UseApacheInclude => 1 );
+ok( $conf, "Loaded the config file" );
+
+%C = $conf->getall;
+
+is_deeply( \%C, { bit => { one => { honk=>'bonk' },
+ two => { honk=>'bonk' }
+ } }, "Apache-style include" );
diff -rubN Config-General-2.33/t/included.conf Config-General-2.33-PG/t/included.conf
--- Config-General-2.33/t/included.conf 1969-12-31 19:00:00.000000000 -0500
+++ Config-General-2.33-PG/t/included.conf 2007-08-21 20:10:39.000000000 -0400
@@ -0,0 +1 @@
+honk=bonk