line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Assets::Filter::Collect; |
2
|
|
|
|
|
|
|
|
3
|
22
|
|
|
22
|
|
666816
|
use strict; |
|
22
|
|
|
|
|
63
|
|
|
22
|
|
|
|
|
736
|
|
4
|
22
|
|
|
22
|
|
128
|
use warnings; |
|
22
|
|
|
|
|
45
|
|
|
22
|
|
|
|
|
656
|
|
5
|
|
|
|
|
|
|
|
6
|
22
|
|
|
22
|
|
146
|
use base qw/File::Assets::Filter/; |
|
22
|
|
|
|
|
70
|
|
|
22
|
|
|
|
|
13106
|
|
7
|
|
|
|
|
|
|
|
8
|
22
|
|
|
22
|
|
236
|
use Digest; |
|
22
|
|
|
|
|
47
|
|
|
22
|
|
|
|
|
404
|
|
9
|
22
|
|
|
22
|
|
130
|
use File::Assets; |
|
22
|
|
|
|
|
41
|
|
|
22
|
|
|
|
|
149
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
for my $ii (qw/fingerprint_digest fingerprint_digester/) { |
12
|
22
|
|
|
22
|
|
763
|
no strict 'refs'; |
|
22
|
|
|
|
|
40
|
|
|
22
|
|
|
|
|
24258
|
|
13
|
|
|
|
|
|
|
*$ii = sub { |
14
|
339
|
|
|
339
|
|
2111
|
my $self = shift; |
15
|
339
|
100
|
|
|
|
1176
|
return $self->stash->{$ii} unless @_; |
16
|
112
|
|
|
|
|
347
|
return $self->stash->{$ii} = shift; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub signature { |
21
|
16
|
|
|
16
|
0
|
104
|
return "collect"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %default = (qw/ |
25
|
|
|
|
|
|
|
skip_single 0 |
26
|
|
|
|
|
|
|
skip_if_exists 0 |
27
|
|
|
|
|
|
|
skip_inline 1 |
28
|
|
|
|
|
|
|
check_content 0 |
29
|
|
|
|
|
|
|
fingerprint_digest 1 |
30
|
|
|
|
|
|
|
check_age 1 |
31
|
|
|
|
|
|
|
/, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
27
|
|
|
27
|
0
|
76
|
my $class = shift; |
36
|
27
|
|
|
|
|
200
|
my $self = $class->SUPER::new(@_); |
37
|
27
|
|
|
|
|
122
|
local %_ = @_; |
38
|
27
|
|
|
|
|
159
|
while (my ($setting, $value) = each %default) { |
39
|
162
|
100
|
|
|
|
4709
|
$self->cfg->{$setting} = exists $_{$setting} ? $_{$setting} : $value; |
40
|
|
|
|
|
|
|
} |
41
|
27
|
|
|
|
|
328
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub pre { |
45
|
56
|
|
|
56
|
0
|
98
|
my $self = shift; |
46
|
56
|
|
|
|
|
372
|
$self->SUPER::pre(@_); |
47
|
|
|
|
|
|
|
|
48
|
56
|
50
|
|
|
|
239
|
return 0 if $self->skip_if_exists; |
49
|
|
|
|
|
|
|
|
50
|
56
|
50
|
|
|
|
1238
|
if ($self->cfg->{fingerprint_digest}) { |
51
|
56
|
|
|
|
|
527
|
$self->fingerprint_digester(File::Assets::Util->digest); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
56
|
|
|
|
|
226
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub process { |
58
|
115
|
|
|
115
|
0
|
174
|
my $self = shift; |
59
|
115
|
|
|
|
|
504
|
$self->SUPER::process(@_); |
60
|
115
|
50
|
|
|
|
264
|
if (my $digester = $self->fingerprint_digester) { |
61
|
115
|
|
|
|
|
181
|
my $asset = $_[0]; |
62
|
115
|
|
|
|
|
455
|
$digester->add($asset->digest."\n"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub post { |
67
|
56
|
|
|
56
|
0
|
113
|
my $self = shift; |
68
|
56
|
|
|
|
|
260
|
$self->SUPER::post(@_); |
69
|
|
|
|
|
|
|
|
70
|
56
|
|
|
|
|
178
|
my $matched = $self->matched; |
71
|
|
|
|
|
|
|
|
72
|
56
|
50
|
|
|
|
176
|
return unless @$matched; |
73
|
|
|
|
|
|
|
|
74
|
56
|
50
|
33
|
|
|
1463
|
return if $self->cfg->{skip_single} && 1 == @$matched; |
75
|
|
|
|
|
|
|
|
76
|
56
|
50
|
|
|
|
458
|
if (my $digester = $self->fingerprint_digester) { |
77
|
56
|
|
|
|
|
488
|
$self->fingerprint_digest($digester->hexdigest); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
56
|
50
|
|
|
|
241
|
return if $self->skip_if_exists; |
81
|
|
|
|
|
|
|
|
82
|
56
|
|
|
|
|
325
|
my $build = $self->should_build; |
83
|
|
|
|
|
|
|
|
84
|
56
|
100
|
|
|
|
3372
|
if ($build) { |
85
|
38
|
|
|
|
|
199
|
$self->build; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
56
|
|
|
|
|
264
|
$self->substitute; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub skip_if_exists { |
92
|
112
|
|
|
112
|
0
|
209
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
112
|
50
|
33
|
|
|
2967
|
if ($self->cfg->{skip_if_exists} && $self->asset) { |
95
|
0
|
0
|
0
|
|
|
0
|
if (-e $self->asset->file && -s _) { |
96
|
0
|
|
|
|
|
0
|
$self->replace; |
97
|
0
|
|
|
|
|
0
|
return 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
112
|
|
|
|
|
872
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub should_build { |
104
|
56
|
|
|
56
|
0
|
92
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# if ($self->cfg->{check_content}) { |
107
|
|
|
|
|
|
|
# my $digest = $self->fingerprint_digest; |
108
|
|
|
|
|
|
|
# my $dir = $self->group->rsc->dir->subdir(".check-content-digest"); |
109
|
|
|
|
|
|
|
# my $file = $dir->file($digest); |
110
|
|
|
|
|
|
|
# unless (-e $file) { |
111
|
|
|
|
|
|
|
# $file->touch; |
112
|
|
|
|
|
|
|
# return 1; |
113
|
|
|
|
|
|
|
# } |
114
|
|
|
|
|
|
|
# $file->touch; |
115
|
|
|
|
|
|
|
# } |
116
|
|
|
|
|
|
|
|
117
|
56
|
50
|
|
|
|
1298
|
if ($self->cfg->{check_age}) { |
118
|
56
|
|
|
|
|
400
|
my $mtime = $self->mtime; |
119
|
56
|
100
|
|
|
|
240
|
return 1 if $mtime > $self->output_asset->file_mtime; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# if ($self->cfg->{check_digest}) { |
123
|
|
|
|
|
|
|
# my $file = $self->check_digest_file; |
124
|
|
|
|
|
|
|
# unless (-e $file) { |
125
|
|
|
|
|
|
|
# return 1; |
126
|
|
|
|
|
|
|
# } |
127
|
|
|
|
|
|
|
# } |
128
|
|
|
|
|
|
|
|
129
|
18
|
|
|
|
|
1460
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub match { |
133
|
121
|
|
|
121
|
0
|
160
|
my $self = shift; |
134
|
121
|
|
|
|
|
173
|
my $asset = shift; |
135
|
121
|
|
|
|
|
157
|
my $match = shift; |
136
|
121
|
|
100
|
|
|
611
|
return $self->SUPER::match($asset, $match && |
137
|
|
|
|
|
|
|
(! $asset->inline || ! $self->cfg->{skip_inline}) && |
138
|
|
|
|
|
|
|
(! $asset->outside) |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#sub check_digest_file { |
143
|
|
|
|
|
|
|
# my $self = shift; |
144
|
|
|
|
|
|
|
# my $key_digest = $self->key_digest; |
145
|
|
|
|
|
|
|
# my $dir = $self->assets->rsc->dir->subdir(".check-digest"); |
146
|
|
|
|
|
|
|
# $dir->mkpath unless -d $dir; |
147
|
|
|
|
|
|
|
# my $file = $dir->file($key_digest); |
148
|
|
|
|
|
|
|
# return $file; |
149
|
|
|
|
|
|
|
#} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub build { |
152
|
38
|
|
|
38
|
0
|
73
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
38
|
|
|
|
|
185
|
my $content = $self->build_content; |
155
|
|
|
|
|
|
|
|
156
|
38
|
|
|
|
|
149
|
my $output_asset = $self->output_asset; |
157
|
|
|
|
|
|
|
|
158
|
38
|
100
|
|
|
|
220
|
$output_asset->write($content) if defined $content; |
159
|
|
|
|
|
|
|
|
160
|
38
|
|
|
|
|
10321
|
return $output_asset; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub output_asset { |
164
|
157
|
|
|
157
|
0
|
244
|
my $self = shift; |
165
|
157
|
|
66
|
|
|
459
|
return $self->stash->{output_asset} ||= do { |
166
|
56
|
|
|
|
|
253
|
$self->assets->output_asset($self); |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub substitute { |
171
|
56
|
|
|
56
|
0
|
107
|
my $self = shift; |
172
|
56
|
|
33
|
|
|
261
|
my $asset = shift || $self->output_asset; |
173
|
|
|
|
|
|
|
|
174
|
56
|
|
|
|
|
371
|
my $slice = $self->slice; |
175
|
56
|
|
|
|
|
187
|
my $matched = $self->matched; |
176
|
56
|
|
|
|
|
117
|
my $top_match = $matched->[0]; |
177
|
56
|
|
|
|
|
171
|
my $top_asset = $top_match->{asset}; |
178
|
|
|
|
|
|
|
|
179
|
56
|
|
|
|
|
148
|
for my $match (reverse @$matched) { |
180
|
115
|
|
|
|
|
246
|
my $rank = $match->{rank}; |
181
|
115
|
|
|
|
|
333
|
splice @$slice, $rank, 1, (); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
56
|
|
|
|
|
279
|
splice @$slice, $top_match->{rank}, 0, $asset; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub fingerprint { |
188
|
56
|
|
|
56
|
0
|
165
|
return $_[0]->fingerprint_digest; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub find_type { |
196
|
|
|
|
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
my $frob; |
198
|
|
|
|
|
|
|
return $frob if $frob = $self->type; |
199
|
|
|
|
|
|
|
return $frob if (($frob = $self->matched->[0]) && ($frob = $frob->{asset}->type)); |
200
|
|
|
|
|
|
|
return undef; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|