Dear Perlmonks, I have what I feel is a relatively fundamental question about Perl OO, regarding multiple inheritance: can I bless a ref into multiple packages?

The specific problem I'm trying to solve involves DBIx::Class. This ORM maps SQL table rows to instances of a class/package associated with the table. In order to achieve subclassing, one can store the additional attributes for the subclasses in the same table as the base class. Whenever a table row is retrieved, the method inflate_result() of the corresponding class is called - this method then blesses the table row (stored as a hashref) into the correct subclass (normally by looking at a specific table attribute that contains e.g. the name of the subclass).

E.g. a vehicles table containes rows that correspond to instances of the class Vehicle. A 'type' attribute could contain information about the type of vehicle and be used by Vehicle::inflate_result() to bless the vehicle row into an instances of Vehicle::Car or Vehicle::Airplane.

Now, I have a table containing entries that inherit from two base classes. These classes have subclasses, and I want to bless the table row hashref into two different subclasses, one for each base class - I have attributes like 'type1' and 'type2', not just one 'type'.

Now my question: How can I bless a hashref into two different packages? I know Perl can do multiple inheritance via the @ISA array, but I need to use bless to associate with two unrelated classes.

In reply to Multiple Inheritance (DBIx::Class) by Cybris

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.