Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Objects with Private Variables

by Anonymous Monk
on Mar 30, 2003 at 16:21 UTC ( #246740=note: print w/replies, xml ) Need Help??

in reply to Objects with Private Variables

So how does the closure know what $self it is using? As far as I understand, $self will be out of scope when I return from "new". Or is a new reference to the "new" block saved each time it runs?

Replies are listed 'Best First'.
Re: Re: Objects with Private Variables
by diotalevi (Canon) on Mar 30, 2003 at 17:10 UTC

    You missed the key point - the anonymous subroutine is a closure because it "captures" the $type, $class and $self instances. So when you call the function later the $self variable is still accessible from inside $closure thus it all works.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://246740]
[choroba]: I can't say "Good morning", getting the "Whoa cowboy"
[marto]: the same thing just happened to me :P
Discipulus our orders office is a crow of idiots...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2017-01-19 10:05 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (170 votes). Check out past polls.