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