line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Assets::Asset::Content; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
160
|
use warnings; |
|
24
|
|
|
|
|
44
|
|
|
24
|
|
|
|
|
779
|
|
4
|
24
|
|
|
24
|
|
123
|
use strict; |
|
24
|
|
|
|
|
46
|
|
|
24
|
|
|
|
|
789
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
518
|
use Object::Tiny qw/file/; |
|
24
|
|
|
|
|
55
|
|
|
24
|
|
|
|
|
177
|
|
7
|
24
|
|
|
24
|
|
3494
|
use File::Assets::Carp; |
|
24
|
|
|
|
|
45
|
|
|
24
|
|
|
|
|
145
|
|
8
|
24
|
|
|
24
|
|
3461
|
use File::Assets::Util; |
|
24
|
|
|
|
|
43
|
|
|
24
|
|
|
|
|
10456
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
108
|
|
|
108
|
0
|
3060
|
my $self = bless {}, shift; |
12
|
108
|
50
|
|
|
|
440
|
$self->{file} = shift or croak "Can't have content without a file"; |
13
|
108
|
|
|
|
|
888
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub content { |
17
|
164
|
|
|
164
|
0
|
227
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
164
|
|
|
|
|
4070
|
my $file = $self->file; |
20
|
164
|
50
|
|
|
|
958
|
croak "Trying to get content from non-existent file ($file)" unless -e $file; |
21
|
164
|
100
|
100
|
|
|
8873
|
if (! $self->{content} || $self->stale) { |
22
|
54
|
|
|
|
|
223
|
local $/ = undef; |
23
|
54
|
|
|
|
|
253
|
$self->{content} = \$file->slurp; |
24
|
54
|
|
|
|
|
19177
|
$self->{content_mtime} = $file->stat->mtime; |
25
|
54
|
|
|
|
|
11450
|
$self->{content_size} = length ${ $self->{content} }; |
|
54
|
|
|
|
|
1472
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
164
|
|
|
|
|
2067
|
return $self->{content}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub digest { |
32
|
117
|
|
|
117
|
0
|
185
|
my $self = shift; |
33
|
117
|
|
66
|
|
|
1206
|
return $self->{digest} ||= do { |
34
|
53
|
|
|
|
|
329
|
File::Assets::Util->digest->add(${ $self->content })->hexdigest; |
|
53
|
|
|
|
|
1317
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub file_mtime { |
39
|
347
|
|
|
347
|
0
|
441
|
my $self = shift; |
40
|
347
|
|
100
|
|
|
8775
|
return (stat($self->file))[9] || 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub file_size { |
44
|
180
|
|
|
180
|
0
|
250
|
my $self = shift; |
45
|
180
|
|
50
|
|
|
4239
|
return (stat($self->file))[7] || 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub content_mtime { |
49
|
181
|
|
|
181
|
0
|
11009
|
my $self = shift; |
50
|
181
|
100
|
|
|
|
575
|
$self->content unless $self->{content}; |
51
|
181
|
|
|
|
|
805
|
return $self->{content_mtime}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub content_size { |
55
|
180
|
|
|
180
|
0
|
10068
|
my $self = shift; |
56
|
180
|
50
|
|
|
|
448
|
$self->content unless $self->{content}; |
57
|
180
|
|
|
|
|
1164
|
return $self->{content_size}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub refresh { |
61
|
70
|
|
|
70
|
0
|
107
|
my $self = shift; |
62
|
70
|
100
|
|
|
|
177
|
if ($self->stale) { |
63
|
1
|
|
|
|
|
5
|
delete $self->{digest}; |
64
|
1
|
|
|
|
|
4
|
delete $self->{content}; |
65
|
1
|
|
|
|
|
4
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
69
|
|
|
|
|
396
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub stale { |
71
|
181
|
|
|
181
|
0
|
267
|
my $self = shift; |
72
|
|
|
|
|
|
|
return |
73
|
181
|
|
100
|
|
|
1023
|
($self->file_mtime > $self->content_mtime) || |
74
|
|
|
|
|
|
|
($self->file_size != $self->content_size); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |