Multiple inheritance is great, and Perl handles it just fine if you have a clear understanding of your hereditary hierarchy and some potential errors (such as those described in perldoc perltoot ). However, he does not discuss the prohibition of using fields pragmas with multiple inheritance. In fact, I cannot find documentation about this at all ...
Here is an illustration:
package Parent1; use fields 'field1'; package Parent2; use fields 'field2'; package Child; use base qw(Parent1 Parent2);
Error with the error: "Unable to multiply the inheritance of fields in ..."
This does not work, even if both parents have the same fields .. even if they are provably the same, because they come from grandfather and grandmother:
package Grandparent; use fields qw(field1); package Parent1; use base 'Grandparent'; package Parent2; use base 'Grandparent'; package Child; use base qw(Parent1 Parent2);
One lie for the correct implementation of this method is the invariant that the index of the field in the child always coincides with the index in its parent. I'm not sure if this requirement is really necessary, however ... unlike C ++, where an object can be accessed using a pointer typed for a parent, Perl always knows the actual type of an object when working by its reference (indeed, fields pseudohash is essentially a vtable stored on every instance of an object). And especially in the second example above, the fields inherited from each parent come from both parents, so they can be added together and there is no conflicting index.
I am sure there are other problems, but I have not found them yet.
Can anyone with some knowledge of the internal Perl components comment on this?
Ether source share