From: Jesse Luehrs Date: Thu, 10 Jun 2010 23:25:06 +0000 (-0500) Subject: handle fixing when the child class already does all necessary roles X-Git-Tag: 1.08~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b85607ab6b19221c14fe167884cf0726bf1d51a3;p=gitmo%2FMoose.git handle fixing when the child class already does all necessary roles --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 4f2a829..20874bf 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -525,6 +525,14 @@ sub _reconcile_roles_for_metaclass { my @role_differences = $self->_role_differences( $class_meta_name, $super_meta_name, ); + + # handle the case where we need to fix compatibility between a class and + # its parent, but all roles in the class are already also done by the + # parent + # see t/050/054.t + return Class::MOP::class_of($super_meta_name) + unless @role_differences; + return Moose::Meta::Class->create_anon_class( superclasses => [$super_meta_name], roles => \@role_differences, diff --git a/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t new file mode 100644 index 0000000..6190faa --- /dev/null +++ b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t @@ -0,0 +1,46 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo::Meta::Constructor1; + use Moose::Role; +} + +{ + package Foo::Meta::Constructor2; + use Moose::Role; +} + +{ + package Foo; + use Moose; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor1'] }, + ); +} + +{ + package Foo::Sub; + use Moose; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor2'] }, + ); + extends 'Foo'; +} + +{ + package Foo::Sub::Sub; + use Moose; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor2'] }, + ); + ::lives_ok { extends 'Foo::Sub' } "doesn't try to fix if nothing is needed"; +} + +done_testing;