Tie::Subset::Hash::Masked - Tie a hash to mask some of its keys
use Tie::Subset::Hash::Masked; use Data::Dumper; my %hash = ( foo=>11, bar=>22, quz=>33 ); tie my %masked, 'Tie::Subset::Hash::Masked', \%hash, ['bar','quz']; print Dumper(\%masked); # shows only { foo => 11 } $masked{baz}++; # adds this key to %masked and %hash
This class for tied hashes provides a masked "view" of a hash.
tie
tie my %masked, 'Tie::Subset::Hash::Masked', \%hash, \@mask;
You must specify which keys from the original hash should be masked in the tied hash. (Keys that do not yet exist in the original hash may also be specified.)
If the key is masked, returns nothing (undef), otherwise, the value from the underlying hash is returned.
If the key is masked, the operation is ignored and a warning issued, otherwise, the new value will be stored in the underlying hash.
exists
Will return true only if the key exists in the underlying hash and the key is not masked.
each
keys
Only keys that exist in the underlying hash and that aren't masked are iterated over. The iterator of the underlying hash is utilized, so iterating over the tied hash will affect the state of the iterator of the underlying hash.
delete
If the key is masked, the operation is ignored and a warning issued, otherwise, the key will be deleted from the underlying hash.
Not (yet) supported (because it is ambiguous whether this operation should delete keys from the underlying hash or not). Attempting to clear the tied hash currently does nothing and causes a warning to be issued.
A future version of this module may lift this limitation (if a useful default behavior exists).
Tie::Subset::Hash
"See Also" in Tie::Subset
Copyright (c) 2023 Hauke Daempfling (haukex@zero-g.net).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command perldoc perlartistic or see http://perldoc.perl.org/perlartistic.html.
perldoc perlartistic
To install Tie::Subset, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Subset
CPAN shell
perl -MCPAN -e shell install Tie::Subset
For more information on module installation, please visit the detailed CPAN module installation guide.