line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Memoize::HashKey::Ignore; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
214278
|
use 5.006; |
|
3
|
|
|
|
|
36
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
69
|
|
5
|
3
|
|
|
3
|
|
13
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
133
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1235
|
use Try::Tiny; |
|
3
|
|
|
|
|
5122
|
|
|
3
|
|
|
|
|
131
|
|
8
|
3
|
|
|
3
|
|
1143
|
use Memoize; |
|
3
|
|
|
|
|
4008
|
|
|
3
|
|
|
|
|
1140
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Memoize::HashKey::Ignore - allow certain keys not to be memoized. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Memoize; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
tie my %scalar_cache = 'Memoize::HashKey::Ignore', IGNORE => sub { my $key = shift, return ($key eq 'BROKENKEY') ? 1 : 0; }; |
23
|
|
|
|
|
|
|
tie my %list_cache = 'Memoize::HashKey::Ignore', IGNORE => sub { my $key = shift, return ($key eq 'BROKENKEY') ? 1 : 0; }; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
memoize('function', SCALAR_CACHE => [ HASH => \%scalar_cache ], LIST_CACHE => [ HASH => \%list_cache ]); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 EXPORT |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Sometimes you don't want to store certain keys. You know what the values looks likes, but you can't easily write memoize function which culls them itself. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Memoize::HashKey::Ignore allows you to supply a code reference which describes, which keys should not be stored in Memoization Cache. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module will allow you to memoize the entire function with splitting it into cached and uncached pieces. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub TIEHASH { |
38
|
6
|
|
|
6
|
|
1827
|
my ($package, %args) = @_; |
39
|
6
|
|
100
|
|
|
39
|
my $cache = $args{HASH} || {}; |
40
|
|
|
|
|
|
|
|
41
|
6
|
100
|
100
|
|
|
38
|
if ($args{IGNORE} and not ref $args{IGNORE} eq 'CODE') { |
42
|
1
|
|
|
|
|
18
|
die 'Memoize::HashKey::Ignore: IGNORE argument must be a code ref.'; |
43
|
|
|
|
|
|
|
} |
44
|
5
|
100
|
|
|
|
17
|
if ($args{TIE}) { |
45
|
1
|
|
|
|
|
3
|
my ($module, @opts) = @{$args{TIE}}; |
|
1
|
|
|
|
|
3
|
|
46
|
1
|
|
|
|
|
3
|
my $modulefile = $module . '.pm'; |
47
|
1
|
|
|
|
|
3
|
$modulefile =~ s{::}{/}g; |
48
|
1
|
|
|
1
|
|
434
|
try { require $modulefile } |
49
|
|
|
|
|
|
|
catch { |
50
|
1
|
|
|
1
|
|
27
|
die 'Memoize::HashKey::Ignore: Could not load hash tie module "' . $module . '": ' . $_; |
51
|
1
|
|
|
|
|
12
|
}; |
52
|
0
|
|
|
|
|
0
|
my $rc = ( |
53
|
|
|
|
|
|
|
tie %$cache => $module, |
54
|
|
|
|
|
|
|
@opts |
55
|
|
|
|
|
|
|
); |
56
|
0
|
0
|
|
|
|
0
|
if (not $rc) { |
57
|
0
|
|
|
|
|
0
|
die 'Memoize::HashKey::Ignore Could not tie hash to "' . $module . '": ' . $@; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
4
|
|
|
|
|
12
|
$args{CACHE} = $cache; |
62
|
4
|
|
|
|
|
26
|
return bless \%args => $package; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub EXISTS { |
66
|
63
|
|
|
63
|
|
10549
|
my ($self, $key) = @_; |
67
|
63
|
100
|
|
|
|
230
|
return (exists $self->{CACHE}->{$key}) ? 1 : 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub FETCH { |
71
|
36
|
|
|
36
|
|
238
|
my ($self, $key) = @_; |
72
|
36
|
|
|
|
|
177
|
return $self->{CACHE}->{$key}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub CLEAR { |
76
|
2
|
|
|
2
|
|
1360
|
my ($self) = @_; |
77
|
2
|
|
|
|
|
9
|
$self->{CACHE} = {}; |
78
|
2
|
|
|
|
|
8
|
return $self->{CACHE}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub STORE { |
82
|
27
|
|
|
27
|
|
424
|
my ($self, $key, $value) = @_; |
83
|
|
|
|
|
|
|
|
84
|
27
|
100
|
66
|
|
|
89
|
if (not defined $self->{IGNORE} or not &{$self->{IGNORE}}($key)) { |
|
27
|
|
|
|
|
72
|
|
85
|
21
|
|
|
|
|
145
|
$self->{CACHE}->{$key} = $value; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
27
|
|
|
|
|
113
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
binary.com, C<< >> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 BUGS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
98
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
99
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
perldoc Memoize::HashKey::Ignore |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
You can also look for information at: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over 4 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * CPAN Ratings |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * Search CPAN |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; # End of Memoize::HashKey::Ignore |