in reply to oop - obvious AUTOLOAD question

The current package, where AUTOLOAD is defined is where
the subroutine is created.

This is also the namespace in
which the created routine exists. This is because you stripped
off the explicit package name. You could specify the namespace
if you wish. Why? Efficiency maybe. Caching the
creations of AUTOLOAD is often a reasonable idea.
But pushing the result back down the inheritance tree
may not be reasonable.

In an AUTOLOAD sub you should usually avoid handling routines
that have a name in all uppercase. Perl has special functions
like DESTROY, these subs are all named in all caps.

Also isn't the goto pointless.

Replies are listed 'Best First'.
Re: Re: oop - obvious AUTOLOAD question
by fglock (Vicar) on Sep 25, 2002 at 18:51 UTC

    The goto after AUTOLOAD is a shortcut, so that you don't have to make a new stack frame, etc, when you pass control to the new method.

    update:oops. This was a response to node 200692 but something went wrong with the links. thanks footpad

    Edited: ~Wed Sep 25 22:30:46 2002 (GMT) by footpad: Reparented, per Consideration.

      In my tests a goto &rout is slower than a plain rout.

      I don't usually care much about micro-optimizations, but
      given that AUTOLOAD is a slug, it seems a bad time to
      imply that an arcane construct is faster than a normal call.

        it seems a bad time to imply that an arcane construct is faster than a normal call.

        I don't think anyone attempted to imply anything about the efficiency of using goto. As you almost pointed out, if you are using AUTOLOAD in the first place, efficiency probably isn't your primary consideration. The real point to it is correctness. Using goto hides the fact that the code is AUTOLOAD'd. The AUTOLOAD'd code can then do things like call caller() without worrying or wondering whether it was called directly.

        -sauoq
        "My two cents aren't worth a dime.";