confess "Could not load class ($class) because : $e" if $e;
}
- # initialize a metaclass if necessary
- unless (does_metaclass_exist($class)) {
- my $e = do { local $@; eval { Class::MOP::Class->initialize($class) }; $@ };
- confess "Could not initialize class ($class) because : $e" if $e;
- }
-
- return get_metaclass_by_name($class) if defined wantarray;
+ get_metaclass_by_name($class) || $class if defined wantarray;
}
sub _is_valid_class_name {
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 19;
+use Test::More tests => 22;
use Test::Exception;
require Class::MOP;
sub method {}
};
-ok(Class::MOP::load_class('Class'), "this should not die!");
+
+my $ret = Class::MOP::load_class('Class');
+ok($ret, "this should not die!");
+is( $ret, "Class", "class name returned" );
+
+ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" );
throws_ok {
Class::MOP::load_class('FakeClassOhNo');
ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)');
}
"a class with just constants is still a class";
+
+{
+ package Lala;
+ use metaclass;
+}
+
+isa_ok( Class::MOP::load_class("Lala"), "Class::MOP::Class", "when an object has a metaclass it is returned" );