line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Memoize::HashKey::Ignore; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
220575
|
use 5.006; |
|
3
|
|
|
|
|
44
|
|
4
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
92
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
142
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1472
|
use Syntax::Keyword::Try; |
|
3
|
|
|
|
|
6857
|
|
|
3
|
|
|
|
|
15
|
|
8
|
3
|
|
|
3
|
|
1431
|
use Memoize; |
|
3
|
|
|
|
|
4963
|
|
|
3
|
|
|
|
|
1644
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Memoize::HashKey::Ignore - allow certain keys not to be memoized. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
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
|
|
1527
|
my ($package, %args) = @_; |
39
|
6
|
|
100
|
|
|
33
|
my $cache = $args{HASH} || {}; |
40
|
|
|
|
|
|
|
|
41
|
6
|
100
|
100
|
|
|
30
|
if ($args{IGNORE} and not ref $args{IGNORE} eq 'CODE') { |
42
|
1
|
|
|
|
|
13
|
die 'Memoize::HashKey::Ignore: IGNORE argument must be a code ref.'; |
43
|
|
|
|
|
|
|
} |
44
|
5
|
100
|
|
|
|
16
|
if ($args{TIE}) { |
45
|
1
|
|
|
|
|
3
|
my ($module, @opts) = @{$args{TIE}}; |
|
1
|
|
|
|
|
4
|
|
46
|
1
|
|
|
|
|
4
|
my $modulefile = $module . '.pm'; |
47
|
1
|
|
|
|
|
3
|
$modulefile =~ s{::}{/}g; |
48
|
|
|
|
|
|
|
try { require $modulefile } |
49
|
1
|
|
|
|
|
4
|
catch ($e) { |
50
|
|
|
|
|
|
|
die 'Memoize::HashKey::Ignore: Could not load hash tie module "' . $module . '": ' . $e; |
51
|
|
|
|
|
|
|
} |
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
|
|
|
|
|
9
|
$args{CACHE} = $cache; |
62
|
4
|
|
|
|
|
18
|
return bless \%args => $package; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub EXISTS { |
66
|
63
|
|
|
63
|
|
8220
|
my ($self, $key) = @_; |
67
|
63
|
100
|
|
|
|
171
|
return (exists $self->{CACHE}->{$key}) ? 1 : 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub FETCH { |
71
|
36
|
|
|
36
|
|
202
|
my ($self, $key) = @_; |
72
|
36
|
|
|
|
|
131
|
return $self->{CACHE}->{$key}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub CLEAR { |
76
|
2
|
|
|
2
|
|
1107
|
my ($self) = @_; |
77
|
2
|
|
|
|
|
9
|
$self->{CACHE} = {}; |
78
|
2
|
|
|
|
|
5
|
return $self->{CACHE}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub STORE { |
82
|
27
|
|
|
27
|
|
333
|
my ($self, $key, $value) = @_; |
83
|
|
|
|
|
|
|
|
84
|
27
|
100
|
66
|
|
|
69
|
if (not defined $self->{IGNORE} or not &{$self->{IGNORE}}($key)) { |
|
27
|
|
|
|
|
54
|
|
85
|
21
|
|
|
|
|
114
|
$self->{CACHE}->{$key} = $value; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
27
|
|
|
|
|
82
|
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 |