line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::Check; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
11
|
|
|
11
|
|
46280
|
use strict; |
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
241
|
|
5
|
11
|
|
|
11
|
|
32
|
use warnings; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
238
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
8
|
11
|
|
|
11
|
|
4060
|
use Error::Pure qw(err); |
|
11
|
|
|
|
|
63644
|
|
|
11
|
|
|
|
|
192
|
|
9
|
11
|
|
|
11
|
|
461
|
use Error::Pure::Utils; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
4577
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Version. |
12
|
|
|
|
|
|
|
our $VERSION = 0.08; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Error level. |
15
|
|
|
|
|
|
|
$Error::Pure::Utils::LEVEL = 5; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Hash create. |
18
|
|
|
|
|
|
|
sub TIEHASH { |
19
|
17
|
|
|
17
|
|
14445
|
my ($class, $hash_hr, $stack_ar) = @_; |
20
|
17
|
100
|
|
|
|
53
|
if (ref $hash_hr ne 'HASH') { |
21
|
1
|
|
|
|
|
5
|
err 'Parameter isn\'t hash.'; |
22
|
|
|
|
|
|
|
} |
23
|
16
|
100
|
|
|
|
34
|
if (! $stack_ar) { |
24
|
11
|
|
|
|
|
19
|
$stack_ar = []; |
25
|
|
|
|
|
|
|
} |
26
|
16
|
100
|
|
|
|
48
|
if (ref $stack_ar ne 'ARRAY') { |
27
|
1
|
|
|
|
|
2
|
err 'Stack isn\'t array.'; |
28
|
|
|
|
|
|
|
} |
29
|
15
|
|
|
|
|
27
|
my $self = bless {}, $class; |
30
|
15
|
|
|
|
|
49
|
$self->{'data'} = {}; |
31
|
15
|
|
|
|
|
14
|
foreach my $key (keys %{$hash_hr}) { |
|
15
|
|
|
|
|
42
|
|
32
|
21
|
|
|
|
|
50
|
_add_hash_value($self->{'data'}, $key, $hash_hr->{$key}, |
33
|
|
|
|
|
|
|
$stack_ar); |
34
|
|
|
|
|
|
|
} |
35
|
15
|
|
|
|
|
26
|
$self->{'stack'} = $stack_ar; |
36
|
15
|
|
|
|
|
40
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Hash clear. |
40
|
|
|
|
|
|
|
sub CLEAR { |
41
|
1
|
|
|
1
|
|
404
|
my $self = shift; |
42
|
1
|
|
|
|
|
2
|
$self->{'data'} = {}; |
43
|
1
|
|
|
|
|
3
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Hash delete. |
47
|
|
|
|
|
|
|
sub DELETE { |
48
|
2
|
|
|
2
|
|
11941
|
my ($self, $key) = @_; |
49
|
2
|
|
|
|
|
5
|
delete $self->{'data'}->{$key}; |
50
|
2
|
|
|
|
|
5
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Hash exists. |
54
|
|
|
|
|
|
|
sub EXISTS { |
55
|
17
|
|
|
17
|
|
95
|
my ($self, $key) = @_; |
56
|
17
|
|
|
|
|
40
|
return exists $self->{'data'}->{$key}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Hash fetch. |
60
|
|
|
|
|
|
|
sub FETCH { |
61
|
30
|
|
|
30
|
|
13470
|
my ($self, $key) = @_; |
62
|
30
|
100
|
|
|
|
69
|
if (! exists $self->{'data'}->{$key}) { |
63
|
5
|
|
|
|
|
8
|
my @stack = (@{$self->{'stack'}}, $key); |
|
5
|
|
|
|
|
12
|
|
64
|
5
|
|
|
|
|
29
|
err 'Key \''.join('->', @stack).'\' doesn\'t exist.'; |
65
|
|
|
|
|
|
|
} |
66
|
25
|
|
|
|
|
55
|
return $self->{'data'}->{$key}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Hash first key. |
70
|
|
|
|
|
|
|
sub FIRSTKEY { |
71
|
20
|
|
|
20
|
|
5081
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Resets each. |
74
|
20
|
|
|
|
|
23
|
my $a = scalar keys %{$self->{'data'}}; |
|
20
|
|
|
|
|
39
|
|
75
|
|
|
|
|
|
|
|
76
|
20
|
|
|
|
|
19
|
return each %{$self->{'data'}}; |
|
20
|
|
|
|
|
64
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Hash nextkey. |
80
|
|
|
|
|
|
|
sub NEXTKEY { |
81
|
24
|
|
|
24
|
|
1350
|
my $self= shift; |
82
|
24
|
|
|
|
|
19
|
return each %{$self->{'data'}}; |
|
24
|
|
|
|
|
62
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Hash scalar. |
86
|
|
|
|
|
|
|
sub SCALAR { |
87
|
1
|
|
|
1
|
|
6
|
my $self = shift; |
88
|
1
|
|
|
|
|
2
|
return scalar %{$self->{'data'}}; |
|
1
|
|
|
|
|
4
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Hash store. |
92
|
|
|
|
|
|
|
sub STORE { |
93
|
2
|
|
|
2
|
|
3839
|
my ($self, $key, $value) = @_; |
94
|
2
|
|
|
|
|
6
|
_add_hash_value($self->{'data'}, $key, $value, $self->{'stack'}); |
95
|
2
|
|
|
|
|
3
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Add hash value to storage. |
99
|
|
|
|
|
|
|
sub _add_hash_value { |
100
|
23
|
|
|
23
|
|
29
|
my ($hash_hr, $key, $value, $stack_ar) = @_; |
101
|
23
|
100
|
|
|
|
50
|
if (ref $value eq 'HASH') { |
102
|
|
|
|
|
|
|
tie my %tmp, 'Tie::Hash::Check', $value, |
103
|
4
|
|
|
|
|
5
|
[@{$stack_ar}, $key]; |
|
4
|
|
|
|
|
19
|
|
104
|
4
|
|
|
|
|
10
|
$hash_hr->{$key} = \%tmp; |
105
|
|
|
|
|
|
|
} else { |
106
|
19
|
|
|
|
|
29
|
$hash_hr->{$key} = $value; |
107
|
|
|
|
|
|
|
} |
108
|
23
|
|
|
|
|
32
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |