Multiple inheritance in Perl is major pain in the ass. Partially because of lack of language support to do OO, and partially because people tend to populate their objects from the constructor, instead of using separate methods for that. If for instance, B and C used a constructor that looked like:
sub new { bless {}, shift; }
and then initialization routines like this:
package B; sub init { my $self = shift; @$self {qw /_foo _bar/} = @_; } sub init { my $self = shift; @$self {qw /_baz _qux/} = @_; }
your package could look like:
package C; use A; use B; our @ISA = qw /B C/; sub new {bless {}, shift} sub init { my $self = shift; $self -> B::init(@_[0, 1]); $self -> C::init(@_[2, 3]); }
Of course, it gets worse if one or more of the packages uses a filehandle, or an array to implement to object, or if two of the inheriting classes use the key (but to find out, you have to break encapsulation).

In short, multiple inheritance in Perl is only possible if all of the classes you inherit have been implemented with this in mind (most classes don't - noone really teaches for this possibility, it's much easier to dismiss it with the statement that multiple inheritance is not done), or if you are lucky and willing to break encapsulation.

It seems that for your B and C, you're lucky, and can do it by breaking encapsulation.

As for question 3, sometimes it's good to admit defeat, and use a language with better OO support than Perl. (Which are easy to find, as it's hard to find a language with worse support)


In reply to Re: Understanding 'Multiple Inheritance' by Anonymous Monk
in thread Understanding 'Multiple Inheritance' by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.