-
Notifications
You must be signed in to change notification settings - Fork 140
/
IsGroup.pm
71 lines (45 loc) · 1.13 KB
/
IsGroup.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package App::Ack::Filter::IsGroup;
=head1 NAME
App::Ack::Filter::IsGroup
=head1 DESCRIPTION
The App::Ack::Filter::IsGroup class optimizes multiple
App::Ack::Filter::Is calls into one container.
Let's say you have 100 C<--type-add=is:...> filters.
You could have
my @filters = map { make_is_filter($_) } 1..100;
and then do
if ( any { $_->filter($rsrc) } @filters ) { ... }
but that's slow, because of of method lookup overhead, function call
overhead, etc. So ::Is filters know how to organize themselves into an
::IsGroup filter.
=cut
use strict;
use warnings;
use base 'App::Ack::Filter';
use File::Spec 3.00 ();
sub new {
my ( $class ) = @_;
return bless {
data => {},
}, $class;
}
sub add {
my ( $self, $filter ) = @_;
$self->{data}->{ $filter->{filename} } = 1;
return;
}
sub filter {
my ( $self, $resource ) = @_;
my $data = $self->{'data'};
my $base = $resource->basename;
return exists $data->{$base};
}
sub inspect {
my ( $self ) = @_;
return ref($self) . " - $self";
}
sub to_string {
my ( $self ) = @_;
return join(' ', keys %{$self->{data}});
}
1;