| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Assets::Filter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
22
|
|
|
22
|
|
141
|
use strict; |
|
|
22
|
|
|
|
|
49
|
|
|
|
22
|
|
|
|
|
741
|
|
|
4
|
22
|
|
|
22
|
|
117
|
use warnings; |
|
|
22
|
|
|
|
|
47
|
|
|
|
22
|
|
|
|
|
753
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
22
|
|
|
22
|
|
129
|
use Object::Tiny qw/cfg where signature/; |
|
|
22
|
|
|
|
|
52
|
|
|
|
22
|
|
|
|
|
378
|
|
|
7
|
22
|
|
|
22
|
|
5200
|
use File::Assets::Carp; |
|
|
22
|
|
|
|
|
51
|
|
|
|
22
|
|
|
|
|
239
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
22
|
|
|
22
|
|
3892
|
use Digest; |
|
|
22
|
|
|
|
|
45
|
|
|
|
22
|
|
|
|
|
648
|
|
|
10
|
22
|
|
|
22
|
|
150
|
use Scalar::Util qw/weaken/; |
|
|
22
|
|
|
|
|
52
|
|
|
|
22
|
|
|
|
|
1732
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
for my $ii (qw/matched mtime assets bucket slice/) { |
|
13
|
22
|
|
|
22
|
|
129
|
no strict 'refs'; |
|
|
22
|
|
|
|
|
45
|
|
|
|
22
|
|
|
|
|
27392
|
|
|
14
|
|
|
|
|
|
|
*$ii = sub { |
|
15
|
989
|
|
|
989
|
|
1209
|
my $self = shift; |
|
16
|
989
|
100
|
|
|
|
2798
|
return $self->stash->{$ii} unless @_; |
|
17
|
166
|
|
|
|
|
330
|
return $self->stash->{$ii} = shift; |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %default = (qw/ |
|
22
|
|
|
|
|
|
|
/, |
|
23
|
|
|
|
|
|
|
output => undef, |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new_parse { |
|
27
|
300
|
|
|
300
|
0
|
506
|
my $class = shift; |
|
28
|
300
|
50
|
|
|
|
708
|
return unless my $filter = shift; |
|
29
|
|
|
|
|
|
|
|
|
30
|
300
|
|
|
|
|
426
|
$filter =~ s/^yui-compressor\b/yuicompressor/; # A special case |
|
31
|
300
|
|
|
|
|
604
|
my $kind = lc $class; |
|
32
|
300
|
|
|
|
|
935
|
$kind =~ s/^File::Assets::Filter:://i; |
|
33
|
300
|
|
|
|
|
762
|
$kind =~ s/::/-/g; |
|
34
|
|
|
|
|
|
|
|
|
35
|
300
|
|
|
|
|
458
|
my %cfg; |
|
36
|
300
|
100
|
|
|
|
690
|
if (ref $filter eq "") { |
|
|
|
50
|
|
|
|
|
|
|
37
|
282
|
|
|
|
|
370
|
my $cfg = $filter; |
|
38
|
282
|
100
|
|
|
|
8771
|
return unless $cfg =~ s/^\s*$kind(?:\s*$|:([^:]))//i; |
|
39
|
24
|
50
|
|
|
|
197
|
$cfg = "$1$cfg" if defined $1; |
|
40
|
24
|
|
|
|
|
165
|
%cfg = $class->new_parse_cfg($cfg); |
|
41
|
24
|
100
|
|
|
|
205
|
if (ref $_[0] eq "HASH") { |
|
|
|
50
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
51
|
%cfg = (%cfg, %{ $_[0] }); |
|
|
2
|
|
|
|
|
14
|
|
|
43
|
2
|
|
|
|
|
7
|
shift; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
elsif (ref $_[0] eq "ARRAY") { |
|
46
|
0
|
|
|
|
|
0
|
%cfg = (%cfg, @{ $_[0] }); |
|
|
0
|
|
|
|
|
0
|
|
|
47
|
0
|
|
|
|
|
0
|
shift; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
elsif (ref $filter eq "ARRAY") { |
|
51
|
|
|
|
|
|
|
# TODO? Get rid of this? |
|
52
|
18
|
100
|
66
|
|
|
445
|
return unless $filter->[0] && $filter->[0] =~ m/^\s*$kind\s*$/i; |
|
53
|
3
|
|
|
|
|
10
|
my @cfg = @$filter; |
|
54
|
3
|
|
|
|
|
8
|
shift @cfg; |
|
55
|
3
|
|
|
|
|
11
|
%cfg = @cfg; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
27
|
|
|
|
|
241
|
return $class->new(%cfg, @_); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new_parse_cfg { |
|
62
|
24
|
|
|
24
|
0
|
55
|
my $class = shift; |
|
63
|
24
|
|
|
|
|
55
|
my $cfg = shift; |
|
64
|
24
|
50
|
|
|
|
94
|
$cfg = "" unless defined $cfg; |
|
65
|
24
|
|
|
|
|
49
|
my %cfg; |
|
66
|
24
|
|
|
|
|
94
|
%cfg = map { my @itm = split m/=/, $_, 2; $itm[0], $itm[1] } split m/;/, $cfg; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
67
|
24
|
|
|
|
|
84
|
$cfg{__cfg__} = $cfg; |
|
68
|
24
|
|
|
|
|
117
|
return %cfg; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
|
72
|
28
|
|
|
28
|
0
|
67
|
my $class = shift; |
|
73
|
28
|
|
|
|
|
262
|
my $self = $class->SUPER::new; |
|
74
|
28
|
|
|
|
|
307
|
local %_ = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# $self->{assets} = $_{assets}; |
|
77
|
|
|
|
|
|
|
# weaken $self->{assets}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
28
|
|
|
|
|
214
|
$self->{cfg} = {}; |
|
80
|
|
|
|
|
|
|
|
|
81
|
28
|
|
|
|
|
170
|
while (my ($setting, $value) = each %default) { |
|
82
|
28
|
50
|
|
|
|
1177
|
$self->cfg->{$setting} = exists $_{$setting} ? $_{$setting} : $value; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
28
|
|
|
|
|
364
|
return $self; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub fit { |
|
89
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
90
|
0
|
|
|
|
|
0
|
my $bucket = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
0
|
return 1 unless $self->{fit}; |
|
93
|
0
|
0
|
|
|
|
0
|
return 1 if $bucket->kind->is_better_than_or_equal($self->{fit}); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub stash { |
|
97
|
1716
|
|
100
|
1716
|
0
|
16243
|
return shift->{stash} ||= {}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub type { |
|
101
|
0
|
|
|
0
|
0
|
0
|
return shift->where->{type}; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub output { |
|
105
|
0
|
|
|
0
|
0
|
0
|
return shift->cfg->{output}; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub begin { |
|
109
|
56
|
|
|
56
|
0
|
94
|
my $self = shift; |
|
110
|
56
|
|
|
|
|
92
|
my $slice = shift; |
|
111
|
56
|
|
|
|
|
171
|
my $bucket = shift; |
|
112
|
56
|
|
|
|
|
85
|
my $assets = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
56
|
|
|
|
|
250
|
$self->stash->{slice} = $slice; |
|
115
|
56
|
|
|
|
|
174
|
$self->stash->{bucket} = $bucket; |
|
116
|
56
|
|
|
|
|
135
|
$self->stash->{assets} = $assets; |
|
117
|
56
|
|
|
|
|
128
|
$self->stash->{mtime} = 0; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub end { |
|
121
|
56
|
|
|
56
|
0
|
92
|
my $self = shift; |
|
122
|
56
|
|
|
|
|
832
|
delete $self->{stash}; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub filter { |
|
126
|
56
|
|
|
56
|
0
|
474
|
my $self = shift; |
|
127
|
56
|
|
|
|
|
97
|
my $slice = shift; |
|
128
|
56
|
|
|
|
|
109
|
my $bucket = shift; |
|
129
|
56
|
|
|
|
|
89
|
my $assets = shift; |
|
130
|
|
|
|
|
|
|
|
|
131
|
56
|
|
|
|
|
286
|
$self->begin($slice, $bucket, $assets); |
|
132
|
|
|
|
|
|
|
|
|
133
|
56
|
50
|
|
|
|
314
|
return unless $self->pre; |
|
134
|
|
|
|
|
|
|
|
|
135
|
56
|
|
|
|
|
111
|
my @matched; |
|
136
|
56
|
|
|
|
|
258
|
$self->matched(\@matched); |
|
137
|
|
|
|
|
|
|
|
|
138
|
56
|
|
|
|
|
93
|
my $count = 0; |
|
139
|
56
|
|
|
|
|
215
|
for (my $rank = 0; $rank < @$slice; $rank++) { |
|
140
|
121
|
|
|
|
|
213
|
my $asset = $slice->[$rank]; |
|
141
|
|
|
|
|
|
|
|
|
142
|
121
|
100
|
|
|
|
350
|
next unless $self->_match($asset); |
|
143
|
|
|
|
|
|
|
|
|
144
|
115
|
|
|
|
|
184
|
$count = $count + 1; |
|
145
|
115
|
|
|
|
|
797
|
push @matched, { asset => $asset, rank => $rank, count => $count }; |
|
146
|
|
|
|
|
|
|
|
|
147
|
115
|
|
|
|
|
401
|
my $asset_file_mtime = $asset->file_mtime; |
|
148
|
115
|
100
|
|
|
|
7636
|
$self->mtime($asset_file_mtime) if $asset_file_mtime >= $self->mtime; |
|
149
|
|
|
|
|
|
|
|
|
150
|
115
|
|
|
|
|
537
|
$self->process($asset, $rank, $count, scalar @$slice, $slice); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
56
|
|
|
|
|
353
|
$self->post; |
|
153
|
|
|
|
|
|
|
|
|
154
|
56
|
|
|
|
|
262
|
$self->end; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _match { |
|
158
|
121
|
|
|
121
|
|
172
|
my $self = shift; |
|
159
|
121
|
|
|
|
|
148
|
my $asset = shift; |
|
160
|
|
|
|
|
|
|
|
|
161
|
121
|
|
|
|
|
476
|
return $self->match($asset, 1); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub match { |
|
165
|
121
|
|
|
121
|
0
|
896
|
my $self = shift; |
|
166
|
121
|
|
|
|
|
182
|
my $asset = shift; |
|
167
|
121
|
|
|
|
|
190
|
my $match = shift; |
|
168
|
|
|
|
|
|
|
|
|
169
|
121
|
100
|
|
|
|
571
|
return $match ? 1 : 0; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub pre { |
|
173
|
56
|
|
|
56
|
0
|
133
|
return 1; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
115
|
|
|
115
|
0
|
223
|
sub process { |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub post { |
|
180
|
56
|
|
|
56
|
0
|
116
|
return 1; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub remove { |
|
184
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
|
185
|
1
|
|
|
|
|
7
|
carp __PACKAGE__, "::remove() is deprecated, nothing happens"; |
|
186
|
1
|
|
|
|
|
178
|
return; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub kind { |
|
190
|
342
|
|
|
342
|
0
|
4747
|
my $self = shift; |
|
191
|
342
|
|
|
|
|
759
|
return $self->bucket->kind; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__ |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my %default = (qw/ |
|
199
|
|
|
|
|
|
|
/, |
|
200
|
|
|
|
|
|
|
output => undef, |
|
201
|
|
|
|
|
|
|
); |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub new_parse { |
|
204
|
|
|
|
|
|
|
my $class = shift; |
|
205
|
|
|
|
|
|
|
return unless my $filter = shift; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my $kind = lc $class; |
|
208
|
|
|
|
|
|
|
$kind =~ s/^File::Assets::Filter:://i; |
|
209
|
|
|
|
|
|
|
$kind =~ s/::/-/g; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
my %cfg; |
|
212
|
|
|
|
|
|
|
if (ref $filter eq "") { |
|
213
|
|
|
|
|
|
|
my $cfg = $filter; |
|
214
|
|
|
|
|
|
|
return unless $cfg =~ s/^\s*$kind(?:\s*$|:([^:]))//i; |
|
215
|
|
|
|
|
|
|
$cfg = "$1$cfg" if defined $1; |
|
216
|
|
|
|
|
|
|
%cfg = $class->new_parse_cfg($cfg); |
|
217
|
|
|
|
|
|
|
if (ref $_[0] eq "HASH") { |
|
218
|
|
|
|
|
|
|
%cfg = (%cfg, %{ $_[0] }); |
|
219
|
|
|
|
|
|
|
shift; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
elsif (ref $_[0] eq "ARRAY") { |
|
222
|
|
|
|
|
|
|
%cfg = (%cfg, @{ $_[0] }); |
|
223
|
|
|
|
|
|
|
shift; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
elsif (ref $filter eq "ARRAY") { |
|
227
|
|
|
|
|
|
|
return unless $filter->[0] && $filter->[0] =~ m/^\s*$kind\s*$/i; |
|
228
|
|
|
|
|
|
|
my @cfg = @$filter; |
|
229
|
|
|
|
|
|
|
shift @cfg; |
|
230
|
|
|
|
|
|
|
%cfg = @cfg; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
return $class->new(%cfg, @_); |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub new_parse_cfg { |
|
237
|
|
|
|
|
|
|
my $class = shift; |
|
238
|
|
|
|
|
|
|
my $cfg = shift; |
|
239
|
|
|
|
|
|
|
$cfg = "" unless defined $cfg; |
|
240
|
|
|
|
|
|
|
my %cfg; |
|
241
|
|
|
|
|
|
|
%cfg = map { my @itm = split m/=/, $_, 2; $itm[0], $itm[1] } split m/;/, $cfg; |
|
242
|
|
|
|
|
|
|
$cfg{__cfg__} = $cfg; |
|
243
|
|
|
|
|
|
|
return %cfg; |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub new { |
|
247
|
|
|
|
|
|
|
my $class = shift; |
|
248
|
|
|
|
|
|
|
my $self = $class->SUPER::new; |
|
249
|
|
|
|
|
|
|
local %_ = @_; |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
$self->{assets} = $_{assets}; |
|
252
|
|
|
|
|
|
|
weaken $self->{assets}; |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $where = $_{where}; |
|
255
|
|
|
|
|
|
|
if ($_{type}) { |
|
256
|
|
|
|
|
|
|
croak "You specified a type AND a where clause" if $where; |
|
257
|
|
|
|
|
|
|
$where = { |
|
258
|
|
|
|
|
|
|
type => $_{type}, |
|
259
|
|
|
|
|
|
|
}; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
if (defined (my $type = $where->{type})) { |
|
262
|
|
|
|
|
|
|
$where->{type} = File::Assets::Util->parse_type($_{type}) or croak "Don't know the type ($type)"; |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
if (defined (my $path = $where->{path})) { |
|
265
|
|
|
|
|
|
|
if (ref $path eq "CODE") { |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
elsif (ref $path eq "Regex") { |
|
268
|
|
|
|
|
|
|
$where->{path} = sub { |
|
269
|
|
|
|
|
|
|
return defined $_ && $_ =~ $path; |
|
270
|
|
|
|
|
|
|
}; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
elsif (! ref $path) { |
|
273
|
|
|
|
|
|
|
$where->{path} = sub { |
|
274
|
|
|
|
|
|
|
return defined $_ && $_ eq $path; |
|
275
|
|
|
|
|
|
|
}; |
|
276
|
|
|
|
|
|
|
} |
|
277
|
|
|
|
|
|
|
else { |
|
278
|
|
|
|
|
|
|
croak "Don't know what to do with where path ($path)"; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
} |
|
281
|
|
|
|
|
|
|
$self->{where} = $where; |
|
282
|
|
|
|
|
|
|
$self->{cfg} = {}; |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
while (my ($setting, $value) = each %default) { |
|
285
|
|
|
|
|
|
|
$self->cfg->{$setting} = exists $_{$setting} ? $_{$setting} : $value; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
return $self; |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
|