Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by tye (Sage)
on Jul 11, 2001 at 22:41 UTC ( #95802=note: print w/replies, xml ) Need Help??


in reply to Need help understanding variable scope in modules

You could call it via _accessible( $self, $1 ) where you can even replace $self with any single scalar. The reason you get "undefined value" is that _accessible( $1 ) sets @_ to only contain a single value so that $_[1] is undef.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: Need help understanding variable scope in modules
by Abigail (Deacon) on Jul 11, 2001 at 23:23 UTC
    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

      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";

      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://95802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2021-05-06 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (77 votes). Check out past polls.

    Notices?