}
}
- return get_metaclass_by_name($found) || $found
- if $found;
+ return $found if $found;
confess join(
"\n",
}
sub load_class {
- load_first_existing_class($_[0]);
+ my $class = load_first_existing_class($_[0]);
+ return get_metaclass_by_name($class) || $class;
}
sub _is_valid_class_name {
Given a list of class names, this function will attempt to load each
one in turn.
-If it finds a class it can load, it will return that class's
-metaclass. If none of the classes can be loaded, it will throw an
-exception.
+If it finds a class it can load, it will return that class' name.
+If none of the classes can be loaded, it will throw an exception.
=back
isa_ok( Class::MOP::load_class("Lala"), "Class::MOP::Class", "when an object has a metaclass it is returned" );
lives_ok {
- isa_ok(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Class::MOP::Class", 'Load_classes first param ok, metaclass returned');
- isa_ok(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Class::MOP::Class", 'Load_classes second param ok, metaclass returned');
+ is(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Lala", 'load_first_existing_class 1/2 params ok, class name returned');
+ is(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Lala", 'load_first_existing_class 2/2 params ok, class name returned');
} 'load_classes works';
+
throws_ok {
Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist")
} qr/Could not load class \(Does::Not::Exist.*Could not load class \(Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception';