From: Jesse Luehrs Date: Thu, 7 Oct 2010 23:11:22 +0000 (-0500) Subject: ignore composite roles during role reconciliation X-Git-Tag: 1.16~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e15f532cceab75fb6ddd8780ed790f139b3a909;p=gitmo%2FMoose.git ignore composite roles during role reconciliation --- diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index ac48606..74ce8b3 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -322,16 +322,20 @@ sub _reconcile_roles_for_metaclass { sub _role_differences { my ($class_meta_name, $super_meta_name) = @_; - my @super_role_metas = $super_meta_name->meta->can('calculate_all_roles_with_inheritance') - ? $super_meta_name->meta->calculate_all_roles_with_inheritance - : $super_meta_name->meta->can('calculate_all_roles') - ? $super_meta_name->meta->calculate_all_roles - : (); - my @role_metas = $class_meta_name->meta->can('calculate_all_roles_with_inheritance') - ? $class_meta_name->meta->calculate_all_roles_with_inheritance - : $class_meta_name->meta->can('calculate_all_roles') - ? $class_meta_name->meta->calculate_all_roles - : (); + my @super_role_metas + = grep { !$_->isa('Moose::Meta::Role::Composite') } + $super_meta_name->meta->can('calculate_all_roles_with_inheritance') + ? $super_meta_name->meta->calculate_all_roles_with_inheritance + : $super_meta_name->meta->can('calculate_all_roles') + ? $super_meta_name->meta->calculate_all_roles + : (); + my @role_metas + = grep { !$_->isa('Moose::Meta::Role::Composite') } + $class_meta_name->meta->can('calculate_all_roles_with_inheritance') + ? $class_meta_name->meta->calculate_all_roles_with_inheritance + : $class_meta_name->meta->can('calculate_all_roles') + ? $class_meta_name->meta->calculate_all_roles + : (); my @differences; for my $role_meta (@role_metas) { push @differences, $role_meta diff --git a/t/060_compat/005_composite_metaroles.t b/t/060_compat/005_composite_metaroles.t new file mode 100755 index 0000000..570ce30 --- /dev/null +++ b/t/060_compat/005_composite_metaroles.t @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; +use Test::Moose; + +{ + package Foo::Role; + use Moose::Role; +} + +{ + package Bar::Role; + use Moose::Role; +} + +{ + package Parent; + use Moose; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { class => ['Foo::Role'] }, + ); +} + +{ + package Child; + use Moose; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { class => ['Foo::Role', 'Bar::Role'] }, + ); + ::lives_ok { extends 'Parent' }; +} + +with_immutable { + isa_ok('Child', 'Parent'); + isa_ok(Child->meta, Parent->meta->_real_ref_name); + does_ok(Parent->meta, 'Foo::Role'); + does_ok(Child->meta, 'Foo::Role'); + does_ok(Child->meta, 'Bar::Role'); +} 'Parent', 'Child'; + +done_testing;