blib/lib/App/Ack/Filter.pm

filter: Statementstmt 89.2% 25 / 28 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 6 / 6 totaltotal 89.1% 41 / 46 CC 2 SCAR 3.1
CC
2
Cov
90%
create_filter
2.0
to_string
2.0
inspect
2.0
CRAP 1.4
« blib/lib/App/Ack/Files.pm ↑ Summary blib/lib/App/Ack/Filter/IsPath.pm »
1 package App::Ack::Filter;
2  
3 588 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 588 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 588 ▶use App::Ack ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 588 ▶use App::Ack::Filter::Inverse ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 588 my %filter_types;
10  
11 =head1 NAME
12  
13 App::Ack::Filter - Filter objects to filter files
14  
15 =head1 DESCRIPTION
16  
17 An abstract superclass that represents objects that can filter
18 C<App::Ack::File> objects. App::Ack::Filter implementations are
19 responsible for filtering filenames to be searched.
20  
21 =head1 SYNOPSIS
22  
23 # filter implementation
24 package MyFilter;
25  
26 use strict;
27 use warnings;
28 use parent 'App::Ack::Filter';
29  
30 sub filter {
31 my ( $self, $file ) = @_;
32 }
33  
34 BEGIN {
35 App::Ack::Filter->register_filter('mine' => __PACKAGE__);
36 }
37  
38 1;
39  
40 # users
41 App::Ack::Filter->create_filter('mine', @args);
42  
43  
44 =head1 METHODS
45  
46 =head2 App::Ack::Filter->create_filter($type, @args)
47  
48 Creates a filter implementation, registered as C<$type>. C<@args>
49 are provided as additional arguments to the implementation's constructor.
50  
51 =cut
52  
53 75443 ▶sub create_filter {
Subroutine create_filter: called CC=2 SCAR=6.9
Pod documented
54 75443 my ( undef, $type, @args ) = @_;
55  
56 75443 ▶ if ( my $package = $filter_types{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $package = $filter_types{$type}) 75440 3 75443
57 75440 return $package->new(@args);
58 }
59 3 my $allowed_types = join( ', ', sort keys %filter_types );
60 3 App::Ack::die( "Unknown filter type '$type'. Type must be one of: $allowed_types." );
61 }
62  
63 =head2 App::Ack::Filter->register_filter($type, $package)
64  
65 Registers a filter implementation package C<$package> under
66 the name C<$type>.
67  
68 =cut
69  
70 2326 ▶sub register_filter {
Subroutine register_filter: called CC=1 SCAR=0.0
Pod documented
71 2326 my ( undef, $type, $package ) = @_;
72  
73 2326 $filter_types{$type} = $package;
74  
75 2326 return;
76 }
77  
78 =head2 $filter->filter( $file )
79  
80 Must be implemented by filter implementations. Returns
81 true if the filter passes, false otherwise. This method
82 must B<not> alter the passed-in C<$file> object.
83  
84 =head2 $filter->invert()
85  
86 Returns a filter whose L</filter> method returns the opposite of this filter.
87  
88 =cut
89  
90 25 ▶sub invert {
Subroutine invert: called CC=1 SCAR=0.0
Pod documented
91 25 my ( $self ) = @_;
92  
93 25 return App::Ack::Filter::Inverse->new( $self );
94 }
95  
96 =head2 $filter->is_inverted()
97  
98 Returns true if this filter is an inverted filter; false otherwise.
99  
100 =cut
101  
102 11929 ▶sub is_inverted {
Subroutine is_inverted: called CC=1 SCAR=0.0
Pod documented
103 11929 return 0;
104 }
105  
106 =head2 $filter->to_string
107  
108 Converts the filter to a string. This method is also
109 called implicitly by stringification.
110  
111 =cut
112  
113 0 ▶sub to_string {
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
114 0 return '(unimplemented to_string)';
115 }
116  
117 =head2 $filter->inspect
118  
119 Prints a human-readable debugging string for this filter. Useful for,
120 you guessed it, debugging.
121  
122 =cut
123  
124 0 ▶sub inspect {
Subroutine inspect: not called CC=1 SCAR=6.9
Pod documented
125 0 my ( $self ) = @_;
126  
127 0 return ref($self);
128 }
129  
130 588 1;
« blib/lib/App/Ack/Files.pm ↑ Summary blib/lib/App/Ack/Filter/IsPath.pm »