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 reply to Re: Private & Protected Objects
by tobyink
in thread Private & Protected Objects
by Sixes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |