in reply to Catching writes to a bless'ed hash
Inside out objects are designed to prevent this. And with 5.10.x, implementing inside out objects is much easier:
Since the attribute is tucked inside a lexical variable, it's impossible for code defined outside of the scope to touch the attribute.use strict; use warnings; use Hash::Util::FieldHash; fieldhash my %attr1; # You need one for each attribute. sub new {bless \do {my $var}, shift} sub set_attr1 { my $self = shift; $attr1{$self} = shift; } sub get_attr1 { my $self = shift; $attr1{$self} } etc.
There's also a couple of modules out there to help you implement inside out objects, but I don't think they make use of fieldhashes (meaning they do extra work at DESTROY and CLONE time). Of course, if you're stuck with an old perl, those modules are the way to go.
|
|---|