line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Assets::Filter::Collect; |
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
662911
|
use strict; |
|
23
|
|
|
|
|
63
|
|
|
23
|
|
|
|
|
740
|
|
4
|
23
|
|
|
23
|
|
129
|
use warnings; |
|
23
|
|
|
|
|
51
|
|
|
23
|
|
|
|
|
624
|
|
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
124
|
use base qw/File::Assets::Filter/; |
|
23
|
|
|
|
|
44
|
|
|
23
|
|
|
|
|
12912
|
|
7
|
|
|
|
|
|
|
|
8
|
23
|
|
|
23
|
|
158
|
use Digest; |
|
23
|
|
|
|
|
62
|
|
|
23
|
|
|
|
|
418
|
|
9
|
23
|
|
|
23
|
|
125
|
use File::Assets; |
|
23
|
|
|
|
|
46
|
|
|
23
|
|
|
|
|
144
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
for my $ii (qw/fingerprint_digest fingerprint_digester/) { |
12
|
23
|
|
|
23
|
|
739
|
no strict 'refs'; |
|
23
|
|
|
|
|
68
|
|
|
23
|
|
|
|
|
30315
|
|
13
|
|
|
|
|
|
|
*$ii = sub { |
14
|
339
|
|
|
339
|
|
2310
|
my $self = shift; |
15
|
339
|
100
|
|
|
|
1126
|
return $self->stash->{$ii} unless @_; |
16
|
112
|
|
|
|
|
349
|
return $self->stash->{$ii} = shift; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub signature { |
21
|
16
|
|
|
16
|
0
|
114
|
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
|
69
|
my $class = shift; |
36
|
27
|
|
|
|
|
223
|
my $self = $class->SUPER::new(@_); |
37
|
27
|
|
|
|
|
101
|
local %_ = @_; |
38
|
27
|
|
|
|
|
148
|
while (my ($setting, $value) = each %default) { |
39
|
162
|
100
|
|
|
|
4331
|
$self->cfg->{$setting} = exists $_{$setting} ? $_{$setting} : $value; |
40
|
|
|
|
|
|
|
} |
41
|
27
|
|
|
|
|
433
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub pre { |
45
|
56
|
|
|
56
|
0
|
93
|
my $self = shift; |
46
|
56
|
|
|
|
|
356
|
$self->SUPER::pre(@_); |
47
|
|
|
|
|
|
|
|
48
|
56
|
50
|
|
|
|
234
|
return 0 if $self->skip_if_exists; |
49
|
|
|
|
|
|
|
|
50
|
56
|
50
|
|
|
|
1295
|
if ($self->cfg->{fingerprint_digest}) { |
51
|
56
|
|
|
|
|
525
|
$self->fingerprint_digester(File::Assets::Util->digest); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
56
|
|
|
|
|
226
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub process { |
58
|
115
|
|
|
115
|
0
|
153
|
my $self = shift; |
59
|
115
|
|
|
|
|
479
|
$self->SUPER::process(@_); |
60
|
115
|
50
|
|
|
|
250
|
if (my $digester = $self->fingerprint_digester) { |
61
|
115
|
|
|
|
|
182
|
my $asset = $_[0]; |
62
|
115
|
|
|
|
|
429
|
$digester->add($asset->digest."\n"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub post { |
67
|
56
|
|
|
56
|
0
|
149
|
my $self = shift; |
68
|
56
|
|
|
|
|
272
|
$self->SUPER::post(@_); |
69
|
|
|
|
|
|
|
|
70
|
56
|
|
|
|
|
208
|
my $matched = $self->matched; |
71
|
|
|
|
|
|
|
|
72
|
56
|
50
|
|
|
|
168
|
return unless @$matched; |
73
|
|
|
|
|
|
|
|
74
|
56
|
50
|
33
|
|
|
1464
|
return if $self->cfg->{skip_single} && 1 == @$matched; |
75
|
|
|
|
|
|
|
|
76
|
56
|
50
|
|
|
|
462
|
if (my $digester = $self->fingerprint_digester) { |
77
|
56
|
|
|
|
|
441
|
$self->fingerprint_digest($digester->hexdigest); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
56
|
50
|
|
|
|
235
|
return if $self->skip_if_exists; |
81
|
|
|
|
|
|
|
|
82
|
56
|
|
|
|
|
221
|
my $build = $self->should_build; |
83
|
|
|
|
|
|
|
|
84
|
56
|
100
|
|
|
|
3466
|
if ($build) { |
85
|
38
|
|
|
|
|
235
|
$self->build; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
56
|
|
|
|
|
286
|
$self->substitute; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub skip_if_exists { |
92
|
112
|
|
|
112
|
0
|
183
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
112
|
50
|
33
|
|
|
2654
|
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
|
|
|
|
|
972
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub should_build { |
104
|
56
|
|
|
56
|
0
|
98
|
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
|
|
|
|
1360
|
if ($self->cfg->{check_age}) { |
118
|
56
|
|
|
|
|
508
|
my $mtime = $self->mtime; |
119
|
56
|
100
|
|
|
|
239
|
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
|
|
|
|
|
1307
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub match { |
133
|
121
|
|
|
121
|
0
|
163
|
my $self = shift; |
134
|
121
|
|
|
|
|
162
|
my $asset = shift; |
135
|
121
|
|
|
|
|
153
|
my $match = shift; |
136
|
121
|
|
100
|
|
|
1724
|
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
|
68
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
38
|
|
|
|
|
191
|
my $content = $self->build_content; |
155
|
|
|
|
|
|
|
|
156
|
38
|
|
|
|
|
139
|
my $output_asset = $self->output_asset; |
157
|
|
|
|
|
|
|
|
158
|
38
|
100
|
|
|
|
233
|
$output_asset->write($content) if defined $content; |
159
|
|
|
|
|
|
|
|
160
|
38
|
|
|
|
|
10151
|
return $output_asset; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub output_asset { |
164
|
157
|
|
|
157
|
0
|
223
|
my $self = shift; |
165
|
157
|
|
66
|
|
|
429
|
return $self->stash->{output_asset} ||= do { |
166
|
56
|
|
|
|
|
250
|
$self->assets->output_asset($self); |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub substitute { |
171
|
56
|
|
|
56
|
0
|
130
|
my $self = shift; |
172
|
56
|
|
33
|
|
|
256
|
my $asset = shift || $self->output_asset; |
173
|
|
|
|
|
|
|
|
174
|
56
|
|
|
|
|
274
|
my $slice = $self->slice; |
175
|
56
|
|
|
|
|
194
|
my $matched = $self->matched; |
176
|
56
|
|
|
|
|
130
|
my $top_match = $matched->[0]; |
177
|
56
|
|
|
|
|
115
|
my $top_asset = $top_match->{asset}; |
178
|
|
|
|
|
|
|
|
179
|
56
|
|
|
|
|
140
|
for my $match (reverse @$matched) { |
180
|
115
|
|
|
|
|
186
|
my $rank = $match->{rank}; |
181
|
115
|
|
|
|
|
413
|
splice @$slice, $rank, 1, (); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
56
|
|
|
|
|
255
|
splice @$slice, $top_match->{rank}, 0, $asset; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub fingerprint { |
188
|
56
|
|
|
56
|
0
|
162
|
return $_[0]->fingerprint_digest; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |