in reply to Whats wrong with symbol refs here?

What's wrong with using AUTOLOAD?

rdfield

Replies are listed 'Best First'.
Re: Re: Whats wrong with symbol refs here?
by Anonymous Monk on Feb 05, 2002 at 09:54 UTC
    Was using it at first. I thought it might be faster without the autoloader... if there are many child classes all the lookups would take more time than just creating real methods once at init. At least that seems to make sense.
      What do you mean 'just creating real methods once'?? AutoLoader can create the methods once (during the first call) then you can goto the method (this is considered a 'good' goto). I'm also not saying this is better than your way, the only advantage to this way is that the method never gets created if its never called.

        This is what I was referring to in my other writeup in this thread

        A real life example cut and paste from a production module :

        sub AUTOLOAD { my ( $self, $arg ) = @_; no strict 'refs'; (my $method = $AUTOLOAD ) =~ s/^.*:://; if ( exists $self->{_data}->{$method} ) { *{$AUTOLOAD} = sub { my ( $self, $arg ) = @_; if ( defined $arg ) { $self->{_data}->{$method} = $arg; } return $self->{_data}->{$method}; }; } else { croak qq%Can't locate object method $method via package % . __PA +CKAGE__ ; } goto &{$AUTOLOAD}; }

        /J\

      If you were concerned about performance, you wouldn't be using OO, see perltoot.

      rdfield