line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
87187
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
1
|
|
|
1
|
|
6
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
694
|
use List::MoreUtils qw(indexes first_index); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
9
|
1
|
|
|
1
|
|
456
|
use namespace::clean; |
|
1
|
|
|
|
|
7809
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
985
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
644
|
|
|
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
|
|
38
|
my $search = $self->search; |
21
|
|
|
|
|
|
|
my %args; |
22
|
5
|
|
|
|
|
14
|
if ($self->multiple) { |
23
|
5
|
|
|
|
|
6
|
%args = ( |
24
|
5
|
100
|
|
|
|
44
|
if_string => sub { |
25
|
|
|
|
|
|
|
[indexes {$_ eq $search} unpack('(A)*', $_[0])]; |
26
|
|
|
|
|
|
|
}, |
27
|
1
|
|
|
1
|
|
16
|
if_array_ref => sub { |
|
7
|
|
|
|
|
26
|
|
28
|
|
|
|
|
|
|
[indexes {$_ eq $search} @{$_[0]}]; |
29
|
|
|
|
|
|
|
}, |
30
|
1
|
|
|
1
|
|
3
|
); |
|
4
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
4
|
|
31
|
|
|
|
|
|
|
} |
32
|
2
|
|
|
|
|
11
|
else { |
33
|
|
|
|
|
|
|
%args = ( |
34
|
|
|
|
|
|
|
if_string => sub { |
35
|
|
|
|
|
|
|
index($_[0], $search); |
36
|
|
|
|
|
|
|
}, |
37
|
3
|
|
|
3
|
|
50
|
if_array_ref => sub { |
38
|
|
|
|
|
|
|
first_index {$_ eq $search} @{$_[0]}; |
39
|
|
|
|
|
|
|
}, |
40
|
1
|
|
|
1
|
|
3
|
); |
|
2
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
4
|
|
41
|
|
|
|
|
|
|
} |
42
|
3
|
|
|
|
|
21
|
as_path($self->path)->updater(%args); |
43
|
|
|
|
|
|
|
} |
44
|
5
|
|
|
|
|
17
|
|
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 |