line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::Longest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION='1.1'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
847
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
177
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub TIEHASH { |
8
|
1
|
|
|
1
|
|
63
|
my $class = shift; |
9
|
1
|
|
|
|
|
5
|
my $self = CLEAR({}); |
10
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub longestkey { |
14
|
3
|
|
|
3
|
1
|
115
|
my $self = shift; |
15
|
3
|
100
|
|
|
|
14
|
rescan($self) if($self->{RESCAN_NEEDED}); |
16
|
3
|
|
|
|
|
8
|
$self->{KEY}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub longestvalue { |
20
|
5
|
|
|
5
|
1
|
93
|
my $self = shift; |
21
|
5
|
100
|
|
|
|
16
|
rescan($self) if($self->{RESCAN_NEEDED}); |
22
|
5
|
|
|
|
|
14
|
$self->{VALUE}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# the no warnings here (and the one later) are so we can take length(undef) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub rescan { |
28
|
1
|
|
|
1
|
|
7
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
195
|
|
29
|
3
|
|
|
3
|
0
|
4
|
my $self = shift; |
30
|
3
|
|
|
|
|
7
|
$self->{KEY} = $self->{VALUE} = undef; |
31
|
3
|
|
|
|
|
4
|
foreach (keys %{$self->{CURRENT_STATE}}) { |
|
3
|
|
|
|
|
12
|
|
32
|
14
|
100
|
|
|
|
37
|
$self->{KEY} = $_ if(length($_) > length($self->{KEY})); |
33
|
14
|
100
|
|
|
|
48
|
$self->{VALUE} = $self->{CURRENT_STATE}->{$_} |
34
|
|
|
|
|
|
|
if(length($self->{CURRENT_STATE}->{$_}) > length($self->{VALUE})); |
35
|
|
|
|
|
|
|
} |
36
|
3
|
|
|
|
|
7
|
$self->{RESCAN_NEEDED} = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub CLEAR { |
40
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
41
|
1
|
|
|
|
|
7
|
$self = { |
42
|
|
|
|
|
|
|
KEY => undef, |
43
|
|
|
|
|
|
|
VALUE => undef, |
44
|
|
|
|
|
|
|
CURRENT_STATE => {}, |
45
|
|
|
|
|
|
|
RESCAN_NEEDED => 0 |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub STORE { |
50
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
390
|
|
51
|
9
|
|
|
9
|
|
130
|
my($self, $key, $value)=@_; |
52
|
9
|
100
|
|
|
|
24
|
$self->{KEY} = $key unless(defined($self->{KEY})); |
53
|
9
|
100
|
|
|
|
17
|
$self->{VALUE} = $value unless(defined($self->{VALUE})); |
54
|
9
|
100
|
100
|
|
|
49
|
$self->{RESCAN_NEEDED} = 1 if( |
55
|
|
|
|
|
|
|
length($key) == length($self->{KEY}) || |
56
|
|
|
|
|
|
|
length($self->{CURRENT_STATE}->{$key}) == length($self->{VALUE}) |
57
|
|
|
|
|
|
|
); |
58
|
9
|
|
|
|
|
18
|
$self->{CURRENT_STATE}->{$key} = $value; |
59
|
9
|
100
|
|
|
|
20
|
$self->{KEY} = $key if(length($key) > length($self->{KEY})); |
60
|
9
|
100
|
|
|
|
43
|
$self->{VALUE} = $value if(length($value) > length($self->{VALUE})); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub FETCH { |
64
|
6
|
|
|
6
|
|
27
|
my($self, $key) = @_; |
65
|
6
|
|
|
|
|
28
|
$self->{CURRENT_STATE}->{$key}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub FIRSTKEY { |
69
|
1
|
|
|
1
|
|
8
|
my $self = shift; |
70
|
1
|
|
|
|
|
1
|
scalar keys %{$self->{CURRENT_STATE}}; |
|
1
|
|
|
|
|
4
|
|
71
|
1
|
|
|
|
|
2
|
scalar each %{$self->{CURRENT_STATE}}; |
|
1
|
|
|
|
|
8
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub DELETE { |
75
|
3
|
|
|
3
|
|
66
|
my($self, $key) = @_; |
76
|
3
|
100
|
100
|
|
|
20
|
$self->{RESCAN_NEEDED} = 1 if( |
77
|
|
|
|
|
|
|
$key eq $self->{KEY} || |
78
|
|
|
|
|
|
|
$self->{CURRENT_STATE}->{$key} eq $self->{VALUE} |
79
|
|
|
|
|
|
|
); |
80
|
3
|
|
|
|
|
11
|
delete $self->{CURRENT_STATE}->{$key}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
6
|
|
|
6
|
|
7
|
sub NEXTKEY { my $self = shift; scalar each %{$self->{CURRENT_STATE}}; } |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
37
|
|
84
|
3
|
|
|
3
|
|
17
|
sub EXISTS { my($self, $key) = @_; exists($self->{CURRENT_STATE}->{$key}); } |
|
3
|
|
|
|
|
11
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |