in reply to Re: wat ::DESTROY will do
in thread wat ::DESTROY will do

Your last sentence is interesting: do you mean this for performance reasons or just for added readability? Or (as it always is with my guesses) for something different from both?

Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

Don't fool yourself.

Replies are listed 'Best First'.
Re^3: wat ::DESTROY will do
by brian_d_foy (Abbot) on May 23, 2005 at 10:59 UTC

    Once perl finds a real method, it doesn't have to go back through @ISA looking for AUTOLOADs. Also, you don't have to make DESTROY a special case. Avoid special cases when possible.

    --
    brian d foy <brian@stonehenge.com>

      Unless someone else's AUTOLOAD will handle DESTROY...

      Since, as you know, all other packages automatically derive from UNIVERSAL, if one of them uses AUTOLOAD to handle DESTROY, which is odd in and of itself, your UNIVERSAL::DESTROY method will short-circuit that since, as you say, perl will find UNIVERSAL::DESTROY before looking for Some::Package::AUTOLOAD.

        Packages don't really derive from UNIVERSAL: it's just the last entry in @ISA. It's not like Object in Java or some other languages. UNIVERSAL will always be after everything else.

        It's true that some other AUTOLOAD may handle DESTROY, and in that case you wouldn't want to do that. I typically don't let AUTOLOAD handle special methods like DESTROY, though.

        --
        brian d foy <brian@stonehenge.com>