From: Stevan Little Date: Tue, 15 Apr 2008 22:55:09 +0000 (+0000) Subject: c3 tests and details X-Git-Tag: 0_64~73 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=77a143bafdd524b01eb35af7d47c2a1d5554b5e2;p=gitmo%2FClass-MOP.git c3 tests and details --- diff --git a/Changes b/Changes index 8b3297a..fd58507 100644 --- a/Changes +++ b/Changes @@ -1,12 +1,17 @@ Revision history for Perl extension Class-MOP. 0.55 + ~ added MRO::Compat as a dependency ~ + ~ all classes now have proper c3 support ~ + * Class::MOP::Class - rebless_instance now returns the instance it has just blessed, this is mostly to facilitate chaining - set the attr correctly in rebless_instance when it has no init_arg + - tweaked &linear_isa and &class_precedence_list + to support c3 classes. 0.54 Fri. March, 14, 2008 * Class::MOP diff --git a/Makefile.PL b/Makefile.PL index 85db423..065acd5 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,6 +8,7 @@ license 'perl'; requires 'Scalar::Util' => '1.18'; requires 'Sub::Name' => '0.02'; +requires 'MRO::Compat' => '0.05'; requires 'Carp' => '0'; build_requires 'Test::More' => '0.62'; diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 68c3d47..c7f8807 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -512,6 +512,7 @@ sub linearized_isa { sub class_precedence_list { my $self = shift; + my $name = $self->name; unless (Class::MOP::IS_RUNNING_ON_5_10()) { # NOTE: @@ -521,15 +522,26 @@ sub class_precedence_list { # blow up otherwise. Yes, it's an ugly hack, better # suggestions are welcome. # - SL - ($self->name || return)->isa('This is a test for circular inheritance') + ($name || return)->isa('This is a test for circular inheritance') } - ( - $self->name, - map { - $self->initialize($_)->class_precedence_list() - } $self->superclasses() - ); + # if our mro is c3, we can + # just grab the linear_isa + if (mro::get_mro($name) eq 'c3') { + return @{ mro::get_linear_isa($name) } + } + else { + # NOTE: + # we can't grab the linear_isa for dfs + # since it has all the duplicates + # already removed. + return ( + $name, + map { + $self->initialize($_)->class_precedence_list() + } $self->superclasses() + ); + } } ## Methods diff --git a/t/200_Class_C3_compatibility.t b/t/200_Class_C3_compatibility.t index bf091d4..481b56e 100644 --- a/t/200_Class_C3_compatibility.t +++ b/t/200_Class_C3_compatibility.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More; +use Test::More tests => 8; =pod @@ -14,34 +14,32 @@ approach to method resolution. =cut BEGIN { - eval "use Class::C3"; - plan skip_all => "Class::C3 required for this test" if $@; - plan tests => 7; + use_ok('Class::MOP'); } { package Diamond_A; - Class::C3->import; + use mro 'c3'; use metaclass; # everyone will just inherit this now :) sub hello { 'Diamond_A::hello' } } { package Diamond_B; + use mro 'c3'; use base 'Diamond_A'; - Class::C3->import; } { package Diamond_C; - Class::C3->import; + use mro 'c3'; use base 'Diamond_A'; sub hello { 'Diamond_C::hello' } } { package Diamond_D; + use mro 'c3'; use base ('Diamond_B', 'Diamond_C'); - Class::C3->import; } # we have to manually initialize @@ -50,7 +48,8 @@ BEGIN { Class::C3::initialize(); is_deeply( - [ Class::C3::calculateMRO('Diamond_D') ], +# [ Class::C3::calculateMRO('Diamond_D') ], + [ Diamond_D->meta->class_precedence_list ], [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ], '... got the right MRO for Diamond_D');