1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
=encoding utf8
=head1 NAME
Hash::Case - base class for hashes with key-casing requirements
=head1 INHERITANCE
Hash::Case
is a Tie::StdHash
Hash::Case is extended by
Hash::Case::Lower
Hash::Case::Preserve
Hash::Case::Upper
=head1 SYNOPSIS
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);
=head1 DESCRIPTION
L<Hash::Case|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: C<Lower> and C<Upper> are tied native hashes:
these hashes have no need for hidden fields or other assisting
data structured. A case C<Preserve> hash will actually create
three hashes.
The following strategies are implemented:
=over 4
=item * L<Hash::Case::Lower|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.
=item * L<Hash::Case::Upper|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.
=item * L<Hash::Case::Preserve|Hash::Case::Preserve>
The actual casing is ignored, but not forgotten.
=back
=head1 METHODS
=head2 Constructors
=over 4
=item tie B<%hash>, $class, [$values,] %options
Tie the C<%hash> with the C<$class> (package which extends L<Hash::Case>).
The C<%options> differ per implementation: read the manual page for the
package you actually use. The optional C<$values> is a reference to an ARRAY
(containing key-value PAIRS) or a HASH: they fill-in the initial C<%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;
=back
=head2 Hidden object access
Besides all the usual HASH actions which are implemented for the tied
C<%hash>, you can also call methods on the C<tied()> object.
=over 4
=item $obj-E<gt>B<addHashData>(\%data)
Add the C<%data> to the created tied hash. The existing values in the hash
remain, the keys are adapted to the needs of the the casing.
=item $obj-E<gt>B<addPairs>(@pairs)
Specify an even length list of alternating key and value to be stored in
the hash.
=item $obj-E<gt>B<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 L<addHashData()|Hash::Case/"Hidden object access">. Wrapper hashes will use the hash you specify here
to store the data, and re-create the mapping hash.
=back
=head1 SEE ALSO
This module is part of Hash-Case version 1.07,
built on January 26, 2026. Website: F<http://perl.overmeer.net/CPAN/>
=head1 LICENSE
For contributors see file ChangeLog.
This software is copyright (c) 2002-2026 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
|