line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2002-2003,2007-2012 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.00. |
5
|
4
|
|
|
4
|
|
27
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
134
|
|
6
|
4
|
|
|
4
|
|
18
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
150
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Hash::Case; |
9
|
4
|
|
|
4
|
|
23
|
use vars '$VERSION'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
189
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
4112
|
use Tie::Hash; # contains Tie::StdHash |
|
4
|
|
|
|
|
4476
|
|
|
4
|
|
|
|
|
125
|
|
14
|
4
|
|
|
4
|
|
26
|
use base 'Tie::StdHash'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2376
|
|
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
3541
|
use Log::Report 'hash-case'; |
|
4
|
|
|
|
|
520620
|
|
|
4
|
|
|
|
|
32
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEHASH(@) |
20
|
13
|
|
|
13
|
|
5268
|
{ my $class = shift; |
21
|
13
|
100
|
|
|
|
67
|
my $to = @_ % 2 ? shift : undef; |
22
|
13
|
|
|
|
|
59
|
my %opts = (@_, add => $to); |
23
|
13
|
|
|
|
|
90
|
(bless {}, $class)->init( \%opts ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Used for case-insensitive hashes which do not need more than |
27
|
|
|
|
|
|
|
# one hash. |
28
|
|
|
|
|
|
|
sub native_init($) |
29
|
13
|
|
|
13
|
0
|
28
|
{ my ($self, $args) = @_; |
30
|
13
|
|
|
|
|
34
|
my $add = delete $args->{add}; |
31
|
|
|
|
|
|
|
|
32
|
13
|
100
|
|
|
|
73
|
if(!$add) { ; } |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
33
|
4
|
|
|
|
|
41
|
elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } |
34
|
4
|
|
|
|
|
43
|
elsif(ref $add eq 'HASH') { $self->addHashData($add) } |
35
|
0
|
|
|
|
|
0
|
else { error "cannot initialize the native hash this way" } |
36
|
|
|
|
|
|
|
|
37
|
13
|
|
|
|
|
46
|
$self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Used for case-insensitive hashes which are implemented around |
41
|
|
|
|
|
|
|
# an existing hash. |
42
|
|
|
|
|
|
|
sub wrapper_init($) |
43
|
0
|
|
|
0
|
0
|
0
|
{ my ($self, $args) = @_; |
44
|
0
|
|
|
|
|
0
|
my $add = delete $args->{add}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
0
|
if(!$add) { ; } |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
elsif(ref $add eq 'ARRAY') { $self->addPairs(@$add) } |
48
|
0
|
|
|
|
|
0
|
elsif(ref $add eq 'HASH') { $self->setHash($add) } |
49
|
0
|
|
|
|
|
0
|
else { error "cannot initialize a wrapping hash this way" } |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub addPairs(@) |
56
|
4
|
|
|
4
|
1
|
9
|
{ my $self = shift; |
57
|
4
|
|
|
|
|
83
|
$self->STORE(shift, shift) while @_; |
58
|
4
|
|
|
|
|
9
|
$self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub addHashData($) |
63
|
4
|
|
|
4
|
1
|
10
|
{ my ($self, $data) = @_; |
64
|
4
|
|
|
|
|
30
|
while(my ($k, $v) = each %$data) { $self->STORE($k, $v) } |
|
8
|
|
|
|
|
42
|
|
65
|
4
|
|
|
|
|
10
|
$self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub setHash($) |
70
|
0
|
|
|
0
|
1
|
|
{ my ($self, $hash) = @_; # the native implementation is the default. |
71
|
0
|
|
|
|
|
|
%$self = %$hash; |
72
|
0
|
|
|
|
|
|
$self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |