| 1 | package App::Ack::Filter::Match; | ||
| 2 | |||
| 3 | 581 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 581 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 581 | ▶ | no re 'eval'; # Enforce default and block -Mre=eval to block RCE security problem. |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 581 | ▶ | use parent 'App::Ack::Filter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 581 | ▶ | use App::Ack::Filter::MatchGroup (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | App::Ack::Filter::Match | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | Implements filtering files by their filename (regular expression). | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | 5010 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 23 | 5010 | my ( $class, $re ) = @_; | |
| 24 | |||
| 25 | 5010 | $re =~ s{^/|/$}{}g; # XXX validate? | |
| 26 | 5010 | $re = qr/$re/i; | |
| 27 | |||
| 28 | 5010 | return bless { | |
| 29 | regex => $re, | ||
| 30 | groupname => 'MatchGroup', | ||
| 31 | }, $class; | ||
| 32 | } | ||
| 33 | |||
| 34 | 394 | ▶ | sub create_group { |
|
Subroutine
create_group: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 35 | 394 | return App::Ack::Filter::MatchGroup->new; | |
| 36 | } | ||
| 37 | |||
| 38 | 92 | ▶ | sub filter { |
|
Subroutine
filter: called CC=1 SCAR=0.0
Pod
documented
| |||
| 39 | 92 | my ( $self, $file ) = @_; | |
| 40 | |||
| 41 | 92 | return $file->basename =~ /$self->{regex}/; | |
| 42 | } | ||
| 43 | |||
| 44 | 0 | ▶ | sub inspect { |
|
Subroutine
inspect: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 45 | 0 | my ( $self ) = @_; | |
| 46 | |||
| 47 | 0 | return ref($self) . ' - ' . $self->{regex}; | |
| 48 | } | ||
| 49 | |||
| 50 | 10 | ▶ | sub to_string { |
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||
| 51 | 10 | my ( $self ) = @_; | |
| 52 | |||
| 53 | 10 | return "Filename matches $self->{regex}"; | |
| 54 | } | ||
| 55 | |||
| 56 | 581 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 57 | 581 | App::Ack::Filter->register_filter(match => __PACKAGE__); | |
| 58 | } | ||
| 59 | |||
| 60 | 581 | 1; | |