Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^6: Language features affect style

by TimToady (Parson)
on Jun 10, 2009 at 19:20 UTC ( #770427=note: print w/replies, xml ) Need Help??

in reply to Re^5: Language features affect style
in thread Language features affect style

We're kinda confusing levels here. There are really three viewpoints of an object:
  1. The external public view.
  2. The internal private view.
  3. The hidden MOP view
I was speaking from the perspective of #2, not #3. From the #2 perspective, for any normal attribute without an explicit private accessor, $!foo and self!foo are largely interchangeable, give or take a sigil. The MOP may or may not make visible the call that implements $!foo, since $!foo is viewed under #2 as fundamentally a reference to the storage. The MOP is free to not implement method !foo at all if it can determine that it is unneeded, either by analysis or just by being lazy about autoloading one. From the #2 viewpoint, $!foo is just a variable, and method !foo is a (possibly autogenerated) accessor to the variable.

From the #3 perspective, sure, the fundamental accessor for the slot could be identical to method !foo, but then you're kinda hosed if the user wants to actually define the !foo method as a wrapper around $!foo, which would be an infinite regress if you confuse the user's slot accessor with the MOP's slot accessor. So unlike the situation with $.foo, the $!foo notation is not just syntactic sugar for a private accessor, and a private method must be called as self!foo.

So why would the user ever want to define their own private accessor? Primarily to mediate how much you want to dynamically "untrust" any other classes you've trusted by declaration.

Replies are listed 'Best First'.
Re^7: Language features affect style
by John M. Dlugosz (Monsignor) on Jun 15, 2009 at 14:21 UTC
    Ah, so $!x is only for attributes, and not for private methods, right?

    Q. Does the former use the sigil of the has declaration like a variable, as opposed to the function call semantics of $(self!x) ?

    So, the user can define a method !x directly, and the $!x notation doesn't call it, but bypasses it (talking MOP instead). A trusted user poking around in the privates must call it.

    Am I back on track?

    When I'm sure, I can clarify the synopses where it doesn't properly indicate that this is different.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://770427]
[choroba]: but undef %hash and %hash = () both work, too, but the first one keeps the memory allocated, while the latter makes it available for other parts of the program.
[choroba]: iirc
[perldigious]: karlgoethebier: Well it is a pretty old and complicated (for me) bit of code I wrote (poorly by my current standards), so I'm expecting everything to break when I add the scoping and find out what else is undesireably scope changed. :-)
[perldigious]: Ah, thanks choroba, that sort of thing was precisely what I was wondering when I asked.
[perldigious]: I didn't want to tie up memory unecessarily basically, I wanted to "delete" it specifically to free it up, and wasn't sure I was even accomplishing that.
[stevieb]: perldigious You should start by writing some unit tests. That'll ensure current functionality doesn't break with changes.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-07-21 19:55 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (335 votes). Check out past polls.