Subject: | Attribute metaroles do not work in roles |
I have a workaround, but this error is REALLY annoying. So "Important" is the compromise severity.
Consider an attribute metarole, set up thusly:
package Attrs::Are::Massive;
Moose::Exporter->setup_import_methods(
class_metaroles => {
attribute => ['Meta::Attribute::Massive'],
},
role_metaroles => {
attribute => ['Meta::Attribute::Massive'],
},
);
Assume that Meta::Attribute::Massive allows the attribute to have a "mass" attribute.
Now given:
package MyClass;
use Moose;
with 'MyRole';
and:
package MyRole;
use Moose::Role;
has dumbbell => ( is => 'rw', mass => 100 );
compilation of MyClass fails at role integration time.
The bit of code going boom is:
Moose::Meta::Role::Application::ToClass::apply_attributes(/usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-
64int/Moose/Meta/Role/Application/ToClass.pm:145):
145: $class->add_attribute(
146: $role->get_attribute($attribute_name)->attribute_for_class
147: );
and the error message is:
Found unknown argument(s) passed to 'quality' attribute constructor in 'Moose::Meta::Attribute': mass at
/usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Meta/Attribute.pm line 103
Moose::Meta::Attribute::new('Moose::Meta::Attribute', 'quality', 'isa', 'Num', 'definition_context',
'HASH(0xc37cf04)', 'default', 1, 'vis', ...) called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-
64int/Moose/Meta/Attribute.pm line 114
Moose::Meta::Attribute::interpolate_class_and_new('Moose::Meta::Attribute', 'quality', 'isa', 'Num',
'default', 1, 'definition_context', 'HASH(0xc37cf04)', 'is', ...) called at /usr/local/perl/lib/perl5/i486-linux-gnu-
thread-multi-64int/Moose/Meta/Role/Attribute.pm line 91
Moose::Meta::Role::Attribute::attribute_for_class('Moose::Meta::Class::__ANON__::SERIAL::15=HASH(0xc62de98)')
called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Meta/Role/Application/ToClass.pm line 145
Moose::Meta::Role::Application::ToClass::apply_attributes('Moose::Meta::Role::Application::ToClass=HASH(0xc49
1a58)', 'Moose::Meta::Role::Composite=HASH(0xc1e712c)', 'Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)')
called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Meta/Role/Application.pm line 58
Moose::Meta::Role::Application::apply('Moose::Meta::Role::Application::ToClass=HASH(0xc491a58)',
'Moose::Meta::Role::Composite=HASH(0xc1e712c)', 'Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)') called at
/usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Meta/Role/Application/ToClass.pm line 35
Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role::Application::ToClass=HASH(0xc491a58)',
'Moose::Meta::Role::Composite=HASH(0xc1e712c)', 'Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)',
'HASH(0xc3d533c)') called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Meta/Role.pm line 470
Moose::Meta::Role::apply('Moose::Meta::Role::Composite=HASH(0xc1e712c)',
'Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)') called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-
multi-64int/Moose/Util.pm line 162
Moose::Util::_apply_all_roles('Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)', undef, 'MyRole')
called at /usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Util.pm line 98
Moose::Util::apply_all_roles('Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)', 'MyRole') called at
/usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose.pm line 65
Moose::with('Moose::Meta::Class::__ANON__::SERIAL::3=HASH(0xc1b4cd4)', 'MyRole') called at
/usr/local/perl/lib/perl5/i486-linux-gnu-thread-multi-64int/Moose/Exporter.pm line 356
Moose::with('MyRole') called at ...