biome icon indicating copy to clipboard operation
biome copied to clipboard

Stacking Roles doesn't seem to work when resolving attributes

Open cjfields opened this issue 15 years ago • 2 comments

Stacking roles (using roles within roles) doesn't seem to work when attributes are required, even when the 'with' keyword is used after attributes are declared. See the Biome::Role::Location::Does_* classes (interfaces), the Biome::Role::Location::Simple_/Split classes (their role interfaces), and Biome::Location::_ (the classes).

This does work when combining roles in a base class, however, which is a workaround though a bit tedious, as it involves repeatedly adding the same lines every time in cases where the implemention and interface roles are both needed.

This does work with Moose, however, so I need to whittle this down to a small test case.

cjfields avatar Jun 16 '10 15:06 cjfields

I traced the problem to this. Roles consuming roles can't define attributes; this is a well-known problem in Moose that isn't easy to fix. It has been TODO'd for now.

The below code will blow up when combined into the class b/c MyRole1 and myRole2 are both consumed into RoleTest at the same time; MyRole1 isn't consumed into MyRole2 first prior to consuming into RoleTest.



{
package MyRole1;

use Biome::Role;

requires 'foo', 'bar','att1', 'att2';

no Biome::Role;

}
###############################

{
# import Moose magic through meta class (no need to import separately)
package MyRole2;

use Biome::Role;

with 'MyRole1';

requires 'bah';

has 'att1'  => (isa => 'Str', is => 'rw');

sub foo { 1 }

no Biome::Role;

}

###############################

{
package RoleTest;

use Biome;

has 'att2'    => (isa => 'Int', is => 'rw');

with 'MyRole2';

sub bar { 2 }

sub baz { 42 };

sub bah {98.6 };

no Biome;
}

cjfields avatar Jun 16 '10 18:06 cjfields

Blocking on an outstanding Moose bug

cjfields avatar Jun 16 '10 20:06 cjfields