| 1 | # Copyrights 2002-2020 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||
| 5 | # This code is part of distribution Hash::Case. Meta-POD processed with | ||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | package Hash::Case; | ||||||||||||||||||
| 10 | 4 | ▶ | use vars '$VERSION'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 4 | $VERSION = '1.05'; | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 4 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 15 | 4 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 4 | ▶ | use Tie::Hash; # contains Tie::StdHash | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 18 | 4 | ▶ | use base 'Tie::StdHash'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 19 | 4 | ▶ | use Carp qw(croak); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | sub TIEHASH(@) | ||||||||||||||||||
| 23 | 13 | ▶ | { my $class = shift; | ||||||||||||||||
|
Subroutine
TIEHASH: called CC=2 SCAR=6.9
| |||||||||||||||||||
| 24 | 13 | ▶ | my $to = @_ % 2 ? shift : undef; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 25 | 13 | my %opts = (@_, add => $to); | |||||||||||||||||
| 26 | 13 | (bless {}, $class)->init( \%opts ); | |||||||||||||||||
| 27 | } | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | # Used for case-insensitive hashes which do not need more than | ||||||||||||||||||
| 30 | # one hash. | ||||||||||||||||||
| 31 | sub native_init($) | ||||||||||||||||||
| 32 | 13 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||
|
Subroutine
native_init: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||
| 33 | 13 | my $add = delete $args->{add}; | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 13 | ▶ | if(!$add) { ; } | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 36 | 4 | elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } | |||||||||||||||||
| 37 | 4 | elsif(ref $add eq 'HASH') { $self->addHashData($add) } | |||||||||||||||||
| 38 | 0 | else { croak "cannot initialize the native hash this way" } | |||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | 13 | $self; | |||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | # Used for case-insensitive hashes which are implemented around | ||||||||||||||||||
| 44 | # an existing hash. | ||||||||||||||||||
| 45 | sub wrapper_init($) | ||||||||||||||||||
| 46 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||
|
Subroutine
wrapper_init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||
| 47 | 0 | my $add = delete $args->{add}; | |||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | 0 | ▶ | if(!$add) { ; } | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 50 | 0 | elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } | |||||||||||||||||
| 51 | 0 | elsif(ref $add eq 'HASH') { $self->setHash($add) } | |||||||||||||||||
| 52 | 0 | else { croak "cannot initialize a wrapping hash this way" } | |||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | 0 | $self; | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | sub addPairs(@) | ||||||||||||||||||
| 59 | 4 | ▶ | { my $self = shift; | ||||||||||||||||
|
Subroutine
addPairs: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 60 | 4 | ▶ | $self->STORE(shift, shift) while @_; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 61 | 4 | $self; | |||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | sub addHashData($) | ||||||||||||||||||
| 66 | 4 | ▶ | { my ($self, $data) = @_; | ||||||||||||||||
|
Subroutine
addHashData: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 67 | 4 | ▶ | while(my ($k, $v) = each %$data) { $self->STORE($k, $v) } | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 68 | 4 | $self; | |||||||||||||||||
| 69 | } | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | sub setHash($) | ||||||||||||||||||
| 73 | 0 | ▶ | { my ($self, $hash) = @_; # the native implementation is the default. | ||||||||||||||||
|
Subroutine
setHash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 74 | 0 | %$self = %$hash; | |||||||||||||||||
| 75 | 0 | $self; | |||||||||||||||||
| 76 | } | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | 4 | 1; | |||||||||||||||||