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
requires 'Scalar::Util' => '1.18';
requires 'Sub::Name' => '0.02';
+requires 'MRO::Compat' => '0.05';
requires 'Carp' => '0';
build_requires 'Test::More' => '0.62';
sub class_precedence_list {
my $self = shift;
+ my $name = $self->name;
unless (Class::MOP::IS_RUNNING_ON_5_10()) {
# NOTE:
# 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
use strict;
use warnings;
-use Test::More;
+use Test::More tests => 8;
=pod
=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
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');