From: Shawn M Moore Date: Tue, 10 Jun 2008 04:42:06 +0000 (+0000) Subject: Replace is_class_loaded with version from Class::MOP X-Git-Tag: 0.04~47 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf1340491e6b319464aafb33c00c272ce60857ba;p=gitmo%2FMouse.git Replace is_class_loaded with version from Class::MOP --- diff --git a/lib/Mouse.pm b/lib/Mouse.pm index bfe4be7..ff3da1e 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -100,12 +100,28 @@ sub is_class_loaded { return 0 if ref($class) || !defined($class) || !length($class); - no strict 'refs'; - return 1 if defined ${"${class}::VERSION"} || defined @{"${class}::ISA"}; - foreach my $symbol (keys %{"${class}::"}) { - next if substr($symbol, -2, 2) eq '::'; - return 1 if defined &{"${class}::${symbol}"}; + # walk the symbol table tree to avoid autovififying + # \*{${main::}{"Foo::"}} == \*main::Foo:: + + my $pack = \*::; + foreach my $part (split('::', $class)) { + return 0 unless exists ${$$pack}{"${part}::"}; + $pack = \*{${$$pack}{"${part}::"}}; } + + # check for $VERSION or @ISA + return 1 if exists ${$$pack}{VERSION} + && defined *{${$$pack}{VERSION}}{SCALAR}; + return 1 if exists ${$$pack}{ISA} + && defined *{${$$pack}{ISA}}{ARRAY}; + + # check for any method + foreach ( keys %{$$pack} ) { + next if substr($_, -2, 2) eq '::'; + return 1 if defined *{${$$pack}{$_}}{CODE}; + } + + # fail return 0; }