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