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;
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::
}
# 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
}
}
- no strict 'refs';
- *{ __PACKAGE__ . '::get_linear_isa'} = $impl;
+
+ no warnings 'once';
+ *get_linear_isa = $impl;
}
{ # taken from Sub::Identify
}
# taken from Class/MOP.pm
-sub _is_valid_class_name {
+sub is_valid_class_name {
my $class = shift;
return 0 if ref($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)";
}