Catmandu/Fix/paste.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 100% 62 / 62 CC 6 SCAR 8.7
CC
6
Cov
100%
_build_fixer
4.0
__ANON__
3.0
BEGIN
1.0
CRAP 2.4
« Catmandu/Store/Hash.pm ↑ Summary Catmandu/Cmd/drop.pm »
1 package Catmandu::Fix::paste;
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 qw(is_value is_code_ref);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Util::Path qw(as_path);
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 with 'Catmandu::Fix::Builder';
14  
15 1 has path => (fix_arg => 1);
16 1 has args => (fix_arg => 'collect');
17  
18 3 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=4 SCAR=13.9
19 3 my ($self) = @_;
20 3 my $args = $self->args;
21 3 my $join_char = ' ';
22 3 my $getters = [];
23 3 my $creator = as_path($self->path)->creator;
24  
25 3 ▶ for (my $i = 0; $i < @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 10 2 12
26 10 my $arg = $args->[$i];
27 10 ▶ if ($arg eq 'join_char') {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg eq 'join_char') { } 1 9 10
elsif (my($literal) = $arg =~ /^~(.*)/) { } 1 8 9
28 1 $join_char = $args->[$i + 1];
29 1 last;
30 }
31 elsif (my ($literal) = $arg =~ /^~(.*)/) {
32 1 push @$getters, $literal;
33 }
34 else {
35 8 push @$getters, as_path($arg)->getter;
36 }
37 }
38  
39 3 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
40 3 my $data = $_[0];
41 3 my $vals = [];
42 3 for my $getter (@$getters) {
43 9 ▶ if (is_code_ref($getter)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_code_ref($getter)) { } 8 1 9
44 8 push @$vals, grep {is_value($_)} @{$getter->($data)};
45 }
46 else {
47 1 push @$vals, $getter;
48 }
49 }
50 3 $creator->($data, join($join_char, @$vals));
51 3 $data;
52 3 };
53 }
54  
55 1 1;
56  
57 __END__
« Catmandu/Store/Hash.pm ↑ Summary Catmandu/Cmd/drop.pm »