steves has asked for the wisdom of the Perl Monks concerning the following question:

I started playing with dynamic inheritance and am looking for feedback from anyone else insane enough to do this.

My first attempt mostly works. The idea behind this is really to do instance inheritance. The basic problem being this: I have a generic interface that implements 90% of a class interface. But a run-time set type in each instance determines the other 10% of the interface. To complicate matters, each instance could be derived from either the 90% parent class or one of its decendants.

The way I first tried this was to use AUTOLOAD. In there, I examine the type, change the 90% class @ISA array to include the appropriate 10% type package, then call the method I pick up doing that. But once I muck with @ISA, UNIVERSAL::can doesn't see it. I looked at the Perl source (version 5.6.1) and I see @ISA caching in there but it's unclear if that's at fault.

Any feedback on the caching or better ways to do this, or even people telling me I'm insane for doing this appreciated. I really need to play more but I figured it can't hurt to ask some monks now if it saves me work.

Replies are listed 'Best First'.
Re: dynamic inheritance
by chromatic (Archbishop) on Jan 31, 2002 at 01:57 UTC

    bikeNomad and I ran into this in his Class::Prototyped. The problem is indeed @ISA caching, and (to my knowledge) it wasn't fixed in 5.6.1. My workaround is:

    delete ${"$package\::"}{'::ISA::CACHE::'};

    where $package is the name of the package containing the modified @ISA. Of course, you might find that CPAN module interesting...

    Update: We ran into the problem while adding to @ISA, so my guess is that any changes are troublesome. It's been a while since I read the source, though.
      Out of curiosity, is the @ISA caching a problem only when you're deleting items from @ISA, or also for adding items?

      -- Frag.
      --
      "It's beat time, it's hop time, it's monk time!"

      You the man chromatic. That did the trick. Thanks for the tip. I'll check out Class::Prototyped.

      Perl maintains its record with me. In addition to There's More Than One Way To Do It my other Perl motto is There's Always A Way To Do It.