line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::index; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
104748
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
784
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
9
|
1
|
|
|
1
|
|
600
|
use List::MoreUtils qw(indexes first_index); |
|
1
|
|
|
|
|
9485
|
|
|
1
|
|
|
|
|
9
|
|
10
|
1
|
|
|
1
|
|
1221
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
822
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has search => (fix_arg => 1); |
15
|
|
|
|
|
|
|
has multiple => (fix_opt => 1); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_fixer { |
20
|
5
|
|
|
5
|
|
51
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
15
|
my $search = $self->search; |
23
|
5
|
|
|
|
|
9
|
my %args; |
24
|
5
|
100
|
|
|
|
49
|
if ($self->multiple) { |
25
|
|
|
|
|
|
|
%args = ( |
26
|
|
|
|
|
|
|
if_string => sub { |
27
|
1
|
|
|
1
|
|
23
|
[indexes {$_ eq $search} unpack('(A)*', $_[0])]; |
|
7
|
|
|
|
|
33
|
|
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
if_array_ref => sub { |
30
|
1
|
|
|
1
|
|
3
|
[indexes {$_ eq $search} @{$_[0]}]; |
|
4
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
5
|
|
31
|
|
|
|
|
|
|
}, |
32
|
2
|
|
|
|
|
16
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
|
|
|
|
|
|
%args = ( |
36
|
|
|
|
|
|
|
if_string => sub { |
37
|
3
|
|
|
3
|
|
60
|
index($_[0], $search); |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
if_array_ref => sub { |
40
|
1
|
|
|
1
|
|
3
|
first_index {$_ eq $search} @{$_[0]}; |
|
2
|
|
|
|
|
30
|
|
|
1
|
|
|
|
|
23
|
|
41
|
|
|
|
|
|
|
}, |
42
|
3
|
|
|
|
|
24
|
); |
43
|
|
|
|
|
|
|
} |
44
|
5
|
|
|
|
|
22
|
as_path($self->path)->updater(%args); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Catmandu::Fix::index - Find all positions of a (sub)string in a field |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# On strings, search the occurence of a character in a string |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# word => "abcde" |
62
|
|
|
|
|
|
|
index(word,'c') # word => 2 |
63
|
|
|
|
|
|
|
index(word,'x') # word => -1 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# word => "abccde" |
66
|
|
|
|
|
|
|
index(word,'c', multiple:1) # word => [2,3] |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# word => [a,b,bba] , loop over all word(s) with the '*' |
69
|
|
|
|
|
|
|
index(word.*,'a') # word -> [0,-1,2] |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# On arrays, search the occurence of a word in an array |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# words => ["foo","bar","foo"] |
74
|
|
|
|
|
|
|
index(words,'bar') # words => 1 |
75
|
|
|
|
|
|
|
index(words,'foo', multiple: 1) # words => [0,2] |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L<Catmandu::Fix> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |