Catmandu/Fix/copy_field.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 100% 46 / 46 CC 2 SCAR 2.0
CC
2
Cov
100%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Catmandu/Fix/add_to_exporter.pm ↑ Summary Catmandu/Fix/move_field.pm »
1 package Catmandu::Fix::copy_field;
2  
3 10 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 our $VERSION = '1.2025';
6  
7 10 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Catmandu::Util::Path qw(as_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 10 with 'Catmandu::Fix::Builder';
14  
15 10 has old_path => (fix_arg => 1);
16 10 has new_path => (fix_arg => 1);
17  
18 32 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=1 SCAR=0.0
19 32 my ($self) = @_;
20 32 my $old_path = as_path($self->old_path);
21 32 my $new_path = as_path($self->new_path);
22 32 my $getter = $old_path->getter;
23 32 my $creator = $new_path->creator;
24  
25 58 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
26 58 my $data = $_[0];
27 58 my $values = [map {clone($_)} @{$getter->($data)}];
28 58 ▶ while (@$values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$values) 61 58 119
29 61 $data = $creator->($data, shift @$values);
30 }
31 58 $data;
32 32 };
33 }
34  
35 10 1;
36  
37 __END__
« Catmandu/Fix/add_to_exporter.pm ↑ Summary Catmandu/Fix/move_field.pm »