Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 70111
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: chip [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.0202
Fixed in: (no value)



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 ...
From: chip [...] pobox.com
Apologies for a partial edit of the transcript. For "vis" read "mass", and for "quality" read "dumbbell".
From: chip [...] pobox.com
Also assume Attrs::Are::Massive is used in each source file.
On Sat Aug 06 22:54:05 2011, CHIPS wrote: Show quoted text
> 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'], > },
I think you want applied_attribute there, not attribute. The docs around this are pretty poor, and we're planning to clean up the API a lot in the next stable release so it's more DWIMmy.
From: chip [...] pobox.com
On Wed Aug 17 12:49:18 2011, DROLSKY wrote: Show quoted text
> I think you want applied_attribute there, not attribute.
Yes, that worked. Thanks. Doc help welcome.