Hash::Case3pm
Base class for hashes with key-casing requirements
Usage
use Hash::Case::Lower;tie my(%lchash), 'Hash::Case::Lower';$lchash{StraNGeKeY} = 3;print keys %lchash; # strangekey(tied %lchash)->addPairs(key => value, ...);(tied %lchash)->addHashData(\%data);(tied %lchash)->setHash(\%replacement);
Inheritance
Hash::Caseis a Tie::StdHashHash::Case is extended byHash::Case::LowerHash::Case::PreserveHash::Case::Upper
Overview
Hash::Case is the base class for various classes which tie special treatment for the casing of keys. Be aware of the differences in implementation: "Lower" and "Upper" are tied native hashes: these hashes have no need for hidden fields or other assisting data structured. A case "Preserve" hash will actually create three hashes.
The following strategies are implemented:
- •
-
Hash::Case::Lower (native hash)
Keys are always considered lower case. The internals of this module translate any incoming key to lower case before it is used.
- •
-
Hash::Case::Upper (native hash)
Like the ::Lower, but then all keys are always translated into upper case. This module can be of use for some databases, which do translate everything to capitals as well. To avoid confusion, you may want to have you own internal Perl hash do this as well.
- •
-
Hash::Case::Preserve
The actual casing is ignored, but not forgotten.
Methods
Constructors
- tie
%hash, $class, [$values,] %options -
Tie the
%hashwith the$class(package which extends Hash::Case). The%optionsdiffer per implementation: read the manual page for the package you actually use. The optional$valuesis a reference to an ARRAY (containing key-value PAIRS) or a HASH: they fill-in the initial%hash.» example:
my %x;tie %x, 'Hash::Case::Lower';$x{Upper} = 3;print keys %x; # 'upper'my @y = (ABC => 3, DeF => 4);tie %x, 'Hash::Case::Lower', \@y;print keys %x; # 'abc' 'def'my %z = (ABC => 3, DeF => 4);tie %x, 'Hash::Case::Lower', \%z;
Hidden object access
Besides all the usual HASH actions which are implemented for the tied %hash, you can also call methods on the tied() object.
- $obj->
addHashData(\%data) -
Add the
%datato the created tied hash. The existing values in the hash remain, the keys are adapted to the needs of the the casing.
- $obj->
addPairs(@pairs) -
Specify an even length list of alternating key and value to be stored in the hash.
- $obj->
setHash(\%data) -
The functionality differs for native and wrapper hashes. For native hashes, this is the same as first clearing the hash, and then a call to
addHashData(). Wrapper hashes will use the hash you specify here to store the data, and re-create the mapping hash.
Releases
10 releases since Debian 5.0 (Lenny); the text changed 5 times.