line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Assets::Asset::Content; |
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
165
|
use warnings; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
783
|
|
4
|
23
|
|
|
23
|
|
117
|
use strict; |
|
23
|
|
|
|
|
44
|
|
|
23
|
|
|
|
|
730
|
|
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
133
|
use Object::Tiny qw/file/; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
200
|
|
7
|
23
|
|
|
23
|
|
3914
|
use File::Assets::Carp; |
|
23
|
|
|
|
|
52
|
|
|
23
|
|
|
|
|
146
|
|
8
|
23
|
|
|
23
|
|
3284
|
use File::Assets::Util; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
10515
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
108
|
|
|
108
|
0
|
3132
|
my $self = bless {}, shift; |
12
|
108
|
50
|
|
|
|
475
|
$self->{file} = shift or croak "Can't have content without a file"; |
13
|
108
|
|
|
|
|
959
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub content { |
17
|
164
|
|
|
164
|
0
|
246
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
164
|
|
|
|
|
4194
|
my $file = $self->file; |
20
|
164
|
50
|
|
|
|
1004
|
croak "Trying to get content from non-existent file ($file)" unless -e $file; |
21
|
164
|
100
|
100
|
|
|
9643
|
if (! $self->{content} || $self->stale) { |
22
|
54
|
|
|
|
|
239
|
local $/ = undef; |
23
|
54
|
|
|
|
|
238
|
$self->{content} = \$file->slurp; |
24
|
54
|
|
|
|
|
13586
|
$self->{content_mtime} = $file->stat->mtime; |
25
|
54
|
|
|
|
|
12245
|
$self->{content_size} = length ${ $self->{content} }; |
|
54
|
|
|
|
|
346
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
164
|
|
|
|
|
2021
|
return $self->{content}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub digest { |
32
|
117
|
|
|
117
|
0
|
165
|
my $self = shift; |
33
|
117
|
|
66
|
|
|
1191
|
return $self->{digest} ||= do { |
34
|
53
|
|
|
|
|
354
|
File::Assets::Util->digest->add(${ $self->content })->hexdigest; |
|
53
|
|
|
|
|
1543
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub file_mtime { |
39
|
347
|
|
|
347
|
0
|
449
|
my $self = shift; |
40
|
347
|
|
100
|
|
|
8474
|
return (stat($self->file))[9] || 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub file_size { |
44
|
180
|
|
|
180
|
0
|
282
|
my $self = shift; |
45
|
180
|
|
50
|
|
|
4504
|
return (stat($self->file))[7] || 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub content_mtime { |
49
|
181
|
|
|
181
|
0
|
11491
|
my $self = shift; |
50
|
181
|
100
|
|
|
|
557
|
$self->content unless $self->{content}; |
51
|
181
|
|
|
|
|
849
|
return $self->{content_mtime}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub content_size { |
55
|
180
|
|
|
180
|
0
|
10390
|
my $self = shift; |
56
|
180
|
50
|
|
|
|
441
|
$self->content unless $self->{content}; |
57
|
180
|
|
|
|
|
1123
|
return $self->{content_size}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub refresh { |
61
|
70
|
|
|
70
|
0
|
121
|
my $self = shift; |
62
|
70
|
100
|
|
|
|
173
|
if ($self->stale) { |
63
|
1
|
|
|
|
|
3
|
delete $self->{digest}; |
64
|
1
|
|
|
|
|
3
|
delete $self->{content}; |
65
|
1
|
|
|
|
|
3
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
69
|
|
|
|
|
428
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub stale { |
71
|
181
|
|
|
181
|
0
|
265
|
my $self = shift; |
72
|
|
|
|
|
|
|
return |
73
|
181
|
|
100
|
|
|
369
|
($self->file_mtime > $self->content_mtime) || |
74
|
|
|
|
|
|
|
($self->file_size != $self->content_size); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |