Hash-Case-1.07/0000755000175000001440000000000015135665445013731 5ustar00markovusers00000000000000Hash-Case-1.07/MANIFEST0000644000175000001440000000071115135665445015061 0ustar00markovusers00000000000000ChangeLog MANIFEST Makefile.PL README README.md lib/Hash/Case.pm lib/Hash/Case.pod lib/Hash/Case/Lower.pm lib/Hash/Case/Lower.pod lib/Hash/Case/Preserve.pm lib/Hash/Case/Preserve.pod lib/Hash/Case/Upper.pm lib/Hash/Case/Upper.pod t/10lower.t t/20upper.t t/30pres1.t t/31pres2.t xt/99pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Hash-Case-1.07/README0000644000175000001440000000141615055526642014607 0ustar00markovusers00000000000000=== README for Hash-Case version 1.06 = Generated on Tue Sep 2 10:41:06 2025 by OODoc 2.02 There are various ways to install this module: (1) if you have a command-line, you can do: perl -MCPAN -e 'install ' (2) if you use Windows, have a look at http://ppm.activestate.com/ (3) if you have downloaded this module manually (as root/administrator) gzip -d Hash-Case-1.06.tar.gz tar -xf Hash-Case-1.06.tar cd Hash-Case-1.06 perl Makefile.PL make # optional make test # optional make install For usage, see the included manual-pages or http://search.cpan.org/dist/Hash-Case-1.06/ Please report problems to http://rt.cpan.org/Dist/Display.html?Queue=Hash-Case Hash-Case-1.07/ChangeLog0000644000175000001440000000474215135665444015511 0ustar00markovusers00000000000000==== version history of Hash::Case All changes made by Mark Overmeer, unless explicitly stated otherwise. version 1.07: Mon 26 Jan 14:24:32 CET 2026 Fixes: - Tie::StdHash needs to be compiled via Tie::Hash. version 1.06: Mon 26 Jan 11:29:04 CET 2026 Changes: - require Perl 5.16 (2015) Improvements: - convert Makefile.PL to OODoc 3.06. - convert code and syntax to new preferences. - add .gitignore - add README.md - improve documentation version 1.05: Thu 6 Feb 16:41:09 CET 2020 Fixes: - accidentally left a "use Log::Report" in. version 1.04: Thu 6 Feb 16:22:37 CET 2020 Changes: - replace Log::Report by croak on request by [Ed Avis] GitHub#1 version 1.03: Mon 22 Jan 17:14:46 CET 2018 Improvements: - convert to GIT - development on GitHUB version 1.02: Fri Mar 9 09:24:30 CET 2012 Fixes: - typo in docs. rt.cpan.org#75630 [Florian Schlich] - remove unused nested Makefile.PL rt.cpan.org#75630 [Florian Schlich] version 1.01: Mon Feb 15 10:21:42 CET 2010 Fixes: - do not use /bin/pwd in t/pod.t Improvements: - use Log::Report for error handling. version 1.006: Thu Jun 19 08:40:46 CEST 2008 - perl5.005 does not understand "use 5.6.0" and tie bug in 5.6.2. So require 5.008 [cpantesters] version 1.005: Wed Jun 18 09:02:28 CEST 2008 - require perl 5.6.0 [cpantesters] - minor distribution clean-ups version 1.004: Fri Jun 8 15:37:31 CEST 2007 - fixed 2 typo's in POD (Thanks to CPANTS) - add t/pod.t - use oodist to create docs. version 1.003: Mon Oct 27 07:58:44 CET 2003 - Added methods addPairs() and addHashData() to initialize a hash with values. - Use Test::More i.s.o. Test - Move pm files to a new lib/ directory - Copyrights also in 2003 version 1.002: Fri Aug 2 16:48:23 CEST 2002 - Changed my e-mail address to mark@overmeer.net - Added Hash::Case::init() as dummy. - Some configuration problems fixed. - An array passed as initializer for the hash was cleaned in the process, which is not nice, of course. Reported by [Jenda Krynicky] version 1.001: Sat Jun 15 13:29:55 CEST 2002 This code is fully tested, and too simple to be true, so I release it without hesitation as stable. - Initial implementation of Hash::Case - Initial implementation of Hash::Case::Lower, tests in t/10lower.t - Initial implementation of Hash::Case::Upper, tests in t/20upper.t - Initial implementation of Hash::Case::Preserve, tests in t/30pres1.t - Initial implementation of Hash::Case::Preserve, tests in t/31pres2.t Hash-Case-1.07/Makefile.PL0000644000175000001440000000341015135665444015700 0ustar00markovusers00000000000000use ExtUtils::MakeMaker; use 5.016; use warnings; use strict; # Use command 'oodist' to produce your whole software release. my $version = '1.07', my $git = "https://github.com/markov2/perl5-Hash-Case"; my $publish = "../public_html/hash-case"; my $homepage = "http://perl.overmeer.net/CPAN/"; my %oodist = ( oodoc_version => 3.06, first_year => 2002, email => "markov\@cpan.org", include => [ ], use => [ ], parser => { syntax => 'markov', skip_links => [ 'Tie::StdHash', ], pmhead => undef, }, tests => { }, release => { publish => "$publish/source", }, raw => { publish => "$publish/raw", }, generate => [ { # Add real pod to the releases format => 'pod3', podtail => undef, }, ], ); my %requires = ( 'Tie::Hash' => 0, # 'Tie::StdHash' => 0, # hidden component of Tie::Hash 'Carp' => 0, ); WriteMakefile NAME => 'Hash::Case', VERSION => $version, AUTHOR => 'Mark Overmeer ', ABSTRACT => 'Play trics with HASH keys', LICENSE => 'perl_5', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => "$git.git", web => $git, }, bugtracker => { web => "$git/issues", }, homepage => $homepage, license => [ 'http//dev.perl.org/licenses/' ], }, prereqs => { runtime => { requires => \%requires, recommends => {}, suggests => {}, }, develop => { requires => { 'OODoc' => '3.00', }, }, test => { requires => { 'Test::More' => 1.00, 'Test::Pod' => 1.00, }, }, }, # You may use multiple set-ups, see "oodist --make" x_oodist => \%oodist, }; Hash-Case-1.07/lib/0000755000175000001440000000000015135665445014477 5ustar00markovusers00000000000000Hash-Case-1.07/lib/Hash/0000755000175000001440000000000015135665445015362 5ustar00markovusers00000000000000Hash-Case-1.07/lib/Hash/Case/0000755000175000001440000000000015135665445016235 5ustar00markovusers00000000000000Hash-Case-1.07/lib/Hash/Case/Upper.pod0000644000175000001440000000351115135665444020033 0ustar00markovusers00000000000000=encoding utf8 =head1 NAME Hash::Case::Upper - native hash with enforced lower cased keys =head1 INHERITANCE Hash::Case::Upper is a Hash::Case is a Tie::StdHash =head1 SYNOPSIS use Hash::Case::Upper; tie my(%uchash), 'Hash::Case::Upper'; $uchash{StraNGeKeY} = 3; print keys %uchash; # STRANGEKEY =head1 DESCRIPTION L extends L, which lets you play various trics with hash keys. In this implementation, the fake hash is case insensitive and the keys stored in upper-case. Extends L<"DESCRIPTION" in Hash::Case|Hash::Case/"DESCRIPTION">. =head1 METHODS Extends L<"METHODS" in Hash::Case|Hash::Case/"METHODS">. =head2 Constructors Extends L<"Constructors" in Hash::Case|Hash::Case/"Constructors">. =over 4 =item tie B<%hash>, 'Hash::Case::Upper', [$values,] %options Define C<%hash> to have only upper-cased keys. The hash is initialized with the C<$values>, specified as ARRAY or HASH. Currently, there are no C<%options> defined. Improves base, see L =back =head2 Hidden object access Extends L<"Hidden object access" in Hash::Case|Hash::Case/"Hidden object access">. =over 4 =item $obj-EB(\%data) Inherited, see L =item $obj-EB(@pairs) Inherited, see L =item $obj-EB(\%data) Inherited, see L =back =head1 SEE ALSO This module is part of Hash-Case version 1.07, built on January 26, 2026. Website: F =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. Hash-Case-1.07/lib/Hash/Case/Upper.pm0000644000175000001440000000161515135665444017670 0ustar00markovusers00000000000000# This code is part of Perl distribution Hash-Case version 1.07. # The POD got stripped from this file by OODoc version 3.06. # 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. # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later package Hash::Case::Upper;{ our $VERSION = '1.07'; } use base 'Hash::Case'; use strict; use warnings; use Carp qw/croak/; #-------------------- sub init($) { my ($self, $args) = @_; $self->SUPER::native_init($args); ! keys %$args or croak "no options available for ". __PACKAGE__; $self; } sub FETCH($) { $_[0]->{uc $_[1]} } sub STORE($$) { $_[0]->{uc $_[1]} = $_[2] } sub EXISTS($) { exists $_[0]->{uc $_[1]} } sub DELETE($) { delete $_[0]->{uc $_[1]} } 1; Hash-Case-1.07/lib/Hash/Case/Preserve.pm0000644000175000001440000000346515135665444020375 0ustar00markovusers00000000000000# This code is part of Perl distribution Hash-Case version 1.07. # The POD got stripped from this file by OODoc version 3.06. # 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. # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later package Hash::Case::Preserve;{ our $VERSION = '1.07'; } use base 'Hash::Case'; use strict; use warnings; use Carp 'croak'; #-------------------- sub init($) { my ($self, $args) = @_; $self->{HCP_data} = {}; $self->{HCP_keys} = {}; my $keep = $args->{keep} || 'LAST'; if($keep eq 'LAST') { $self->{HCP_update} = 1 } elsif($keep eq 'FIRST') { $self->{HCP_update} = 0 } else { croak "use 'FIRST' or 'LAST' with the option keep"; } $self->SUPER::native_init($args); } # Maintain two hashes within this object: one to store the values, and # one to preserve the casing. The main object also stores the options. # The data is kept under lower cased keys. sub FETCH($) { $_[0]->{HCP_data}{lc $_[1]} } sub STORE($$) { my ($self, $key, $value) = @_; my $lckey = lc $key; $self->{HCP_keys}{$lckey} = $key if $self->{HCP_update} || !exists $self->{HCP_keys}{$lckey}; $self->{HCP_data}{$lckey} = $value; } sub FIRSTKEY { my $self = shift; my $a = scalar keys %{$self->{HCP_keys}}; $self->NEXTKEY; } sub NEXTKEY($) { my $self = shift; if(my ($k, $v) = each %{$self->{HCP_keys}}) { return wantarray ? ($v, $self->{HCP_data}{$k}) : $v; } (); } sub EXISTS($) { exists $_[0]->{HCP_data}{lc $_[1]} } sub DELETE($) { my $lckey = lc $_[1]; delete $_[0]->{HCP_keys}{$lckey}; delete $_[0]->{HCP_data}{$lckey}; } sub CLEAR() { %{$_[0]->{HCP_data}} = (); %{$_[0]->{HCP_keys}} = (); } 1; Hash-Case-1.07/lib/Hash/Case/Lower.pod0000644000175000001440000000353015135665444020031 0ustar00markovusers00000000000000=encoding utf8 =head1 NAME Hash::Case::Lower - hash with enforced lower cased keys =head1 INHERITANCE Hash::Case::Lower is a Hash::Case is a Tie::StdHash =head1 SYNOPSIS use Hash::Case::Lower; tie my(%lchash), 'Hash::Case::Lower'; $lchash{StraNGeKeY} = 3; print keys %lchash; # strangekey =head1 DESCRIPTION L extends L, which lets you play various trics with hash keys. In this implementation, the fake hash is case insensitive and the keys stored in lower-case. Extends L<"DESCRIPTION" in Hash::Case|Hash::Case/"DESCRIPTION">. =head1 METHODS Extends L<"METHODS" in Hash::Case|Hash::Case/"METHODS">. =head2 Constructors Extends L<"Constructors" in Hash::Case|Hash::Case/"Constructors">. =over 4 =item tie B<%hash>, 'Hash::Case::Lower', [$values,] %options Define C<%hash> to have only lower-cased keys. The hash is initialized with the C<$values>, specified as ARRAY (with key-value PAIRS) or HASH. Currently, there are no C<%options> defined. Improves base, see L =back =head2 Hidden object access Extends L<"Hidden object access" in Hash::Case|Hash::Case/"Hidden object access">. =over 4 =item $obj-EB(\%data) Inherited, see L =item $obj-EB(@pairs) Inherited, see L =item $obj-EB(\%data) Inherited, see L =back =head1 SEE ALSO This module is part of Hash-Case version 1.07, built on January 26, 2026. Website: F =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. Hash-Case-1.07/lib/Hash/Case/Preserve.pod0000644000175000001440000000436115135665444020537 0ustar00markovusers00000000000000=encoding utf8 =head1 NAME Hash::Case::Preserve - hash with enforced lower cased keys =head1 INHERITANCE Hash::Case::Preserve is a Hash::Case is a Tie::StdHash =head1 SYNOPSIS use Hash::Case::Preserve; tie my(%cphash), 'Hash::Case::Preserve'; $cphash{StraNGeKeY} = 3; print keys %cphash; # StraNGeKeY print $cphash{strangekey}; # 3 print $cphash{STRANGEKEY}; # 3 =head1 DESCRIPTION L extends L, which lets you play various trics with hash keys. This extension implements a fake hash which is case-insentive. The keys are administered in the casing as they were used: case-insensitive but case-preserving. Extends L<"DESCRIPTION" in Hash::Case|Hash::Case/"DESCRIPTION">. =head1 METHODS Extends L<"METHODS" in Hash::Case|Hash::Case/"METHODS">. =head2 Constructors Extends L<"Constructors" in Hash::Case|Hash::Case/"Constructors">. =over 4 =item tie B<%hash>, 'Hash::Case::Preserve', [$values,] %options Define C<%hash> to be case insensitive, but case preserving. The hash is initialized with the C<$values>, specified as ARRAY (passing flat key-value pairs) or HASH. Improves base, see L -Option--Default keep 'LAST' =over 2 =item keep => 'FIRST'|'LAST' Which casing is the preferred casing? The FIRST appearance or the LAST. Only stores will affect the casing, deletes will undo the definition. Defaults to LAST, which is slightly faster. =back =back =head2 Hidden object access Extends L<"Hidden object access" in Hash::Case|Hash::Case/"Hidden object access">. =over 4 =item $obj-EB(\%data) Inherited, see L =item $obj-EB(@pairs) Inherited, see L =item $obj-EB(\%data) Inherited, see L =back =head1 SEE ALSO This module is part of Hash-Case version 1.07, built on January 26, 2026. Website: F =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. Hash-Case-1.07/lib/Hash/Case/Lower.pm0000644000175000001440000000161515135665444017665 0ustar00markovusers00000000000000# This code is part of Perl distribution Hash-Case version 1.07. # The POD got stripped from this file by OODoc version 3.06. # 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. # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later package Hash::Case::Lower;{ our $VERSION = '1.07'; } use base 'Hash::Case'; use strict; use warnings; use Carp qw/croak/; #-------------------- sub init($) { my ($self, $args) = @_; $self->SUPER::native_init($args); ! keys %$args or croak "no options possible for ". __PACKAGE__; $self; } sub FETCH($) { $_[0]->{lc $_[1]} } sub STORE($$) { $_[0]->{lc $_[1]} = $_[2] } sub EXISTS($) { exists $_[0]->{lc $_[1]} } sub DELETE($) { delete $_[0]->{lc $_[1]} } 1; Hash-Case-1.07/lib/Hash/Case.pm0000644000175000001440000000353315135665444016576 0ustar00markovusers00000000000000# This code is part of Perl distribution Hash-Case version 1.07. # The POD got stripped from this file by OODoc version 3.06. # 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. # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later package Hash::Case;{ our $VERSION = '1.07'; } use Tie::Hash; # Tie::StdHash is a hidden package inside this :-( use base 'Tie::StdHash'; use warnings; use strict; use Carp qw/croak/; #-------------------- sub TIEHASH(@) { my $class = shift; my $to = @_ % 2 ? shift : undef; my %opts = (@_, add => $to); (bless {}, $class)->init( \%opts ); } # Used for case-insensitive hashes which do not need more than # one hash. sub native_init($) { my ($self, $args) = @_; my $add = delete $args->{add}; if(!$add) { ; } elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } elsif(ref $add eq 'HASH') { $self->addHashData($add) } else { croak "cannot initialize the native hash this way" } $self; } # Used for case-insensitive hashes which are implemented around # an existing hash. sub wrapper_init($) { my ($self, $args) = @_; my $add = delete $args->{add}; if(!$add) { ; } elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } elsif(ref $add eq 'HASH') { $self->setHash($add) } else { croak "cannot initialize a wrapping hash this way" } $self; } #----------- sub addPairs(@) { my $self = shift; $self->STORE(shift, shift) while @_; $self; } sub addHashData($) { my ($self, $data) = @_; while(my ($k, $v) = each %$data) { $self->STORE($k, $v) } $self; } sub setHash($) { my ($self, $hash) = @_; # the native implementation is the default. %$self = %$hash; $self; } 1; Hash-Case-1.07/lib/Hash/Case.pod0000644000175000001440000000655715135665444016755 0ustar00markovusers00000000000000=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 is the base class for various classes which tie special treatment for the casing of keys. Be aware of the differences in implementation: C and C are tied native hashes: these hashes have no need for hidden fields or other assisting data structured. A case C hash will actually create three hashes. The following strategies are implemented: =over 4 =item * L (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 (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 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). 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 object. =over 4 =item $obj-EB(\%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-EB(@pairs) Specify an even length list of alternating key and value to be stored in the hash. =item $obj-EB(\%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. 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 =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. Hash-Case-1.07/t/0000755000175000001440000000000015135665445014174 5ustar00markovusers00000000000000Hash-Case-1.07/t/10lower.t0000644000175000001440000000225715055526634015655 0ustar00markovusers00000000000000#!/usr/bin/env perl # Test lower cased hash use strict; use warnings; use Test::More; BEGIN {plan tests => 31} use Hash::Case::Lower; my %h; tie %h, 'Hash::Case::Lower'; cmp_ok(keys %h, '==', 0); $h{abc} = 3; cmp_ok($h{abc}, '==', 3); cmp_ok($h{ABC}, '==', 3); cmp_ok($h{AbC}, '==', 3); cmp_ok(keys %h, '==', 1); my @h = keys %h; cmp_ok(@h, '==', 1); is($h[0], 'abc'); $h{dEf} = 4; cmp_ok($h{def}, '==', 4); cmp_ok($h{dEf}, '==', 4); cmp_ok(keys %h, '==', 2); my (@k, @v); while(my ($k, $v) = each %h) { push @k, $k; push @v, $v; } cmp_ok(@k, '==', 2); @k = sort @k; is($k[0], 'abc'); is($k[1], 'def'); ok(@v==2); @v = sort {$a <=> $b} @v; cmp_ok($v[0], '==', 3); cmp_ok($v[1], '==', 4); ok(exists $h{ABC}); cmp_ok(delete $h{ABC}, '==', 3); cmp_ok(keys %h, '==', 1); %h = (); cmp_ok(keys %h, '==', 0); ok(tied %h); my %a; tie %a, 'Hash::Case::Lower', [ AbC => 3, dEf => 4 ]; ok(tied %a); cmp_ok(keys %a, '==', 2); ok(defined $a{abc}); cmp_ok($a{ABC}, '==', 3); cmp_ok($a{DeF}, '==', 4); my %b; tie %b, 'Hash::Case::Lower', { AbC => 3, dEf => 4 }; ok(tied %b); cmp_ok(keys %b, '==', 2); ok(defined $b{abc}); cmp_ok($b{ABC}, '==', 3); cmp_ok($b{DeF}, '==', 4); Hash-Case-1.07/t/20upper.t0000644000175000001440000000273415055526634015661 0ustar00markovusers00000000000000#!/usr/bin/env perl # Test upper cased hash use strict; use warnings; use Test::More; BEGIN {plan tests => 35} use Hash::Case::Upper; my %h; tie %h, 'Hash::Case::Upper'; cmp_ok(keys %h, '==', 0); $h{ABC} = 3; cmp_ok($h{ABC}, '==', 3); cmp_ok($h{abc}, '==', 3); cmp_ok($h{AbC}, '==', 3); cmp_ok(keys %h, '==', 1); my @h = keys %h; cmp_ok(@h, '==', 1); is($h[0], 'ABC'); $h{dEf} = 4; cmp_ok($h{def}, '==', 4); cmp_ok($h{dEf}, '==', 4); cmp_ok(keys %h, '==', 2); my (@k, @v); while(my ($k, $v) = each %h) { push @k, $k; push @v, $v; } cmp_ok(@k, '==', 2); @k = sort @k; is($k[0], 'ABC'); is($k[1], 'DEF'); cmp_ok(@v, '==', 2); @v = sort {$a <=> $b} @v; cmp_ok($v[0], '==', 3); cmp_ok($v[1], '==', 4); ok(exists $h{ABC}); cmp_ok(delete $h{ABC}, '==', 3); cmp_ok(keys %h, '==', 1); %h = (); cmp_ok(keys %h, '==', 0); ok(tied %h); my %a; tie %a, 'Hash::Case::Upper', [ AbC => 3, dEf => 4 ]; ok(tied %a); cmp_ok(keys %a, '==', 2); ok(defined $a{abc}); cmp_ok($a{ABC}, '==', 3); cmp_ok($a{DeF}, '==', 4); my %b; tie %b, 'Hash::Case::Upper', { AbC => 3, dEf => 4 }; ok(tied %b); cmp_ok(keys %b, '==', 2); ok(defined $b{abc}); cmp_ok($b{ABC}, '==', 3); cmp_ok($b{DeF}, '==', 4); ### test boolean context (bug reported by Dmitry Bolshakoff) tie my %c, 'Hash::Case::Upper'; is((%c ? 'yes' : 'no'), 'no', 'empty'); is((!%c ? 'yes' : 'no'), 'yes', 'empty'); $c{111} = 222; is((%c ? 'yes' : 'no'), 'yes', 'not empty'); is((!%c ? 'yes' : 'no'), 'no', 'not empty'); Hash-Case-1.07/t/31pres2.t0000644000175000001440000000273215055526634015561 0ustar00markovusers00000000000000#!/usr/bin/env perl # Test case-preserving hash, where the first appearance is kept. use strict; use warnings; use Test::More; BEGIN {plan tests => 37} use Hash::Case::Preserve; my %h; tie %h, 'Hash::Case::Preserve', keep => 'FIRST'; cmp_ok(keys %h, '==', 0); $h{ABC} = 3; cmp_ok($h{ABC}, '==', 3); cmp_ok($h{abc}, '==', 3); cmp_ok($h{AbC}, '==', 3); cmp_ok(keys %h, '==', 1); my @h = keys %h; ok(@h==1); is($h[0], 'ABC'); # first STORE $h{abc} = 6; cmp_ok(keys %h, '==', 1); cmp_ok($h{ABC}, '==', 6); is((keys %h)[0], 'ABC'); $h{ABC} = 3; cmp_ok(keys %h, '==', 1); cmp_ok($h{ABC}, '==', 3); is((keys %h)[0], 'ABC'); $h{dEf} = 4; cmp_ok($h{def}, '==', 4); cmp_ok($h{dEf}, '==', 4); cmp_ok(keys %h, '==', 2); my (@k, @v); while(my ($k, $v) = each %h) { push @k, $k; push @v, $v; } cmp_ok(@k, '==', 2); @k = sort @k; is($k[0], 'ABC'); is($k[1], 'dEf'); ok(@v==2); @v = sort {$a <=> $b} @v; cmp_ok($v[0], '==', 3); cmp_ok($v[1], '==', 4); ok(exists $h{ABC}); cmp_ok(delete $h{ABC}, '==', 3); cmp_ok(keys %h, '==', 1); %h = (); cmp_ok(keys %h, '==', 0); ok(tied %h); my %a; tie %a, 'Hash::Case::Preserve', [ AbC => 3, dEf => 4 ], keep => 'FIRST'; ok(tied %a); cmp_ok(keys %a, '==', 2); ok(defined $a{abc}); cmp_ok($a{ABC}, '==', 3); cmp_ok($a{DeF}, '==', 4); my %b; tie %b, 'Hash::Case::Preserve', { AbC => 3, dEf => 4 }, keep => 'FIRST'; ok(tied %b); cmp_ok(keys %b, '==', 2); ok(defined $b{abc}); cmp_ok($b{ABC}, '==', 3); cmp_ok($b{DeF}, '==', 4); Hash-Case-1.07/t/30pres1.t0000644000175000001440000000275315055526634015562 0ustar00markovusers00000000000000#!/usr/bin/env perl # Test case-preserving hash, where the last appearance is kept. use strict; use warnings; use Test::More; BEGIN {plan tests => 37} use Hash::Case::Preserve; my %h; tie %h, 'Hash::Case::Preserve', keep => 'LAST'; cmp_ok(keys %h, '==', 0); $h{ABC} = 3; cmp_ok($h{ABC}, '==', 3); cmp_ok($h{abc}, '==', 3); cmp_ok($h{AbC}, '==', 3); cmp_ok(keys %h, '==', 1); my @h = keys %h; cmp_ok(@h, '==', 1); is($h[0], 'ABC'); # last STORE $h{abc} = 6; cmp_ok(keys %h, '==', 1); cmp_ok($h{ABC}, '==', 6); is((keys %h)[0], 'abc'); $h{ABC} = 3; cmp_ok(keys %h, '==', 1); cmp_ok($h{ABC}, '==', 3); is((keys %h)[0], 'ABC'); $h{dEf} = 4; cmp_ok($h{def}, '==', 4); cmp_ok($h{dEf}, '==', 4); cmp_ok(keys %h, '==', 2); my (@k, @v); while(my ($k, $v) = each %h) { push @k, $k; push @v, $v; } cmp_ok(@k, '==', 2); @k = sort @k; is($k[0], 'ABC'); is($k[1], 'dEf'); cmp_ok(@v, '==', 2); @v = sort {$a <=> $b} @v; cmp_ok($v[0], '==', 3); cmp_ok($v[1], '==', 4); ok(exists $h{ABC}); cmp_ok(delete $h{ABC}, '==', 3); cmp_ok(keys %h, '==', 1); %h = (); cmp_ok(keys %h, '==', 0); ok(tied %h); my %a; tie %a, 'Hash::Case::Preserve', [ AbC => 3, dEf => 4 ], keep => 'LAST'; ok(tied %a); cmp_ok(keys %a, '==', 2); ok(defined $a{abc}); cmp_ok($a{ABC}, '==', 3); cmp_ok($a{DeF}, '==', 4); my %b; tie %b, 'Hash::Case::Preserve', { AbC => 3, dEf => 4 }, keep => 'LAST'; ok(tied %b); cmp_ok(keys %b, '==', 2); ok(defined $b{abc}); cmp_ok($b{ABC}, '==', 3); cmp_ok($b{DeF}, '==', 4); Hash-Case-1.07/README.md0000644000175000001440000000374615135635754015222 0ustar00markovusers00000000000000# Hash::Case Ties hashes to play tricks with keys. * My extended documentation: * Development via GitHub: * Sponsor me: * Download from CPAN: * Indexed from CPAN: ## Installing On github, you can find the processed version for each release. But the better source is CPAN; to get it installed simply run: ```sh cpan -i Hash::Case ``` ## Development → Release Important to know, is that I use an extension on POD to write the manuals. The "raw" unprocessed version is visible on GitHub. It will run without problems, but does not contain manual-pages. Releases to CPAN are different: "raw" documentation gets removed from the code and translated into real POD and clean HTML. This reformatting is implemented with the OODoc distribution (A name I chose before OpenOffice existed, sorry for the confusion) Clone from github for the "raw" version. For instance, when you want to contribute a new feature. ## Contributing When you want to contribute to this module, you do not need to provide a perfect patch... actually: it is nearly impossible to create a patch which I will merge without modification. Usually, I need to adapt the style of code and documentation to my own strict rules. When you submit an extension, please contribute a set with 1. code 2. code documentation 3. regression tests in t/ **Please note:** When you contribute in any way, you agree to transfer the copyrights to Mark Overmeer (you will get the honors in the code and/or ChangeLog). You also automatically agree that your contribution is released under the same license as this project: licensed as perl itself. ## Copyright and License This project is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See Hash-Case-1.07/xt/0000755000175000001440000000000015135665445014364 5ustar00markovusers00000000000000Hash-Case-1.07/xt/99pod.t0000644000175000001440000000041715055526634015514 0ustar00markovusers00000000000000#!/usr/bin/env perl use warnings; use strict; use Test::More; BEGIN { eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; plan skip_all => "devel home uses OODoc" if $ENV{MARKOV_DEVEL}; } all_pod_files_ok(); Hash-Case-1.07/META.yml0000644000175000001440000000216415135665445015205 0ustar00markovusers00000000000000--- abstract: 'Play trics with HASH keys' author: - 'Mark Overmeer ' build_requires: ExtUtils::MakeMaker: '0' Test::More: '1' Test::Pod: '1' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.76, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Hash-Case no_index: directory: - t - inc recommends: {} requires: Carp: '0' Tie::Hash: '0' resources: bugtracker: https://github.com/markov2/perl5-Hash-Case/issues homepage: http://perl.overmeer.net/CPAN/ repository: https://github.com/markov2/perl5-Hash-Case.git version: '1.07' x_oodist: email: markov@cpan.org first_year: 2002 generate: - format: pod3 podtail: ~ include: [] oodoc_version: 3.06 parser: pmhead: ~ skip_links: - Tie::StdHash syntax: markov raw: publish: ../public_html/hash-case/raw release: publish: ../public_html/hash-case/source tests: {} use: [] x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Hash-Case-1.07/META.json0000644000175000001440000000420215135665445015350 0ustar00markovusers00000000000000{ "abstract" : "Play trics with HASH keys", "author" : [ "Mark Overmeer " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.76, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Hash-Case", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "OODoc" : "3.00" } }, "runtime" : { "recommends" : {}, "requires" : { "Carp" : "0", "Tie::Hash" : "0" }, "suggests" : {} }, "test" : { "requires" : { "Test::More" : "1", "Test::Pod" : "1" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/markov2/perl5-Hash-Case/issues" }, "homepage" : "http://perl.overmeer.net/CPAN/", "repository" : { "type" : "git", "url" : "https://github.com/markov2/perl5-Hash-Case.git", "web" : "https://github.com/markov2/perl5-Hash-Case" } }, "version" : "1.07", "x_oodist" : { "email" : "markov@cpan.org", "first_year" : 2002, "generate" : [ { "format" : "pod3", "podtail" : null } ], "include" : [], "oodoc_version" : 3.06, "parser" : { "pmhead" : null, "skip_links" : [ "Tie::StdHash" ], "syntax" : "markov" }, "raw" : { "publish" : "../public_html/hash-case/raw" }, "release" : { "publish" : "../public_html/hash-case/source" }, "tests" : {}, "use" : [] }, "x_serialization_backend" : "JSON::PP version 4.16" }