From: gfx Date: Sun, 20 Sep 2009 07:06:57 +0000 (+0900) Subject: Cleanup X-Git-Tag: 0.32~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a81cc7b83f688ff21284b599a81e14a44bcdf401;p=gitmo%2FMouse.git Cleanup --- diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 98d19e5..e03e12a 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -191,12 +191,11 @@ sub unimport { sub load_class { my $class = shift; - if (ref($class) || !defined($class) || !length($class)) { + if (!Mouse::Util::is_valid_class_name($class)) { my $display = defined($class) ? $class : 'undef'; confess "Invalid class name ($display)"; } - return 1 if $class eq 'Mouse::Object'; return 1 if is_class_loaded($class); (my $file = "$class.pm") =~ s{::}{/}g; @@ -207,11 +206,14 @@ 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 exists $is_class_loaded_cache{$class}; + # walk the symbol table tree to avoid autovififying # \*{${main::}{"Foo::"}} == \*main::Foo:: @@ -222,15 +224,15 @@ sub is_class_loaded { } # check for $VERSION or @ISA - return 1 if exists ${$$pack}{VERSION} + return ++$is_class_loaded_cache{$class} if exists ${$$pack}{VERSION} && defined *{${$$pack}{VERSION}}{SCALAR}; - return 1 if exists ${$$pack}{ISA} + return ++$is_class_loaded_cache{$class} 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}; + return ++$is_class_loaded_cache{$class} if defined *{${$$pack}{$_}}{CODE}; } # fail diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 4b28c07..f24c76e 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -2,7 +2,6 @@ package Mouse::Meta::Module; use strict; use warnings; -use Scalar::Util qw/blessed weaken/; use Mouse::Util qw/get_code_info/; use Carp 'confess'; diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 43bcdd9..4d27fd8 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -120,10 +120,6 @@ sub import { return; } - my $meta_method = sub{ - Mouse::Meta::Role->initialize(ref($_[0]) || $_[0]); - }; - Mouse::Meta::Role->initialize($caller)->add_method(meta => sub { return Mouse::Meta::Role->initialize(ref($_[0]) || $_[0]); }); diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 25de2ab..30eea32 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -52,8 +52,9 @@ BEGIN { } } - no strict 'refs'; - *{ __PACKAGE__ . '::get_linear_isa'} = $impl; + + no warnings 'once'; + *get_linear_isa = $impl; } { # taken from Sub::Identify @@ -100,7 +101,7 @@ BEGIN { } # taken from Class/MOP.pm -sub _is_valid_class_name { +sub is_valid_class_name { my $class = shift; return 0 if ref($class); @@ -120,7 +121,7 @@ sub load_first_existing_class { my $found; my %exceptions; for my $class (@classes) { - unless ( _is_valid_class_name($class) ) { + unless ( is_valid_class_name($class) ) { my $display = defined($class) ? $class : 'undef'; confess "Invalid class name ($display)"; }