Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Need help understanding variable scope in modules

by Abigail (Deacon)
on Jul 11, 2001 at 23:23 UTC ( #95820=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Need help understanding variable scope in modules
Select or Download Code
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 (Cardinal) 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.

      =cut
      --Brent Dax

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-10-20 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (88 votes), past polls