File: MatchGroup.pm

package info (click to toggle)
ack 3.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,676 kB
  • sloc: perl: 10,935; ansic: 21; fortran: 11; python: 6; makefile: 5; javascript: 3
file content (47 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (3)
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
package App::Ack::Filter::MatchGroup;

=head1 NAME

App::Ack::Filter::MatchGroup

=head1 DESCRIPTION

The App::Ack::Filter::MatchGroup class optimizes multiple ::Match calls
into one container.  See App::Ack::Filter::IsGroup for details.

=cut

use strict;
use warnings;
use parent 'App::Ack::Filter';

sub new {
    my ( $class ) = @_;

    return bless {
        matches => [],
        big_re  => undef,
    }, $class;
}

sub add {
    my ( $self, $filter ) = @_;

    push @{ $self->{matches} }, $filter->{regex};

    my $re = join('|', map { "(?:$_)" } @{ $self->{matches} });
    $self->{big_re} = qr/$re/;

    return;
}

sub filter {
    my ( $self, $file ) = @_;

    return $file->basename =~ /$self->{big_re}/;
}

# This class has no inspect() or to_string() method.
# It will just use the default one unless someone writes something useful.

1;