line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Assets::Cache; |
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
130
|
use strict; |
|
23
|
|
|
|
|
50
|
|
|
23
|
|
|
|
|
815
|
|
4
|
23
|
|
|
23
|
|
130
|
use warnings; |
|
23
|
|
|
|
|
48
|
|
|
23
|
|
|
|
|
917
|
|
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
133
|
use Object::Tiny qw/_content_registry/; |
|
23
|
|
|
|
|
47
|
|
|
23
|
|
|
|
|
130
|
|
7
|
23
|
|
|
23
|
|
3566
|
use File::Assets::Carp; |
|
23
|
|
|
|
|
50
|
|
|
23
|
|
|
|
|
212
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
3857
|
use File::Assets; |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
209
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %cache; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
36
|
|
|
36
|
0
|
91
|
my $class = shift; |
15
|
36
|
|
|
|
|
165
|
local %_ = @_; |
16
|
|
|
|
|
|
|
|
17
|
36
|
|
|
|
|
114
|
my $name = $_{name}; |
18
|
36
|
50
|
|
|
|
140
|
if (defined $name) { |
19
|
36
|
50
|
|
|
|
238
|
if (ref $name eq "SCALAR") { |
|
|
50
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
$name = $$name; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
elsif ($name eq 1) { |
23
|
36
|
|
|
|
|
90
|
$name = "__File::Assets::Cache_cache__"; |
24
|
|
|
|
|
|
|
} |
25
|
36
|
100
|
|
|
|
196
|
return $cache{$name} if $cache{$name} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
21
|
|
|
|
|
88
|
my $self = bless {}, $class; |
29
|
|
|
|
|
|
|
|
30
|
21
|
|
|
|
|
178
|
$self->{_content_registry} = {}; |
31
|
|
|
|
|
|
|
|
32
|
21
|
50
|
|
|
|
115
|
$cache{$name} = $self if $name; |
33
|
|
|
|
|
|
|
|
34
|
21
|
|
|
|
|
109
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub assets { |
38
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
39
|
0
|
|
|
|
|
0
|
return File::Assets->new(cache => $self, @_); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub clear { |
43
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
44
|
0
|
|
|
|
|
0
|
$self->{_content_registry} = {}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub content { |
48
|
70
|
|
|
70
|
0
|
5178
|
my $self = shift; |
49
|
70
|
|
|
|
|
102
|
my $file = shift; |
50
|
70
|
50
|
|
|
|
182
|
croak "Wasn't given a file" unless $file; |
51
|
70
|
|
66
|
|
|
2078
|
my $content = $self->_content_registry->{$file} ||= File::Assets::Asset::Content->new($file); |
52
|
70
|
|
|
|
|
1061
|
$content->refresh; |
53
|
70
|
|
|
|
|
430
|
return $content; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub exists { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $base = shift; |
63
|
|
|
|
|
|
|
my $key = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return exists $self->_asset_registry($base)->{$key} ? 1 : 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub store { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my $base = shift; |
71
|
|
|
|
|
|
|
my $asset = shift; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self->_asset_registry($base)->{$asset->key} = $asset; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub fetch { |
77
|
|
|
|
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
my $base = shift; |
79
|
|
|
|
|
|
|
my $key = shift; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if (my $asset = $self->_asset_registry($base)->{$key}) { |
82
|
|
|
|
|
|
|
$asset->refresh; |
83
|
|
|
|
|
|
|
return $asset; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return undef; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _asset_registry { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
return $self->{_asset_registry} unless @_; |
92
|
|
|
|
|
|
|
my $base = shift; |
93
|
|
|
|
|
|
|
return $self->{_asset_registry}->{$base} ||= {}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|