line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Memory::Simple::ID; |
2
|
3
|
|
|
3
|
|
78191
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
83
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
81
|
|
4
|
3
|
|
|
3
|
|
2573
|
use Time::HiRes; |
|
3
|
|
|
|
|
4758
|
|
|
3
|
|
|
|
|
14
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
7
|
|
|
7
|
1
|
12733
|
my ($class) = @_; |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
|
|
26
|
bless +[], $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get { |
15
|
19
|
|
|
19
|
1
|
400496
|
my $val = $_[0]->[$_[1]]; |
16
|
19
|
100
|
100
|
|
|
126
|
if ($val && defined $val->[0]) { |
17
|
6
|
100
|
|
|
|
46
|
if ($val->[0] > Time::HiRes::time() ) { |
18
|
4
|
|
|
|
|
46
|
return $val->[1]; |
19
|
|
|
|
|
|
|
} else { |
20
|
2
|
|
|
|
|
23
|
$_[0]->[$_[1]] = undef; # remove expired data |
21
|
2
|
|
|
|
|
31
|
return undef; ## no critic |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} else { |
24
|
13
|
|
|
|
|
59
|
return $val->[1]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_or_set { |
29
|
0
|
|
|
0
|
1
|
0
|
my ($self, $id, $code, $expiration) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
0
|
if (my $val = $self->get($id)) { |
32
|
0
|
|
|
|
|
0
|
return $val; |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
0
|
my $val = $code->(); |
35
|
0
|
|
|
|
|
0
|
$self->set($id, $val, $expiration); |
36
|
0
|
|
|
|
|
0
|
return $val; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub set { |
41
|
10
|
|
|
10
|
1
|
35
|
my ($self, $id, $val, $expiration) = @_; |
42
|
|
|
|
|
|
|
|
43
|
10
|
100
|
|
|
|
53
|
$self->[$id] = [defined($expiration) |
44
|
|
|
|
|
|
|
? $expiration + Time::HiRes::time() |
45
|
|
|
|
|
|
|
: undef, |
46
|
|
|
|
|
|
|
$val]; |
47
|
10
|
|
|
|
|
50
|
return $val; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub delete :method { |
51
|
3
|
|
|
3
|
1
|
7
|
my ($self, $id) = @_; |
52
|
3
|
|
|
|
|
8
|
$self->[$id] = undef; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
1
|
1
|
4
|
sub remove { shift->delete(@_) } # alias |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub delete_all { |
57
|
1
|
|
|
1
|
1
|
5
|
@{$_[0]} = (); |
|
1
|
|
|
|
|
4
|
|
58
|
1
|
|
|
|
|
2
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub purge { |
62
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
1
|
my $id; |
65
|
1
|
|
|
|
|
2
|
for ($id = 0; $id < $#{$self}; $id++) { |
|
79
|
|
|
|
|
172
|
|
66
|
78
|
100
|
100
|
|
|
197
|
if (defined($self->[$id]) && $self->[$id][0] < Time::HiRes::time() ) { |
67
|
1
|
|
|
|
|
12
|
$self->delete($id); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub count { |
73
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
3
|
my $count = 0; |
76
|
2
|
|
|
|
|
3
|
for my $id (@{$self}) { |
|
2
|
|
|
|
|
7
|
|
77
|
158
|
100
|
|
|
|
381
|
$count++ if ref($id) eq 'ARRAY'; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
8
|
return $count; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |