The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::Privacy - object data privacy

SYNOPSIS

    use Class::Privacy;

DESCRIPTION

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:

    use Class::Privacy;

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.

IMPLEMENTATION

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.

AUTHOR

Jarkko Hietaniemi

COPYRIGHT AND LICENSE

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.