line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2002-2020 by [Mark Overmeer ]. |
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
|
|
|
4
|
|
31
|
use vars '$VERSION'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
187
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.05'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
115
|
|
15
|
4
|
|
|
4
|
|
17
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
85
|
|
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
|
2013
|
use Tie::Hash; # contains Tie::StdHash |
|
4
|
|
|
|
|
4034
|
|
|
4
|
|
|
|
|
124
|
|
18
|
4
|
|
|
4
|
|
26
|
use base 'Tie::StdHash'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1435
|
|
19
|
4
|
|
|
4
|
|
29
|
use Carp qw(croak); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1862
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub TIEHASH(@) |
23
|
13
|
|
|
13
|
|
3242
|
{ my $class = shift; |
24
|
13
|
100
|
|
|
|
53
|
my $to = @_ % 2 ? shift : undef; |
25
|
13
|
|
|
|
|
44
|
my %opts = (@_, add => $to); |
26
|
13
|
|
|
|
|
52
|
(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
|
|
|
13
|
0
|
27
|
{ my ($self, $args) = @_; |
33
|
13
|
|
|
|
|
26
|
my $add = delete $args->{add}; |
34
|
|
|
|
|
|
|
|
35
|
13
|
100
|
|
|
|
70
|
if(!$add) { ; } |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
4
|
|
|
|
|
31
|
elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } |
37
|
4
|
|
|
|
|
27
|
elsif(ref $add eq 'HASH') { $self->addHashData($add) } |
38
|
0
|
|
|
|
|
0
|
else { croak "cannot initialize the native hash this way" } |
39
|
|
|
|
|
|
|
|
40
|
13
|
|
|
|
|
46
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Used for case-insensitive hashes which are implemented around |
44
|
|
|
|
|
|
|
# an existing hash. |
45
|
|
|
|
|
|
|
sub wrapper_init($) |
46
|
0
|
|
|
0
|
0
|
0
|
{ my ($self, $args) = @_; |
47
|
0
|
|
|
|
|
0
|
my $add = delete $args->{add}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
0
|
if(!$add) { ; } |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } |
51
|
0
|
|
|
|
|
0
|
elsif(ref $add eq 'HASH') { $self->setHash($add) } |
52
|
0
|
|
|
|
|
0
|
else { croak "cannot initialize a wrapping hash this way" } |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
$self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub addPairs(@) |
59
|
4
|
|
|
4
|
1
|
13
|
{ my $self = shift; |
60
|
4
|
|
|
|
|
18
|
$self->STORE(shift, shift) while @_; |
61
|
4
|
|
|
|
|
9
|
$self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub addHashData($) |
66
|
4
|
|
|
4
|
1
|
11
|
{ my ($self, $data) = @_; |
67
|
4
|
|
|
|
|
24
|
while(my ($k, $v) = each %$data) { $self->STORE($k, $v) } |
|
8
|
|
|
|
|
22
|
|
68
|
4
|
|
|
|
|
7
|
$self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub setHash($) |
73
|
0
|
|
|
0
|
1
|
|
{ my ($self, $hash) = @_; # the native implementation is the default. |
74
|
0
|
|
|
|
|
|
%$self = %$hash; |
75
|
0
|
|
|
|
|
|
$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |