develooper Front page | perl.moose | Postings from January 2015

Moo: inheritance conflicting with role composition?

Thread Next
From:
Diab Jerius
Date:
January 7, 2015 19:19
Subject:
Moo: inheritance conflicting with role composition?
Message ID:
CADpyd5CfPd=8-Bb5EjCd9a-xhyA3ns8-MQ93dkr7e6HWUVSHBg@mail.gmail.com
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About