On 11 April 2014 12:59, Thalhammer, Jeffrey Ryan <
[email protected]> wrote:
> From memory, consume the interface/interface-role after all other
> declarations and role consumption, e.g.
>
> I get that. Here’s an example:
>
> package FooRole;
> use Moose::Role;
>
> requires qw(open close read write);
>
> requires qw(eenie meenie);
>
> #----------------------------------------------
>
> package FooWrapper;
> use Moose;
>
> has delegate => (
> is => 'ro',
> isa => 'Foo',
> handles => [ qw(open close read write) ],
> required => 1,
> );
>
> sub eenie {...}
> sub meenie {...}
>
> with qw(FooRole);
>
> That only works if the with comes after the delegation has been
> established. The trouble is, I only want to write that list qw(open close
> read write) once. I could put that in say, @FooRole::METHODS_TO_DELEGATE.
> But
> that variable probably won’t be available to me until *after* FooRole has
> been loaded by the with. At that point, it is too late, and it won’t
> compile because the class hasn’t satisfied the role.
>
Given the example, considering you want to do that in more than one place,
is there a reason why you don't instead have a role that you compose in for
that attribute?
package FooRole;
use Moose::Role;
requires qw(open close read write);
requires qw(eenie meenie);
#----------------------------------------------
package DelegatedAttribute;
use Moose::Role;
has delegate => (
is => 'ro',
isa => 'Foo',
handles => [ qw(open close read write) ],
required => 1,
);
#---------------------------------
package FooWrapper;
use Moose;
sub eenie {...}
sub meenie {...}
with qw(DelegatedAttribute);
with qw(FooRole);
?
If you wanted you could make that parametrizable so that the attribute name
wasn't fixed, but the delegates it provided were.
--
Kent