line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Ack::Filter::Collection; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::Ack::Filter::Collection |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
The Ack::Filter::Collection class can contain filters and internally sort |
10
|
|
|
|
|
|
|
them into groups. The groups can then be optimized for faster filtering. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Filters are grouped and replaced by a fast hash lookup. This leads to |
13
|
|
|
|
|
|
|
improved performance when many such filters are active, like when using |
14
|
|
|
|
|
|
|
the C<--known> command line option. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
19
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
20
|
2
|
|
|
2
|
|
10
|
use parent 'App::Ack::Filter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
0
|
|
my ( $class ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return bless { |
26
|
|
|
|
|
|
|
groups => {}, |
27
|
|
|
|
|
|
|
ungrouped => [], |
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub filter { |
32
|
0
|
|
|
0
|
1
|
|
my ( $self, $file ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
for my $group (values %{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
return 1 if $group->filter($file); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
for my $filter (@{$self->{ungrouped}}) { |
|
0
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
return 1 if $filter->filter($file); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return 0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub add { |
46
|
0
|
|
|
0
|
0
|
|
my ( $self, $filter ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if (exists $filter->{'groupname'}) { |
49
|
0
|
|
0
|
|
|
|
my $group = ($self->{groups}->{$filter->{groupname}} ||= $filter->create_group()); |
50
|
0
|
|
|
|
|
|
$group->add($filter); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
|
push @{$self->{'ungrouped'}}, $filter; |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub inspect { |
60
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return ref($self) . " - $self"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub to_string { |
66
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return join(', ', map { "($_)" } @{$self->{ungrouped}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |