line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::filter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
104261
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Catmandu::Util qw(is_array_ref); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
530
|
use Catmandu::Util::Regex qw(as_regex); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
81
|
|
9
|
1
|
|
|
1
|
|
434
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
10
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
420
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
12
|
1
|
|
|
1
|
|
759
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
15
|
|
|
|
|
|
|
has search => (fix_arg => 1); |
16
|
|
|
|
|
|
|
has invert => (fix_opt => 1); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_fixer { |
21
|
4
|
|
|
4
|
|
38
|
my ($self) = @_; |
22
|
4
|
|
|
|
|
20
|
my $regex = as_regex($self->search); |
23
|
|
|
|
|
|
|
my $cb = $self->invert |
24
|
|
|
|
|
|
|
? sub { |
25
|
1
|
|
|
1
|
|
2
|
[grep {!m/$regex/} @{$_[0]}]; |
|
4
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
4
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
: sub { |
28
|
3
|
|
|
3
|
|
5
|
[grep {m/$regex/} @{$_[0]}]; |
|
10
|
|
|
|
|
98
|
|
|
3
|
|
|
|
|
12
|
|
29
|
4
|
100
|
|
|
|
27
|
}; |
30
|
4
|
|
|
|
|
23
|
as_path($self->path)->updater(if_array_ref => $cb); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Fix::filter - Filter values out of an array based on a regular expression |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# words => ["Patrick","Nicolas","Paul","Frank"] |
46
|
|
|
|
|
|
|
filter(words,'Pa') |
47
|
|
|
|
|
|
|
# words => ["Patrick","Paul"] |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# filter only values that do NOT match the pattern: |
50
|
|
|
|
|
|
|
filter(words, 'Pa', invert: 1) |
51
|
|
|
|
|
|
|
# words => ["Nicolas","Frank"] |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SEE ALSO |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
L<Catmandu::Fix> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |