exclude union roles and same-role-as-self from metaclass inflation
[gitmo/Moo.git] / lib / Moo / Role.pm
index 72f3808..34203a8 100644 (file)
@@ -36,7 +36,9 @@ sub _inhale_if_moose {
   if (!$INFO{$role} and $INC{"Moose.pm"}) {
     if (my $meta = Class::MOP::class_of($role)) {
       $INFO{$role}{methods} = {
-        map +($_ => $role->can($_)), $meta->get_method_list
+        map +($_ => $role->can($_)),
+          grep !$meta->get_method($_)->isa('Class::MOP::Method::Meta'),
+            $meta->get_method_list
       };
       $Role::Tiny::APPLIED_TO{$role} = {
         map +($_->name => 1), $meta->calculate_all_roles
@@ -83,12 +85,23 @@ sub _make_accessors {
     require Method::Generate::Accessor;
     Method::Generate::Accessor->new
   });
+  my $con_gen = $Moo::MAKERS{$target}{constructor};
   my @attrs = @{$INFO{$role}{attributes}||[]};
   while (my ($name, $spec) = splice @attrs, 0, 2) {
+    # needed to ensure we got an index for an arrayref based generator
+    if ($con_gen) {
+      $spec = $con_gen->all_attribute_specs->{$name};
+    }
     $acc_gen->generate_method($target, $name, $spec);
   }
 }
 
+sub apply_roles_to_package {
+  my ($me, $to, @roles) = @_;
+  $me->_inhale_if_moose($_) for @roles;
+  $me->SUPER::apply_roles_to_package($to, @roles);
+}
+
 sub apply_single_role_to_package {
   my ($me, $to, $role) = @_;
   $me->_inhale_if_moose($role);