From: matthewt <matthewt@89-16-177-128.no-reverse-dns-set.bytemark.co.uk>
Date: Sun, 5 Dec 2010 18:53:10 +0000 (+0000)
Subject: fix _load_module to deal with subpackages correctly
X-Git-Tag: release_0.9.3~4
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ed7d68a203449b0b02ee361b02e39b6d9e798a2;p=gitmo%2FMoo.git

fix _load_module to deal with subpackages correctly
---

diff --git a/Changes b/Changes
index 5e820b5..56a0061 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+  - Fix _load_module to deal with pre-existing subpackages
+
 0.9.2 Wed Nov 17 2010
   - Add explanation of Moo's existence
   - Change @ISA setting mechanism to deal with a big in 5.10.0's get_linear_isa
diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm
index 82ecfcb..aaa903a 100644
--- a/lib/Moo/_Utils.pm
+++ b/lib/Moo/_Utils.pm
@@ -1,6 +1,7 @@
 package Moo::_Utils;
 
 sub _getglob { \*{$_[0]} }
+sub _getstash { \%{"$_[0]::"} }
 
 use strictures 1;
 use base qw(Exporter);
@@ -21,8 +22,11 @@ sub _install_modifier {
 our %MAYBE_LOADED;
 
 sub _load_module {
-  return 1 if $_[0]->can('can');
   (my $proto = $_[0]) =~ s/::/\//g;
+  return 1 if $INC{"${proto}.pm"};
+  # can't just ->can('can') because a sub-package Foo::Bar::Baz
+  # creates a 'Baz::' key in Foo::Bar's symbol table
+  return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
   require "${proto}.pm";
   return 1;
 }