Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacking Roles doesn't seem to work when resolving attributes #1

Open
cjfields opened this issue Jun 16, 2010 · 2 comments
Open

Stacking Roles doesn't seem to work when resolving attributes #1

cjfields opened this issue Jun 16, 2010 · 2 comments

Comments

@cjfields
Copy link
Owner

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
Copy link
Owner Author

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
Copy link
Owner Author

Blocking on an outstanding Moose bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant