On Mon, Mar 04, 2013 at 04:12:21AM -0800, Ovid wrote: > From: Jesse Luehrs <d...@tozt.net> > >To: Pedro Melo <m...@simplicidade.org> > >Cc: moose <moose@perl.org> > >Sent: Friday, 1 March 2013, 18:05 > >Subject: Re: Role1 with attribute matches requires on Role2 > > > >On Fri, Mar 01, 2013 at 04:56:57PM +0000, Pedro Melo wrote: > >> Hi, > >> > >> I keep getting bitten by this, and I was wondering if this is > >> something that will be solved eventually, or its something that would > >> be nice to solve but it is actually tricky to do, or just that I'm > >> doing it wrong. > >> > >> I have two roles, R1 and R2. R1 defines a attribute ctx. R2 requires a > >> 'ctx'. > >> > >> If I use the two roles on a class C, with a single "with 'R1', 'R2';" I get > >> > >> 'R1|R2' requires the method 'ctx' to be implemented by 'C' > >> > >> I can work around it with two "with 'R1'; with 'R2';". But I loose all > >> the other protections wrt duplicate methods I might have in R1 and R2. > >> > >> Opinions? > > > >This is something that we'd like to fix - the problem is mainly that > >role accessors aren't generated until they are composed into a class, > >but role application composes roles together before composing them into > >the class. What we really need to do is provide a way for roles to say > >"I'm going to generate a method of this name", which we would be able to > >query during the role summation process (we can't actually generate the > >methods themselves because doing so requires an instance metaclass, > >which only classes have). > > > >Patches to fix this would be appreciated. > > > Out of curiosity, how is this handled in the internals? Does the role > composition do a simple ->can() check for methods? If so, during composition, > could has() fake a forward declaration? > > { > package Foo; > sub bar; > } > say "yes" if Foo->can('bar'); > > You're not actually creating the method yet, but you're promising that it > will be there.
Yes, that is another possibility. I'm not sure which way would be simpler. -doy