Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • The closest I've come up with so far is this:

    #!/usr/bin/perl -l

    use strict;
    use warnings;


        package KillMeNow;
        sub whee { return 'whee!' }
        sub new { bless {}, shift }


        package DontKillMe;
        sub whee { return 'asdfasdf' }


        package KillMeLater;
        @KillMeLater::ISA = 'KillMeNow';
        use overload '%{}' => sub {
            @KillMeLater::ISA =
              rand 1 > .5

  • We need support for coderefs @ISA, like in @INC :)
    life is short
    • Yeah, we were talking about that here at work. It would have solved an annoying little problem here (well, more of a hack to get around some buggy CPAN code).

  • What effect do you really need? You could use an AUTOLOAD which can build a dispatch path and query it on a per-object basis. Or you could generate a new package for each object with the proper path to which calls are delegated by the apparent class. Fixing isa() would not be too difficult, I think.

    This would not affect @ISA, though, if you need that to work.
  • Why would you want to do that?
  • I use instance-based modifications to classes by using Moose and MooseX::Object::Pluggable which I wrote. The basic idea is to use Class::MOP to generate an anonymous class that has feature XYZ you want that inherits from your original class. sounds like you already thought of it, but it works quite nicely and easily with the introspection
  • ... and why do you think that necesarily needs to involve changing @ISA?

    @ISA is just an array store used by the default implementation of the ->isa method to determine is something isa something else, and by the method resolved.

    If you want to fake being an object, them perhaps just overload ->isa?

    Or then there's a Decorator object...

    I'm not sure why making objects do weird things needs to involve @ISA.
    • It's not that I want to have different instances with different inheritance trees. I just want to know if it can be done. It's a matter of curiosity, that's all.