line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YAML::LoadFileCached; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: LoadFileCached.pm,v 1.3 2003/02/03 12:10:01 florian Exp $ |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
9591
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
36
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1398
|
use YAML qw(LoadFile); |
|
1
|
|
|
|
|
27464
|
|
|
1
|
|
|
|
|
768
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
17
|
|
|
|
|
|
|
CacheStatistics |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
our @EXPORT = qw( |
20
|
|
|
|
|
|
|
LoadFileCached |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $cache; |
25
|
|
|
|
|
|
|
my $statistic; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub LoadFileCached |
28
|
|
|
|
|
|
|
{ |
29
|
1001
|
|
|
1001
|
1
|
1006470
|
my($filepath) = @_; |
30
|
|
|
|
|
|
|
|
31
|
1001
|
50
|
|
|
|
4153
|
return undef unless defined $filepath; |
32
|
|
|
|
|
|
|
|
33
|
1001
|
100
|
100
|
|
|
18266
|
if(exists($cache->{$filepath}) && ($statistic->{$filepath}->{'lastchanged'} == (stat($filepath))[9])) |
34
|
|
|
|
|
|
|
{ |
35
|
999
|
|
|
|
|
1819
|
$statistic->{$filepath}->{'cached'}++; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else |
38
|
|
|
|
|
|
|
{ |
39
|
2
|
|
|
|
|
16
|
$cache->{$filepath} = LoadFile($filepath); |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
31689
|
$statistic->{$filepath}->{'lastchanged'} = (stat($filepath))[9]; |
42
|
2
|
|
|
|
|
12
|
$statistic->{$filepath}->{'read'}++; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1001
|
|
|
|
|
3144
|
return $cache->{$filepath}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub CacheStatistics |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
1
|
29
|
my ($filepath) = @_; |
52
|
|
|
|
|
|
|
|
53
|
2
|
50
|
|
|
|
11
|
return $statistic unless defined $filepath; |
54
|
|
|
|
|
|
|
|
55
|
2
|
50
|
|
|
|
14
|
return exists($statistic->{$filepath}) ? $statistic->{$filepath} : undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |