sub inject_all {
require Class::MOP;
inject_fake_metaclass_for($_) for grep $_ ne 'Moo::Object', keys %Moo::MAKERS;
+ inject_fake_metaclass_for($_) for keys %Moo::Role::INFO;
}
sub inject_fake_metaclass_for {
return Class::MOP::get_metaclass_by_name($name) if $DID_INJECT{$name};
require Moose; require Moo; require Moo::Role;
Class::MOP::remove_metaclass_by_name($name);
- my ($meta, $attr_specs) = do {
+ my ($am_role, $meta, $attr_specs) = do {
if (my $info = $Moo::Role::INFO{$name}) {
- (Moose::Meta::Role->initialize($name), $info->{attributes})
+ (1, Moose::Meta::Role->initialize($name), $info->{attributes})
} else {
my $specs = Moo->_constructor_maker_for($name)->all_attribute_specs;
- (Moose::Meta::Class->initialize($name), $specs);
+ (0, Moose::Meta::Class->initialize($name), $specs);
}
};
my %methods = %{Role::Tiny->_concrete_methods_of($name)};
push @attrs, $meta->add_attribute($name => %{$attr_specs->{$name}});
}
}
- foreach my $attr (@attrs) {
- foreach my $method (@{$attr->associated_methods}) {
- $method->{body} = $name->can($method->name);
+ unless ($am_role) {
+ foreach my $attr (@attrs) {
+ foreach my $method (@{$attr->associated_methods}) {
+ $method->{body} = $name->can($method->name);
+ }
}
}
$DID_INJECT{$name} = 1;
})->generate_method($target, $name, \%spec);
$INFO{$target}{attributes}{$name} = \%spec;
};
+ if ($INC{'Moo/HandleMoose.pm'}) {
+ Moo::HandleMoose::inject_fake_metaclass_for($target);
+ }
goto &Role::Tiny::import;
}
is(Foo->new(one => 1, THREE => 3)->one, 1, 'Accessor still works');
+$meta = Moose::Meta::Class->initialize('Spoon');
+
+$meta->superclasses('Moose::Object');
+
+Moose::Util::apply_all_roles($meta, 'Bar');
+
+my $spoon = Spoon->new(four => 4);
+
+is($spoon->four, 4, 'Role application ok');
+
done_testing;