in reply to wat ::DESTROY will do

The AUTOLOAD subroutine does what the other posters said it will do, but by putting it in the UNIVERSAL package makes it available to every class which does not already have it own AUTOLOAD subroutine anywhere else in its @ISA tree.

The code to skip the DESTROY method is a bit odd. If one is going to mess around with a UNIVERSAL::AUTOLOAD, one can also just create a UNIVERSAL::DESTROY that doesn't do anything.

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

Replies are listed 'Best First'.
Re^2: wat ::DESTROY will do
by polettix (Vicar) on May 23, 2005 at 08:29 UTC
    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.

      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.