问题
Let A, B, C, D be Moose classes.
Let both B and C inherit from A. Let also D inherit from both B and C.
What will happen with "duplicate" properties (properties from A present in both B and C)?
回答1:
See Method Dispatch Order in Modern Perl:
Method dispatch order (or method resolution order or MRO) is obvious for single-parent classes. Look in the object's class, then its parent, and so on until you find the method or run out of parents. Classes which inherit from multiple parents (multiple inheritance)—Hovercraft extends both Boat and Car—require trickier dispatch. Reasoning about multiple inheritance is complex. Avoid multiple inheritance when possible. (emphasis mine)
Perl 5 uses a depth-first method resolution strategy. It searches the class of the first named parent and all of that parent's parents recursively before searching the classes of subsequent parents. The mro pragma (Pragmas) provides alternate strategies, including the C3 MRO strategy which searches a given class's immediate parents before searching any of their parents.
来源:https://stackoverflow.com/questions/38133739/multiple-inheritance-from-a-shared-base-class-in-perl-moose