in reply to Re^2: $object->UnrelatedPackage::some_subroutine()
in thread $object->UnrelatedPackage::some_subroutine()

So I should stop using SUPER and should definitely avoid TheDamian's NEXT?

Of course not.

SUPER:: is part of perl's OO system, and a built in pseudo-package. So as far as I am concerned, it is a different story.

As for NEXT, thats up to you if you want to use it. No doubt that TheDamian knows what he is doing, but that's a pretty crazy module. Personally I just try to avoid designing anything which would need it in the first place.

However, what the OP was actually talking about was basically abusing a hole in perl's module/object system (at least thats what I see it as). The OP is actually talking about bascially using this to allow any random blessed object to become the first argument in a function, not a method. This is different from the controlled method dispatching of SUPER and NEXT.

-stvn

Replies are listed 'Best First'.
Re^4: $object->UnrelatedPackage::some_subroutine()
by tilly (Archbishop) on Feb 19, 2005 at 02:55 UTC
    The OP was talking about exactly the trick that makes NEXT:: work. The fact that the result is a controlled method dispatch merely underscores that there is a legitimate reason to use this feature. True, SUPER:: is built-in and works differently, but there is no reason that it couldn't have been built using the same technique.

    Personally I, like you, use SUPER:: and not NEXT::. But that's because I avoid multiple inheritance, and so have no reason to use NEXT::. If I used multiple inheritance, I would likely reverse and use NEXT:: instead of SUPER:: because SUPER:: does something that is fairly obviously the Wrong Thing to do.

    I agree with you that there is a definite possibility of abuse in this feature. I'm even inclined to believe that most people who're using it are more likely to cause themselves grief than they are to benefit significantly. However many abusible features in Perl are also capable, when used in a disciplined way, of helping make code saner. For that reason I'm somewhat hesitant to say, "Never do this." I might be inclined to discourage people from using a feature. But I generally hesitate before saying never to do so.

      The OP was talking about exactly the trick that makes NEXT:: work.

      In a way, but not exactly. The OP was refering to using this trick to make $dbh be the first argument in a function (not a method).

      NEXT is all about controlled method dispatch.

      For the record, I do agree with you, many of perl's dark corners can be very useful. But only if used in a sane way. What the OP is proposing (using a dark corner of the object system to call functions in a funny way) is not a sane use of this feature/bug/dark-corner.

      -stvn
        Point. I saw that the OP had discovered the "dispatch an object to anywhere that you want" functionality, and didn't pay too close of attention to what object and where it was going.

        I still don't consider the dispatch trick to be a bad thing to know about. But I'd agree that this is not a good use of it. (Though it isn't really all that bad, other than its being a pointless way to give something a different syntax.)