Hi all-

I've begun using Roles to declare interfaces -- that is, nothing more than
a list of "requires". So let's say I have a Role that requires 15
attributes/methods.  In the implementation, I know that 5 of those will be
delegated to one class, 5 delegated to another, and the other 5 implemented
by the consuming class.

Rather than having to list each of the delegated attributes/methods by hand
in the consuming class, I'd like to just grab lists from the Role.
 However, I run into run-time vs. compile-time problems because I can't get
the lists from the Role until it has been composed into the class, by which
time it is too late.  I can hack around this by explicitly require-ing the
role first, but that seems really icky.

I realize this violates encapsulation a bit.  The Role should have no idea
how the consuming class might implement its attributes/methods.  But in
this situation, I feel like bending the rules just a bit for the sake of
DRY.

The only idea I have come up with so far is to declare the various
method/attribute lists in some other module completely, and then load them
into the Role/Class as needed.  I can probably make that pretty using
Moose::Exporter or Import::Into, but it basically boils down to global
variables.  Again, icky.

Can you suggest a good way to handle this?  Or maybe convince me that I'm
doing it all wrong anyway?

Thanks for your time.

-Jeff

Reply via email to