From: Brian Cassidy Date: Thu, 23 Aug 2007 12:30:41 +0000 (+0000) Subject: added a simple cache to the perl parser so it can load the same file twice (RT #28812) X-Git-Tag: v0.08~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=83020fbd096a2523ceedbb3ea1e9b99e030f994c added a simple cache to the perl parser so it can load the same file twice (RT #28812) --- diff --git a/Changes b/Changes index 17e7c67..3f6d619 100644 --- a/Changes +++ b/Changes @@ -1,27 +1,31 @@ Revision history for Config-Any +0.08 Wed Aug 23 2007 + pass config options to each parser + fix for loading the same perl config twice (RT #28812) + 0.07 Mon Feb 26 2007 promote 0.06_01 to non-dev. 0.06_01 Sun Feb 25 19:23:00 2007 - fixed bug [rt.cpan.org #25143] make tests fails - - t/61_features.t had 1 more test added than was set to skip if the INI parser - was not installed. Fixed by s/9/10/ on the skip() line. + fixed bug [rt.cpan.org #25143] make tests fails + - t/61_features.t had 1 more test added than was set to skip if the INI parser + was not installed. Fixed by s/9/10/ on the skip() line. 0.06 Thu Feb 22 21:05:00 2007 - removed reference to Test::Exception, bumped version number + removed reference to Test::Exception, bumped version number 0.05 Wed Feb 21 22:00:00 2007 - added support for: - 'force_plugins => [ qw(Config::Any::Foo Config::Any::Blah) ]' parameter - to load_(files|stems) - $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY - boolean, defaulting - to on, controlling whether to map spaces in INI section headings - to nested hashrefs - both as requested by Evan Kaufman + added support for: + - 'force_plugins => [ qw(Config::Any::Foo Config::Any::Blah) ]' parameter + to load_(files|stems) + - $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY - boolean, defaulting + to on, controlling whether to map spaces in INI section headings + to nested hashrefs + both as requested by Evan Kaufman 0.04 Mon Aug 7 15:15:15 2006 - Initial CPAN-worthy release with proper test suite + Initial CPAN-worthy release with proper test suite 0.01 - 0.03 dev releases diff --git a/lib/Config/Any/Perl.pm b/lib/Config/Any/Perl.pm index 6c20ced..1dd1499 100644 --- a/lib/Config/Any/Perl.pm +++ b/lib/Config/Any/Perl.pm @@ -3,6 +3,8 @@ package Config::Any::Perl; use strict; use warnings; +my %cache; + =head1 NAME Config::Any::Perl - Load Perl config files @@ -42,7 +44,14 @@ Attempts to load C<$file> as a Perl file. sub load { my $class = shift; my $file = shift; - return eval { require $file }; + my $content; + + unless( $content = $cache{ $file } ) { + $content = eval { require $file }; + $cache{ $file } = $content; + } + + return $content; } =head1 AUTHOR diff --git a/t/53-perl.t b/t/53-perl.t index 4914075..5e51b41 100644 --- a/t/53-perl.t +++ b/t/53-perl.t @@ -1,11 +1,17 @@ -use Test::More tests => 2; +use Test::More tests => 3; use Config::Any::Perl; -my $config = eval { Config::Any::Perl->load( 't/conf/conf.pl' ) }; +my $file = 't/conf/conf.pl'; +my $config = eval { Config::Any::Perl->load( $file ) }; SKIP: { - skip "Couldn't Load Perl plugin", 2 if $@; + skip "Couldn't Load Perl plugin", 3 if $@; + ok( $config ); is( $config->{ name }, 'TestApp' ); + + my $config_2 = eval { Config::Any::Perl->load( $file ) }; + + is_deeply( $config_2, $config, 'multiple loads of perl configs' ); }