in reply to Re^2: Prevent direct acces to object's attributes
in thread Prevent direct acces to object's attributes

You could have a look at the lock functions in Hash::Util. It's a core module since 5.8, so there's probably nothing to install.

But, I'm sure I've read somewhere that their use is discouraged in objects. Can any Wise Old Monks shed any light on that?

Just Use Moose. You'll love it.

  • Comment on Re^3: Prevent direct acces to object's attributes

Replies are listed 'Best First'.
Re^4: Prevent direct acces to object's attributes
by JavaFan (Canon) on Sep 08, 2009 at 09:57 UTC
    You cannot (re)bless a hash that is locked. Which can hinder certain OO programming techniques. Furthermore, locking a hash doesn't prevent accessing the attributes. 'lock_keys' prevents keys to be added 'lock_value' makes values readonly, and 'lock_hash' makes the entire hash readonly. But keys being readonly still makes them readable. And if you have a reference to the hash (which traditional Perl objects give you), nothing stops you from calling any of the unlock function on them.