laziness, impatience, and hubris | |
PerlMonks |
Re: Private & Protected Objectsby tobyink (Canon) |
on Aug 10, 2014 at 20:15 UTC ( [id://1096931]=note: print w/replies, xml ) | Need Help?? |
Although I agree with the intention, this seems like a bad way to implement it. It seems an unnecessarily black-magic technique to implement a form of protection that can be achieved via easier means. If you just want to avoid an accidental $obj->{field} then use blessed-arrayref objects instead of blessed-hashref objects. It will still be possible for people who do $obj->[3] to access a field, but they're less likely to do that accidentally. Better yet, use inside-out objects. Although they've gone in and out of fashion, there are some good implementations on CPAN (MooseX::InsideOut, MooX::InsideOut, Class::InsideOut, etc) and the various difficulties associated with inside-out objects (e.g. makes Data::Dumper less useful) are well understood. Also, read Method Privacy in Perl - not quite the same topic, but perhaps of interest to you.
In Section
Meditations
|
|