Class::Privacy - object data privacy
use Class::Privacy;
With the Class::Privacy module you can deny other classes from trying to directly access the data of your objects. Simply add the following to your class:
This disallows any outside attempts to directly access (dereference) the inner parts of the objects, only the class itself can do it. For outsiders the only allowed access is through the methods defined in the class.
This is what happens if an outsider tries to access the innards of the objects:
Cannot dereference 'NoPeeking' object at ...
The denial of access includes even derived classes. In other words, this is what most object-oriented languages call private.
There is no way to have protected, package, friend or any other privacy levels. This can be considered to be a feature, not a bug.
The Class:Privacy relies on overloading of the dereferencers %{}, @{}, and ${} (and &{}, just in case). Overloading those operations didn't work properly before Perl 5.6.1. This also means that you cannot have your own overloads for these operations for your objects, but you can still have other overloaded operations.
The protection is probably not foolproof since fools are so ingenious.
Jarkko Hietaniemi
Copyright 2002 Jarkko Hietaniemi All Rights Reserved
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Privacy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Privacy
CPAN shell
perl -MCPAN -e shell install Class::Privacy
For more information on module installation, please visit the detailed CPAN module installation guide.