in reply to (tye)Re: Need help understanding variable scope in modules
in thread Need help understanding variable scope in modules

But if you call it like a regular call, it would break down if you use inheritance.
$self -> _accessable ($1);
will search the inheritance tree for the function called _accessable while
_accessable ($self, $1);
will call AUTOLOAD if the function was inherited.

-- Abigail

Replies are listed 'Best First'.
Re: Re: Need help understanding variable scope in modules
by runrig (Abbot) on Jul 11, 2001 at 23:35 UTC
    Though a roundabout way to accomplish the desired goal would be (with the questionable bonus of making sure '_accessable' is a valid method):
    my $cref = $self->can('_accessable') or croak "Nothing is accessable!"; $cref->($self, $1) or croak "No such attribute: $1";
(tye)Re2: Need help understanding variable scope in modules
by tye (Sage) on Jul 11, 2001 at 23:48 UTC

    Good point. With the function defined within the module (as is implied), I thought that inheritance would not matter. But if AUTOLOAD gets inherited, then the parent class's AUTOLOAD might want to call the child class's _accessible. I just checked and AUTOLOAD does get inherited in 5.6 (I have vague memories of something about this being considered as a bug and can see inherited AUTOLOAD causing some surprises but can also see uses for it so I wasn't sure what the current state was).

    Anyway, I thought that the question implied that inheritance wasn't desired or I would have mentioned it. But thinking on it more, I wouldn't be surprised if that AUTOLOAD was designed to be inherited as part of a technique for inheriting member data.

    Thanks for the catch.

            - tye (but my friends call me "Tye")
      There was a bug where the docs said that AUTOLOAD wouldn't inherit on non-object calls but it did. IIRC, they made a warning when AUTOLOAD inherited on a non-object in 5.004 and outright outlawed it in 5.005.

      --Brent Dax

      @HPAJ=split("", "rekcaH lreP rentonA tsuJ"); print reverse @HPAJ; #sucky but who cares?