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