If he was adding information, it was somewhat misleading. However your post was also technically incorrect.
A closure closes over the current lexical environment. That does not mean that the current lexical environment is private, whatever else shares it can change it. Frequently nothing else shares that environment, but not always. An extreme demonstrating being a function that returns several connected closures - each of which can change the private data that the others look at. (I've done this, but more often in JavaScript than in Perl. It can be a nice technique to use to coordinate between UI elements.)
In the case of our, the current lexical environment includes the fact that certain variables are actually the equivalent package variable. In that case the current lexical environment includes some very non-private stuff. So yes, our creates a closure, but not one that acts a lot like what you'd normally think of as a closure. | [reply] |
A closure closes over the current lexical environment. That does not mean that the current lexical environment is private, whatever else shares it can change it.
When I said a closure "protect[s] it from the outside," I meant from outside the lexical scope that was closed around. I probably should have spelled this out more explicitly, as you have.
In the case of our, the current lexical environment includes the fact that certain variables are actually the equivalent package variable.
Ah, yes. Thanks for the clarification on this. So the closure does not contain the variable per se, but just the alias to it that our created.
| [reply] |