Subject: | Make the tests pass |
There was a few places where the order of the hash mattered...
Subject: | 0001-modules-always-return-sorted.patch |
From eb6d0d94934e64d90a6b93c2b39e44e7f6913285 Mon Sep 17 00:00:00 2001
From: Yanick Champoux <yanick@babyl.dyndns.org>
Date: Thu, 20 Nov 2014 12:04:21 -0500
Subject: [PATCH] modules() always return sorted
... so that the order doesn't change from one run to the next
Also process all constants, not just a random one.
---
lib/Config/Constants.pm | 65 ++++++++++++++++++++-------------------
lib/Config/Constants/Perl.pm | 2 +-
t/20_Config_Constants_Perl_test.t | 2 +-
t/30_Config_Constants_XML_test.t | 2 +-
4 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/lib/Config/Constants.pm b/lib/Config/Constants.pm
index b4b3264..2a8b9e4 100644
--- a/lib/Config/Constants.pm
+++ b/lib/Config/Constants.pm
@@ -97,40 +97,41 @@ sub _load_module {
my $module = shift;
no strict 'refs';
foreach my $constant ($CONFIG->constants($module)) {
- my ($name, $value) = each %{$constant};
- if (defined &{"${module}::$name"}) {
- # since this already exists, we
- # assume that it is a valid constant
- # and that our module was already
- # loaded
- no warnings;
- *{"${module}::$name"} = sub () { $value };
- delete $CHECKED_CONSTANTS{$module}->{$name};
- }
- else {
- # since this does not exist, then our
- # module may not have been loaded yet.
- # but in order to determine this,
- # we have to see if the constants have
- # been registered yet ...
- if (exists $CHECKED_CONSTANTS{$module}) {
- # this means our module was loaded first, and
- # the constants were registered. Now, if
- # we do not see this particular constant
- # in here, then we need to throw an exception
- die "Unknown constant for '$module' -> ($name)"
- unless exists $CHECKED_CONSTANTS{$module}->{$name};
+ while( my ($name, $value) = each %{$constant} ) {
+ if (defined &{"${module}::$name"}) {
+ # since this already exists, we
+ # assume that it is a valid constant
+ # and that our module was already
+ # loaded
+ no warnings;
+ *{"${module}::$name"} = sub () { $value };
+ delete $CHECKED_CONSTANTS{$module}->{$name};
}
else {
- # being in this block means that is is unlikely
- # the conf has been loaded yet, so we will
- # just create our constants, and make a note
- # of each of them so that they can be
- # checked later on.
- $UNCHECKED_CONSTANTS{$module} = { $name => undef };
- *{"${module}::$name"} = sub () { $value };
- }
- }
+ # since this does not exist, then our
+ # module may not have been loaded yet.
+ # but in order to determine this,
+ # we have to see if the constants have
+ # been registered yet ...
+ if (exists $CHECKED_CONSTANTS{$module}) {
+ # this means our module was loaded first, and
+ # the constants were registered. Now, if
+ # we do not see this particular constant
+ # in here, then we need to throw an exception
+ die "Unknown constant for '$module' -> ($name)"
+ unless exists $CHECKED_CONSTANTS{$module}->{$name};
+ }
+ else {
+ # being in this block means that is is unlikely
+ # the conf has been loaded yet, so we will
+ # just create our constants, and make a note
+ # of each of them so that they can be
+ # checked later on.
+ $UNCHECKED_CONSTANTS{$module}{$name} = 1;
+ *{"${module}::$name"} = sub () { $value };
+ }
+ }
+ }
}
}
diff --git a/lib/Config/Constants/Perl.pm b/lib/Config/Constants/Perl.pm
index 55efd0e..b6154d6 100644
--- a/lib/Config/Constants/Perl.pm
+++ b/lib/Config/Constants/Perl.pm
@@ -25,7 +25,7 @@ sub _init {
$self->{_config} = $config;
}
-sub modules { keys %{(shift)->{_config}} }
+sub modules { sort keys %{(shift)->{_config}} }
sub constants {
my ($self, $module) = @_;
diff --git a/t/20_Config_Constants_Perl_test.t b/t/20_Config_Constants_Perl_test.t
index 6f96c19..53cfb30 100644
--- a/t/20_Config_Constants_Perl_test.t
+++ b/t/20_Config_Constants_Perl_test.t
@@ -21,7 +21,7 @@ can_ok('Config::Constants::Perl', 'new');
is_deeply(
[ $config->modules ],
- [ 'Foo::Bar', 'Bar::Baz' ],
+ [ 'Bar::Baz', 'Foo::Bar' ],
'... got the right modules');
is_deeply(
diff --git a/t/30_Config_Constants_XML_test.t b/t/30_Config_Constants_XML_test.t
index 69d909b..99b974d 100644
--- a/t/30_Config_Constants_XML_test.t
+++ b/t/30_Config_Constants_XML_test.t
@@ -21,7 +21,7 @@ can_ok('Config::Constants::XML', 'new');
is_deeply(
[ $config->modules ],
- [ 'Foo::Bar', 'Bar::Baz' ],
+ [ 'Bar::Baz', 'Foo::Bar', ],
'... got the right modules');
is_deeply(
--
1.9.1