Catmandu/Fix/index.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 100% 56 / 56 CC 2 SCAR 1.3
CC
2
Cov
100%
_build_fixer
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Catmandu/Fix/code.pm ↑ Summary Catmandu/Fix/split_field.pm »
1 package Catmandu::Fix::index;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.2025';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catmandu::Util::Path qw(as_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use List::SomeUtils qw(indexes first_index);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has path => (fix_arg => 1);
14 1 has search => (fix_arg => 1);
15 1 has multiple => (fix_opt => 1);
16  
17 1 with 'Catmandu::Fix::Builder';
18  
19 5 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=2 SCAR=6.9
20 5 my ($self) = @_;
21  
22 5 my $search = $self->search;
23 5 my %args;
24 5 ▶ if ($self->multiple) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multiple) { } 2 3 5
25 %args = (
26 1 ▶ if_string => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 1 ▶ [indexes {$_ eq $search} unpack('(A)*', $_[0])];
Subroutine __ANON__: called CC=1 SCAR=0.0
28 },
29 1 ▶ if_array_ref => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 1 ▶ [indexes {$_ eq $search} @{$_[0]}];
Subroutine __ANON__: called CC=1 SCAR=0.0
31 },
32 2 );
33 }
34 else {
35 %args = (
36 3 ▶ if_string => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 3 index($_[0], $search);
38 },
39 1 ▶ if_array_ref => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 1 ▶ first_index {$_ eq $search} @{$_[0]};
Subroutine __ANON__: called CC=1 SCAR=0.0
41 },
42 3 );
43 }
44 5 as_path($self->path)->updater(%args);
45 }
46  
47 1 1;
48  
49 __END__
« Catmandu/Fix/code.pm ↑ Summary Catmandu/Fix/split_field.pm »