The problem with calling multiple constructors is that it results in an object that only contains the results of the last constructor. What is really needed is a seperation of the creation and initialization steps in each class.

Here is the method I use (essentially a cut and paste from Chapter 6 of Damian Conway's excellent book Object Oriented Perl) as it applies to this particular problem:
#!/usr/bin/perl -w use strict; use Employee; my $hid = Employee->new; print "My gender is " . $hid->gender() . "\n"; print "My name is " . $hid->fullname() . "\n"; package Employee; use strict; use _Initializable; use Person; use Gender; @Employee::ISA = qw( _Initializable Person Gender ); sub _init { my $self = shift; $self->Person::_init(); $self->Gender::_init(); } 1; package Person; use strict; use _Initializable; @Person::ISA = qw( _Initializable ); sub _init { my $self = shift; $self->{FULLNAME} = "Robert Walkup"; } sub fullname { my $self = shift; return $self->{FULLNAME}; } 1; package Gender; use strict; use _Initializable; @Gender::ISA = qw( _Initializable ); sub _init { my $self = shift; $self->{GENDER} = "MALE"; } sub gender { my $self = shift; return $self->{GENDER}; } 1; package _Initializable; use strict; sub new { my $class = shift; my $self = {}; bless $self, ref($class) || $class; $self->_init(); return $self; } 1;
As you can see, the only major change is the addition of the _Initializable class to handle the creation of new objects, and the _init methods to initialize said objects. For any method other than a constructor, the options listed by lachoy above should work as advertised.

Vavoom

In reply to Re: Re: how do I do multiple inheritance by Vavoom
in thread how do I do multiple inheritance by rdww

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.