On 1/7/15 2:18 PM, Diab Jerius wrote:
> Hi!
> 
> I've attached some example code which exhibits (to my thinking) an
> unexpected collision between inheritance and composition. I'm using
> Moo v. 1.006001.
> 
> There is a base role (R0) which provides a method, track().
> 
> The role is consumed by another role (R1) which is consumed by a class
> (C1), each of which modifies track().
> 
> C1->new->track exhibits the correct series of modifications.
> 
> C2 is a class which inherits from C1 and also modifies track().
> 
> C2->new->track also exhibits the correct behavior with regard to the
> modifications.
> 
> C3 is a class which inherits from C1, modifies track(), and consumes R0.
> 
> C3->new->track seems to completely ignore its parent class.
> 
> The code outputs the packages whose modification was performed.  I'm
> getting this
> 
> C1:     R1    C1
> C2:     R1    C1    C2
> C3:     C3
> 
> I expected the result for C3 to be
> 
> C3:     R1    C1    C3
> 
> The order of C3's consumption of R0 and extension of C1 doesn't change
> the results.
> 
> What confuses me is that track() calls up the inheritance chain, so
> that any version of track() which ends up in C3 should know enough to
> call C1's track, and thus see the modifications made at that level.
> 
> Please let me know if I'm missing something here!
> 
> Thanks,
> 
> Diab
> 

The problem here is that you are trying to call the superclass of a
role.  next::method and its brethren don't work in roles.  If the role
wants to call the superclass of whatever class it is consumed by, it
needs to use an around modifier.

Reply via email to