Catmandu/Fix/move_field.pm

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