From: gfx Date: Thu, 1 Oct 2009 06:22:39 +0000 (+0900) Subject: Tweaks X-Git-Tag: 0.37_01~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3aac966d5b498bf4adcb8681f59343ae8409c9e5;p=gitmo%2FMouse.git Tweaks --- diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index deee325..d8d9d82 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -204,6 +204,7 @@ sub load_first_existing_class { } # taken from Class/MOP.pm +my %is_class_loaded_cache; sub _try_load_one_class { my $class = shift; @@ -212,7 +213,7 @@ sub _try_load_one_class { confess "Invalid class name ($display)"; } - return if is_class_loaded($class); + return undef if $is_class_loaded_cache{$class} ||= is_class_loaded($class); my $file = $class . '.pm'; $file =~ s{::}{/}g; @@ -233,14 +234,12 @@ sub load_class { return 1; } -my %is_class_loaded_cache; + sub is_class_loaded { my $class = shift; return 0 if ref($class) || !defined($class) || !length($class); - return 1 if $is_class_loaded_cache{$class}; - # walk the symbol table tree to avoid autovififying # \*{${main::}{"Foo::"}} == \*main::Foo:: @@ -252,15 +251,15 @@ sub is_class_loaded { } # check for $VERSION or @ISA - return ++$is_class_loaded_cache{$class} if exists $pack->{VERSION} + return 1 if exists $pack->{VERSION} && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} }; - return ++$is_class_loaded_cache{$class} if exists $pack->{ISA} + return 1 if exists $pack->{ISA} && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0; # check for any method foreach my $name( keys %{$pack} ) { my $entry = \$pack->{$name}; - return ++$is_class_loaded_cache{$class} if ref($entry) ne 'GLOB' || defined *{$entry}{CODE}; + return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE}; } # fail