Skip to content

Loading…

fix a metaclass compat bug #27

Merged
merged 4 commits into from

1 participant

@doy
Moose member
doy commented

No description provided.

@doy doy referenced this pull request in iinteractive/OX
Closed

OX can't inherit from a Bread::Board::Declare class #12

doy added some commits
@doy doy failing test for metaclass compat bug 2b23d52
@doy doy metaclass compat fixes
this should fix an issue introduced by the method conflict changes in
2.08. previously, this codepath would never be hit because it would
always have just been a conflict, but now this works for normal classes
and so it should also work for classes generated by the metaclass
compatibility fixing process.
924b3c6
@doy doy docs 89d5f65
@doy doy make this private 01f692b
@doy doy merged commit f78234b into master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 6, 2013
  1. @doy
  2. @doy

    metaclass compat fixes

    doy committed
    this should fix an issue introduced by the method conflict changes in
    2.08. previously, this codepath would never be hit because it would
    always have just been a conflict, but now this works for normal classes
    and so it should also work for classes generated by the metaclass
    compatibility fixing process.
  3. @doy

    docs

    doy committed
  4. @doy

    make this private

    doy committed
This page is out of date. Refresh to see the latest.
Showing with 92 additions and 14 deletions.
  1. +10 −0 lib/Moose/Meta/Class.pm
  2. +18 −14 lib/Moose/Util.pm
  3. +64 −0 t/metaclasses/metaclass_compat_role_conflicts.t
View
10 lib/Moose/Meta/Class.pm
@@ -212,6 +212,16 @@ sub calculate_all_roles {
grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles };
}
+sub _roles_with_inheritance {
+ my $self = shift;
+ my %seen;
+ grep { !$seen{$_->name}++ }
+ map { Class::MOP::class_of($_)->can('roles')
+ ? @{ Class::MOP::class_of($_)->roles }
+ : () }
+ $self->linearized_isa;
+}
+
sub calculate_all_roles_with_inheritance {
my $self = shift;
my %seen;
View
32 lib/Moose/Util.pm
@@ -341,20 +341,24 @@ sub _reconcile_roles_for_metaclass {
sub _role_differences {
my ($class_meta_name, $super_meta_name) = @_;
- 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 @super_role_metas = map {
+ $_->isa('Moose::Meta::Role::Composite')
+ ? (@{ $_->get_roles })
+ : ($_)
+ } $super_meta_name->meta->can('_roles_with_inheritance')
+ ? $super_meta_name->meta->_roles_with_inheritance
+ : $super_meta_name->meta->can('roles')
+ ? @{ $super_meta_name->meta->roles }
+ : ();
+ my @role_metas = map {
+ $_->isa('Moose::Meta::Role::Composite')
+ ? (@{ $_->get_roles })
+ : ($_)
+ } $class_meta_name->meta->can('_roles_with_inheritance')
+ ? $class_meta_name->meta->_roles_with_inheritance
+ : $class_meta_name->meta->can('roles')
+ ? @{ $class_meta_name->meta->roles }
+ : ();
my @differences;
for my $role_meta (@role_metas) {
push @differences, $role_meta
View
64 t/metaclasses/metaclass_compat_role_conflicts.t
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ package My::Meta::Role1;
+ use Moose::Role;
+ sub foo { 'Role1' }
+}
+BEGIN {
+ package My::Meta::Role2;
+ use Moose::Role;
+ with 'My::Meta::Role1';
+ sub foo { 'Role2' }
+}
+BEGIN {
+ package My::Extension;
+ use Moose::Exporter;
+ Moose::Exporter->setup_import_methods(
+ class_metaroles => {
+ class => ['My::Meta::Role2'],
+ },
+ );
+ $INC{'My/Extension.pm'} = __FILE__;
+}
+BEGIN {
+ package My::Meta::Role3;
+ use Moose::Role;
+}
+BEGIN {
+ package My::Extension2;
+ use Moose::Exporter;
+ Moose::Exporter->setup_import_methods(
+ class_metaroles => {
+ class => ['My::Meta::Role3'],
+ },
+ );
+ $INC{'My/Extension2.pm'} = __FILE__;
+}
+
+{
+ package My::Class1;
+ use Moose;
+ use My::Extension;
+}
+
+is(My::Class1->new->meta->foo, 'Role2');
+
+{
+ package My::Class2;
+ use Moose;
+ use My::Extension2;
+}
+{
+ package My::Class3;
+ use Moose;
+ use My::Extension;
+ extends 'My::Class2';
+}
+
+is(My::Class3->new->meta->foo, 'Role2');
+
+done_testing;
Something went wrong with that request. Please try again.