SPUG: Hashes with Private/Hidden Values
Michael R. Wolf
MichaelRWolf at att.net
Mon May 7 22:54:29 PDT 2007
I did not understand the terms “hide” and “private”, so I had to unpack the
Private.pm attachment. To save others the trouble, here are a few lines...
NAME
Hash::Private - hashref with hidden (private) keys
SYNOPSIS
Using:
use Hash::Private;
my $hash = phash();
$hash->{username} = 'joedoe'; # exposed
$hash->{_password} = 'doejoe'; # hidden
Extending:
package MyClass;
use base 'Hash::Private';
sub new { shift->phash(@_) }
sub _fetch { print "FETCH called\n" }
sub _store { print "STORE called\n" }
sub _exists { print "EXISTS called\n" }
sub _delete { print "DELETE called"\n }
DESCRIPTION
Hash::Private is a class which 'hides' any key within a hash. It does
this by convincing the hash iterators (each(), keys(), values()) to only
return values that do not start with an underscore '_'. By doing so, you
can hide keys within a hash by prefixing them with an underscore.
[
]
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list