line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::Approx;
|
2
|
2
|
|
|
2
|
|
136219
|
use strict;
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
112
|
|
3
|
2
|
|
|
2
|
|
15
|
use vars qw($VERSION @ISA);
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2898
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter;
|
6
|
|
|
|
|
|
|
require Tie::Hash;
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
5293
|
use String::Approx('amatch');
|
|
2
|
|
|
|
|
39025
|
|
|
2
|
|
|
|
|
881
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter Tie::StdHash);
|
11
|
|
|
|
|
|
|
$VERSION = '0.03';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub FETCH {
|
14
|
3
|
|
|
3
|
|
477
|
my $this = shift;
|
15
|
3
|
|
|
|
|
6
|
my $key = shift;
|
16
|
|
|
|
|
|
|
|
17
|
3
|
50
|
|
|
|
4
|
return undef unless %{$this}; # return if the hash is empty
|
|
3
|
|
|
|
|
11
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# We return immediatly if an exact match is found
|
20
|
3
|
100
|
|
|
|
13
|
return $this->{$key} if exists $this->{$key};
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Otherwise, the fuzzy search kicks in
|
23
|
2
|
|
|
|
|
4
|
my @results = amatch( $key, keys( %{$this} ) );
|
|
2
|
|
|
|
|
11
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# wantarray doesn't work on tied hash, unless
|
27
|
|
|
|
|
|
|
# you're using a "tied(%hash)->FETCH('foo');"
|
28
|
|
|
|
|
|
|
# construct
|
29
|
2
|
100
|
|
|
|
91
|
if (wantarray) {
|
30
|
1
|
|
|
|
|
3
|
return @{$this}{@results};
|
|
1
|
|
|
|
|
8
|
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
else {
|
33
|
1
|
|
|
|
|
8
|
return $this->{ $results[0] };
|
34
|
|
|
|
|
|
|
}
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub EXISTS {
|
38
|
6
|
|
|
6
|
|
704
|
my $this = shift;
|
39
|
6
|
|
|
|
|
9
|
my $key = shift;
|
40
|
|
|
|
|
|
|
|
41
|
6
|
100
|
|
|
|
7
|
return undef unless %{$this};
|
|
6
|
|
|
|
|
24
|
|
42
|
5
|
100
|
|
|
|
15
|
if ( $key eq '' ){
|
43
|
1
|
50
|
|
|
|
4
|
return 1 if exists $this->{''};
|
44
|
1
|
|
|
|
|
6
|
return 0;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
4
|
100
|
|
|
|
13
|
return 1 if exists $this->{$key};
|
48
|
3
|
100
|
|
|
|
5
|
return 1 if amatch( $key, keys( %{$this} ) );
|
|
3
|
|
|
|
|
11
|
|
49
|
2
|
|
|
|
|
58
|
return 0;
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub DELETE {
|
54
|
2
|
|
|
2
|
|
6
|
my $this = shift;
|
55
|
2
|
|
|
|
|
3
|
my $key = shift;
|
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
8
|
return delete $this->{$key} if exists $this->{$key};
|
58
|
2
|
|
|
|
|
4
|
my @results = amatch( $key, keys( %{$this} ) );
|
|
2
|
|
|
|
|
11
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# This will delete *all* the keys matching!
|
61
|
2
|
|
|
|
|
838
|
delete @{$this}{ @results };
|
|
2
|
|
|
|
|
11
|
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1;
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__
|