From: Yuval Kogman Date: Tue, 2 Sep 2008 15:25:11 +0000 (+0000) Subject: Class::MOP::load_class no longer creates a metaclass for non Moose/MOP classes X-Git-Tag: 0.66~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c7e2bf4bc415bcde0fa1a50e2d19f6362066a45;p=gitmo%2FClass-MOP.git Class::MOP::load_class no longer creates a metaclass for non Moose/MOP classes --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index c1f7642..7755431 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -121,13 +121,7 @@ sub load_class { 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 { diff --git a/t/083_load_class.t b/t/083_load_class.t index b248686..c9ee05f 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 19; +use Test::More tests => 22; use Test::Exception; require Class::MOP; @@ -30,7 +30,12 @@ do { 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'); @@ -49,3 +54,10 @@ lives_ok { 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" );