line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Cache::Autoupdater; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
6608
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
292
|
|
4
|
8
|
|
|
8
|
|
44
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
279
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
15072
|
use Storable 'dclone'; |
|
8
|
|
|
|
|
43971
|
|
|
8
|
|
|
|
|
984
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
8
|
|
|
8
|
|
22
|
eval { require Time::HiRes; }; |
|
8
|
|
|
|
|
21952
|
|
10
|
8
|
50
|
|
|
|
16927
|
Time::HiRes->import('time') unless $@; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.21; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub TIEHASH { |
16
|
8
|
|
|
8
|
|
6075
|
my $class = shift; |
17
|
8
|
|
|
|
|
1168
|
my %structure = @_; |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
|
|
17
|
my $self = {}; |
20
|
8
|
|
|
|
|
666
|
while ( my ($k, $v) = each %structure ) { |
21
|
4
|
100
|
50
|
|
|
46
|
$self->{ $k } = { |
22
|
|
|
|
|
|
|
timeout => $v->{timeout} || 1, |
23
|
|
|
|
|
|
|
source => $v->{source}, |
24
|
|
|
|
|
|
|
last => 0, |
25
|
|
|
|
|
|
|
result => undef, |
26
|
|
|
|
|
|
|
clone => $v->{clone} ? 1 : 0 |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
73
|
bless $self, $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub FETCH { |
34
|
53
|
|
|
53
|
|
22640195
|
my ( $self, $k ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
53
|
50
|
|
|
|
230
|
return undef unless exists $self->{ $k }; |
37
|
53
|
|
|
|
|
158
|
_fetch( $_[0], $k ) |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub STORE { |
41
|
9
|
|
|
9
|
|
122
|
my ( $self, $k, $v ) = @_; |
42
|
9
|
100
|
50
|
|
|
157
|
$self->{ $k } = { |
43
|
|
|
|
|
|
|
timeout => $v->{timeout} || 1, |
44
|
|
|
|
|
|
|
source => $v->{source}, |
45
|
|
|
|
|
|
|
last => 0, |
46
|
|
|
|
|
|
|
result => undef, |
47
|
|
|
|
|
|
|
clone => $v->{clone} ? 1 : 0 |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub FIRSTKEY { |
52
|
0
|
|
|
0
|
|
0
|
keys %{$_[0]}; |
|
0
|
|
|
|
|
0
|
|
53
|
0
|
|
|
|
|
0
|
my ( $k, $v ) = each %{$_[0]}; |
|
0
|
|
|
|
|
0
|
|
54
|
0
|
|
|
|
|
0
|
_fetch( $_[0], $k ) |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub NEXTKEY { |
58
|
0
|
|
|
0
|
|
0
|
my ( $k, $v ) = each %{$_[0]}; |
|
0
|
|
|
|
|
0
|
|
59
|
0
|
|
|
|
|
0
|
_fetch( $_[0], $k ) |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
0
|
|
0
|
sub EXISTS { exists $_[0]->{ $_[1] } } |
63
|
0
|
|
|
0
|
|
0
|
sub DELETE { delete $_[0]->{ $_[1] } } |
64
|
0
|
|
|
0
|
|
0
|
sub CLEAR { %{ $_[0] } = () } |
|
0
|
|
|
|
|
0
|
|
65
|
0
|
|
|
0
|
|
0
|
sub SCALAR { scalar %{ $_[0] } } |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
0
|
|
0
|
sub UNTIE { $_[0] = undef } |
67
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _fetch { |
70
|
53
|
|
|
53
|
|
98
|
my ( $self, $k ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
53
|
100
|
|
|
|
398
|
if ( $self->{$k}{last} + $self->{$k}{timeout} < time() ) { |
73
|
|
|
|
|
|
|
|
74
|
29
|
|
|
|
|
80
|
my @result = eval { $self->{$k}{source}->() }; |
|
29
|
|
|
|
|
143
|
|
75
|
29
|
50
|
|
|
|
187
|
if ( $@ ) { |
76
|
0
|
|
|
|
|
0
|
warn qq/Check source subroutine for key $k. Error - $@\n/; |
77
|
|
|
|
|
|
|
return undef |
78
|
0
|
|
|
|
|
0
|
} |
79
|
|
|
|
|
|
|
|
80
|
29
|
100
|
|
|
|
590
|
if ( @result == 1 ) { |
|
|
50
|
|
|
|
|
|
81
|
27
|
|
|
|
|
70
|
$self->{$k}{result} = $result[0]; |
82
|
|
|
|
|
|
|
} elsif ( !@result ) { |
83
|
0
|
|
|
|
|
0
|
$self->{$k}{result} = undef; |
84
|
|
|
|
|
|
|
} else { |
85
|
2
|
|
|
|
|
9
|
$self->{$k}{result} = \@result; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
29
|
|
|
|
|
117
|
$self->{$k}{last} = time(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
53
|
100
|
66
|
|
|
845
|
return $self->{$k}{clone} && ref $self->{$k}{result} |
92
|
|
|
|
|
|
|
? dclone($self->{$k}{result}) |
93
|
|
|
|
|
|
|
: $self->{$k}{result}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |