line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
# Purpose : Cache data structures against a file |
3
|
|
|
|
|
|
|
# Author : John Alden |
4
|
|
|
|
|
|
|
# Created : 22 Apr 2005 (based on IFL::FileCache) |
5
|
|
|
|
|
|
|
# CVS : $Id: AgainstFile.pm,v 1.16 2006/05/09 09:04:29 mattheww Exp $ |
6
|
|
|
|
|
|
|
############################################################################### |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Cache::AgainstFile; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
8635
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
155
|
|
11
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
340
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
59
|
use vars qw($VERSION); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
5762
|
|
14
|
|
|
|
|
|
|
$VERSION = sprintf"%d.%03d", q$Revision: 1.16 $ =~ /: (\d+)\.(\d+)/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# API |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
sub new |
20
|
|
|
|
|
|
|
{ |
21
|
15
|
|
|
15
|
1
|
4914
|
my ($class, $loader, $options) = @_; |
22
|
15
|
|
|
|
|
40
|
my $usage = "USAGE: $class->new(\&loader, \%options)"; |
23
|
15
|
50
|
33
|
|
|
102
|
croak($usage) unless $loader && $options; |
24
|
15
|
100
|
|
|
|
322
|
croak($usage . ". Supplied loader is not a code reference") unless ref $loader eq 'CODE'; |
25
|
14
|
100
|
|
|
|
209
|
croak($usage . ". Supplied options is not a hash reference") unless ref $options eq 'HASH'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#Select backend |
28
|
13
|
|
66
|
|
|
147
|
my $method = $options->{Method} || croak("No cache 'Method' option"); |
29
|
12
|
|
|
|
|
44
|
TRACE("Cache: method = $method"); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#Load appropriate backend class on demand |
32
|
12
|
100
|
|
|
|
70
|
my $backend_name = (scalar $method =~ /::/? $method : "$class\::$method"); #If no namespace, assume in the Cache::AgainstFile::Backend namespace |
33
|
12
|
100
|
|
|
|
139
|
die("Package name '$backend_name' doesn't look valid") unless($backend_name =~ /^[\w:]+$/); |
34
|
11
|
|
|
|
|
978
|
eval "require $backend_name"; |
35
|
11
|
100
|
|
|
|
66
|
die("Unable to load $backend_name - $@") if($@); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#Wire up tracing stubs |
38
|
10
|
|
|
|
|
28
|
foreach my $stub (qw(TRACE DUMP)) { |
39
|
4
|
|
|
4
|
|
29
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1299
|
|
40
|
20
|
|
|
|
|
76
|
local $^W = undef; |
41
|
20
|
|
|
|
|
28
|
*{$backend_name."::".$stub} = \&{$stub}; |
|
20
|
|
|
|
|
138
|
|
|
20
|
|
|
|
|
70
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
10
|
|
|
|
|
87
|
my $backend = $backend_name->new($loader, $options); |
45
|
10
|
|
|
|
|
100
|
my $self = { |
46
|
|
|
|
|
|
|
'loader' => $loader, |
47
|
|
|
|
|
|
|
'options' => $options, |
48
|
|
|
|
|
|
|
'method' => $method, |
49
|
|
|
|
|
|
|
'backend' => $backend, |
50
|
|
|
|
|
|
|
}; |
51
|
10
|
|
|
|
|
45
|
bless $self, $class; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Forward the methods to the backend |
55
|
|
|
|
|
|
|
sub get |
56
|
|
|
|
|
|
|
{ |
57
|
73
|
|
|
73
|
1
|
62068624
|
my $self = shift; |
58
|
73
|
50
|
|
|
|
2313
|
croak("File '$_[0]' does not exist") unless(-e $_[0]); |
59
|
73
|
|
|
|
|
661
|
return $self->{backend}->get(@_); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub purge |
63
|
|
|
|
|
|
|
{ |
64
|
8
|
|
|
8
|
1
|
4009001
|
my $self = shift; |
65
|
8
|
|
|
|
|
101
|
return $self->{backend}->purge(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub clear |
69
|
|
|
|
|
|
|
{ |
70
|
15
|
|
|
15
|
1
|
728
|
my $self = shift; |
71
|
15
|
|
|
|
|
69
|
return $self->{backend}->clear(); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub count |
75
|
|
|
|
|
|
|
{ |
76
|
16
|
|
|
16
|
1
|
874223
|
my $self = shift; |
77
|
16
|
|
|
|
|
67
|
return $self->{backend}->count(); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub size |
81
|
|
|
|
|
|
|
{ |
82
|
8
|
|
|
8
|
1
|
20
|
my $self = shift; |
83
|
8
|
|
|
|
|
32
|
return $self->{backend}->size(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#Log::Trace stubs |
87
|
557
|
|
|
557
|
0
|
1059
|
sub TRACE {} |
88
|
24
|
|
|
24
|
0
|
40
|
sub DUMP {} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |