Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday February 01, 2009
03:27 PM

Subtle Inheritance Trap

[ #38387 ]

Multiple Inheritance can be tricky, particularly when you get wild and crazy and have an unbalanced inheritance graph:

{
    package Platypus;
    our @ISA = qw<SpareParts Duck>;
    package Duck;
    our @ISA = 'SpareParts';
    sub quack {}
    package SpareParts;
    our @ISA = 'Animal';
    sub quack {}
    package Animal;
}

See the bug? It's right there, staring you in the face.

Does this help?

         Animal
           |
      SpareParts
       |    |
       |   Duck
       |    |
      Platypus

As both 'SpareParts' and 'Duck' have a 'quack' method, the one in 'Duck' is unreachable if the Platypus inherits from the SpareParts first.

my $platypus = Class::Sniff->new({
    class => 'Platypus',
});
explain $platypus->unreachable;

That correctly reported Duck::quack as unreachable. I'm really quite astonished that it seems to be working.

Oh, and I've already removed an unneeded method in TAP::Parser which I detected with this.

I've now added support for listing all classes which multiply inherit and there's optional 'UNIVERSAL' support, if needed.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • While you're analysing object/inheritance trees, one case that was in my old non-CPAN equivalent tested for the following.

    Class: Foo::Bar
    Method: Foo->Bar

    Resulting bug?

    Foo::Bar->baz parses as Foo::Bar()->baz, forcing you to do Foo::Bar::->baz instead (or something like that...)