use Carp 'confess';
use Scalar::Util 'weaken';
-use Sub::Identify 'get_code_info';
-
BEGIN {
local $@;
eval {
: sub () { 1 };
}
-our $VERSION = '0.64_06';
+our $VERSION = '0.65';
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
# after that everything is loaded, if we're allowed try to load faster XS
# versions of various things
-unless ($ENV{CLASS_MOP_NO_XS}) {
+_try_load_xs() or _load_pure_perl();
+
+sub _try_load_xs {
+ return if $ENV{CLASS_MOP_NO_XS};
+
my $e = do {
local $@;
eval {
require XSLoader;
+ # just doing this - no warnings 'redefine' - doesn't work
+ # for some reason
+ local $^W = 0;
__PACKAGE__->XSLoader::load($XS_VERSION);
};
$@;
};
die $e if $e && $e !~ /object version|loadable object/;
+
+ return $e ? 0 : 1;
}
+sub _load_pure_perl {
+ require Sub::Identify;
+ Sub::Identify->import('get_code_info');
+}
+
+
{
# Metaclasses are singletons, so we cache them here.
# there is no need to worry about destruction though
sub load_class {
my $class = shift;
- if (ref($class) || !defined($class) || !length($class)) {
+ unless ( _is_valid_class_name($class) ) {
my $display = defined($class) ? $class : 'undef';
confess "Invalid class name ($display)";
}
return get_metaclass_by_name($class) if defined wantarray;
}
+sub _is_valid_class_name {
+ my $class = shift;
+
+ return 0 if ref($class);
+ return 0 unless defined($class);
+ return 0 unless length($class);
+
+ return 1 if $class =~ /^\w+(?:::\w+)*$/;
+
+ return 0;
+}
+
sub is_class_loaded {
my $class = shift;