Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: $foo->bar = 14;

by John M. Dlugosz (Monsignor)
on Dec 30, 2002 at 21:45 UTC ( #223188=note: print w/ replies, xml ) Need Help??


in reply to $foo->bar = 14;

OK, the reason you use "automated" accessors instead of using the hash directly is so that the accesor sould be changed at some point without messing up the clients. The internal representation might change, or you might need to hook either the get or the set (or both) to perform other actions, such as keeping the state in sync or reporting debug events.

Having the lvalue return the hash element means the assignment, the setter part, is not under your control. You can't change the code behind setting the value (if the representation changed, for example) without affecting the callers. The only thing it does is let you change the name of the hash element (big deal), or hook "access" without caring whether it will be a get or set and without knowing the new value if a set.

So, I don't use it, since it doesn't do what I want of an accessor.

—John


Comment on Re: $foo->bar = 14;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-30 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls