One thing that tye and I agree on is that inheritance is used far more than it should be. Now I cannot say whether this has anything to do with your problem, but when you inherit from a module whose guts you do not know, you get their implementation and your assumptions about what you can and cannot do with objects are likely to break.

But luckily it is possible to inherit the interface without running the risk of problems with the implementation. Here is a simple example showing how to do that:

package parent; use strict; sub new { return bless {}, shift; } sub talk { shift; print @_; } 1; package child; use Carp; use strict; use vars qw($AUTOLOAD); sub new { my $self = bless {}, shift; $self->{hndl} = new parent(@_); return $self; } sub AUTOLOAD { $AUTOLOAD =~ s/.*://; if (UNIVERSAL::can("parent", $AUTOLOAD)) { eval " sub $AUTOLOAD { (shift)->{hndl}->$AUTOLOAD(\@_); }"; no strict 'refs'; goto &$AUTOLOAD; } else { confess("Method $AUTOLOAD not implemented"); } } 1; package main; my $thing = new child; $thing->talk("Hello world\n"); # In the interface $thing->bye(); # Oops.
The trick is in AUTOLOAD. If you call a method that you have not defined it will see whether it can proxy it. If it can then it creates that method and goes to it. If it can't then it blows up.

UPDATE
Took out the check for DESTROY in AUTOLOAD. I could have sworn that it could be called implicitly but it wasn't when I tested? Ah well, live and learn.

UPDATE 2
I misunderstood the (non)output from the tests. DESTROY was being called after all. I just wasn't seeing the output from it.


In reply to Re (tilly) 1: Reverse Inheritance Irritance by tilly
in thread Reverse Inheritance Irritance by deprecated

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.