Variable::Magic depends on Perl 5.8. 15 years ago, Perl 5.8 was not even dreamed of. (But I think you know that.)
I think that Variable::Magic gives you "more than enough rope" to build enforced protected and private objects, among many other strange things. Using magic has its good uses ("white magic"), but for me, using magic to prevent access does not feel right; it's "black magic".
NOTE in perlmodlib states:
Perl does not enforce private and public parts of its modules as you may have been used to in other languages like C++, Ada, or Modula-17. Perl doesn't have an infatuation with enforced privacy. It would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun.
The module and its user have a contract, part of which is common law, and part of which is "written". Part of the common law contract is that a module doesn't pollute any namespace it wasn't asked to. The written contract for the module (A.K.A. documentation) may make other provisions. But then you know when you use RedefineTheWorld that you're redefining the world and willing to take the consequences.
I prefer a Perl without a shotgun, so I can mess with object internals when needed for a temporary bugfix or workaround.
BTW: I think I could bypass your current protection using caller->isa(__PACKAGE__) like this:
use Third::Party::Class; # uses your constructor package Third::Party::Class { sub bypassPermissions { my ($self,$name,$value)=@_; $self->$name($value); } } my $object=Third::Party::Class->new(...); $object->bypassPermissions(secret => 42);
Alexander
In reply to Re: Private & Protected Objects
by afoken
in thread Private & Protected Objects
by Sixes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |