Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Private & Protected Objects

by tobyink (Canon)
on Aug 10, 2014 at 20:15 UTC ( [id://1096931]=note: print w/replies, xml ) Need Help??


in reply to Private & Protected Objects

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found