Re: Using attributes for 'requires'

[email protected] (Darren Duncan)
Newsgroups perl.moose
Message-ID <[email protected]>
Yuval Kogman wrote (in private):
> 2009/1/19 Darren Duncan <[email protected]>:
>> So, any similar hacks to help with that, prior to Moose roles being smart
>> enough to deal with this?
> 
> with delegation you can just put the role after the attribute declaration:
> 
> has foo => ( ..., handles => [qw(bar)] );
> 
> with 'Role::That::Requires::bar';
> 
> The error was thrown only if 'bar' was an accessor method, which in
> this case it won't be. This may sound arbitrary, because it is, which
> is why it's now gone ;-)

Thank you Yuval Kogman,

That simple rearrangement did make the error concerning delegated methods go away.

Also thank you benh,

The simple hack you mentioned also worked for me with different attributes.

So between the 2 hacks I updated 4 attributes over 2 role-composing classes and 
eliminated 7 now-redundant explicit accessor methods.  And in the future I'm 
sure more will be constructed.

I also noticed the 2 hacks do not seem to work in concert for the same 
attribute, say with an attribute for which we want both role-satisfying 
accessors and role-satisfying delegates.  Now none of my attributes needed both, 
fortunately, but this is still an outstanding issue.

Thanks again. -- Darren Duncan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.