From: Tomas Doran Date: Wed, 22 Oct 2008 14:51:14 +0000 (+0000) Subject: Change load_first_existing_class to return the name of the loaded class, rather than... X-Git-Tag: 0.68~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d8153bdba02bd1106eebe0f79b8be91e4315b64;p=gitmo%2FClass-MOP.git Change load_first_existing_class to return the name of the loaded class, rather than it's metaclass instance. --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 4587469..b4cf30e 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -125,8 +125,7 @@ sub load_first_existing_class { } } - return get_metaclass_by_name($found) || $found - if $found; + return $found if $found; confess join( "\n", @@ -155,7 +154,8 @@ sub _try_load_one_class { } 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 { @@ -950,9 +950,8 @@ B 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 diff --git a/t/083_load_class.t b/t/083_load_class.t index dd49458..d68166e 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -75,9 +75,10 @@ lives_ok { 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';