SPUG: Hashes with Private/Hidden Values

Ingmar Ellenberger ingmar at site42.com
Tue May 8 08:10:06 PDT 2007


Michael,

Thanks for expanding that out (and revealing my poorly written documentation
:).  Still eagerly looking forward to critical review from fellow SPUSsters.

 - Ingmar


On 5/7/07, Michael R. Wolf <MichaelRWolf at att.net> wrote:
>
> 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
>
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays
>     WEB PAGE: http://seattleperl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20070508/6c780133/attachment-0006.html 


More information about the spug-list mailing list