From: Dave Rolsky Date: Sat, 12 Sep 2009 22:23:37 +0000 (-0500) Subject: Do not return anything from load_class. X-Git-Tag: 0.93~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7716a8f9e4be04083165acaa98b71b7d0ce9134c;p=gitmo%2FClass-MOP.git Do not return anything from load_class. The existing return value was goofy (metaclass object or class name). We can always return the class name, but why bother? --- diff --git a/Changes b/Changes index 394a672..b204afb 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,12 @@ Next * mop.c - Applied an MS VC++ compilation fix from Taro Nishino. RT #48072 + * Class::MOP + - The load_class function no longer returns a value, since it's return + value was confusing (either a metaclass object or a class name). It + either loads a class or dies trying. Addresses RT #45883. (Dave + Rolsky) + 0.92_01 Thu, Sep 10, 2009 * Class::MOP::Package - Backwards compatibility tweaks to XS for 5.8.1. (Goro Fuji) diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 73231bf..3ea4fbd 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -132,8 +132,9 @@ sub _try_load_one_class { } sub load_class { - my $class = load_first_existing_class($_[0]); - return get_metaclass_by_name($class) || $class; + load_first_existing_class($_[0]); + + return; } sub _is_valid_class_name { @@ -911,8 +912,7 @@ Note that these are all called as B. This will load the specified C<$class_name>, if it is not already loaded (as reported by C). This function can be used in place of tricks like C or using C -unconditionally. This will return the metaclass of C<$class_name> if -one exists, otherwise it will return C<$class_name>. +unconditionally. =item B diff --git a/t/083_load_class.t b/t/083_load_class.t index 0b5a0e3..76be045 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 36; +use Test::More tests => 32; use Test::Exception; require Class::MOP; @@ -23,9 +23,7 @@ throws_ok { Class::MOP::load_class('__PACKAGE__') } qr/__PACKAGE__\.pm.*\@INC/, 'errors sanely on __PACKAGE__.pm'; -my $meta = Class::MOP::load_class('BinaryTree'); -ok($meta, "successfully loaded the class BinaryTree"); -is($meta->name, "BinaryTree", "load_class returns the metaclass"); +Class::MOP::load_class('BinaryTree'); can_ok('BinaryTree' => 'traverse'); do { @@ -34,9 +32,11 @@ do { }; -my $ret = Class::MOP::load_class('Class'); -ok($ret, "this should not die!"); -is( $ret, "Class", "class name returned" ); +{ + local $@; + eval { Class::MOP::load_class('Class') }; + ok( ! $@, 'load_class never dies' ); +} ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" ); @@ -80,8 +80,6 @@ lives_ok { use metaclass; } -isa_ok( Class::MOP::load_class("Lala"), "Class::MOP::Class", "when an object has a metaclass it is returned" ); - lives_ok { 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');