blib/lib/Catmandu/Fix/move_field.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 4 / 4 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 94.7% 54 / 57 CC 5 SCAR 7.3
CC
5
Cov
98%
__ANON__
4.0
__ANON__
2.0
__ANON__
1.0
CRAP 2.1
« blib/lib/Catmandu/Fix/trim.pm ↑ Summary blib/lib/Catmandu/Fix/Bind.pm »
1 package Catmandu::Fix::move_field;
2  
3 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '1.0201_02';
6  
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 with 'Catmandu::Fix::Base';
12  
13 2 has old_path => (fix_arg => 1);
14 2 has new_path => (fix_arg => 1);
15  
16 sub emit {
17 5 ▶ my ($self, $fixer) = @_;
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
18 5 my $old_path = $fixer->split_path($self->old_path);
19 5 my $old_key = pop @$old_path;
20 5 my $new_path = $fixer->split_path($self->new_path);
21  
22 $fixer->emit_walk_path(
23 $fixer->var,
24 $old_path,
25 sub {
26 5 ▶ my $var = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
27 $fixer->emit_delete_key(
28 $var, $old_key,
29 sub {
30 5 ▶ my $vals = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
31 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (@$new_path and $new_path->[-1] eq '$prepend' || $new_path->[-1] eq '$append') { } 2 3 5
Condition83%5/6
@$new_path and $new_path->[-1] eq "\$prepend" || $new_path->[-1] eq "\$append"
!ll&&!rl&&r
032
$new_path->[-1] eq "\$prepend" or $new_path->[-1] eq "\$append"
l!l&&r!l&&!r
113
MC/DC66%2/3
@$new_path and $new_path->[-1] eq "\$prepend" || $new_path->[-1] eq "\$append"
@$new_path $new_path->[-1] eq "\$prepend" $new_path->[-1] eq "\$append"
Truth table75%3/4
A and B or C
A= @$new_pathB= $new_path->[-1] eq "\$prepend"C= $new_path->[-1] eq "\$append"
ABCresult
0XX0
1000
11X1
1011
32 @$new_path
33 && ( $new_path->[-1] eq '$prepend'
34 || $new_path->[-1] eq '$append')
35 )
36 {
37 2 my $new_key = pop @$new_path;
38 $fixer->emit_create_path(
39 $fixer->var,
40 $new_path,
41 sub {
42 2 ▶ my $var = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
43 2 ▶ my $sym
Branch: 1 branch
BranchTrueFalseTotal
$new_key eq '$prepend' ? : 1 1 2
44 = $new_key eq '$prepend'
45 ? 'unshift'
46 : 'push';
47 2 "if (\@{${vals}} && is_array_ref(${var} //= [])) {"
48 . "${sym}(\@{${var}}, \@{${vals}});"
49 . "}";
50 }
51 2 );
52 }
53 else {
54 $fixer->emit_create_path(
55 $fixer->var,
56 $new_path,
57 sub {
58 3 ▶ my $var = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
59 3 "if (\@{${vals}}) {"
60 . "${var} = shift(\@{${vals}});" . "}";
61 }
62 3 );
63 }
64 }
65 5 );
66 }
67 5 );
68 }
69  
70 2 1;
71  
72 __END__
73  
74 =pod
75  
76 =head1 NAME
77  
78 Catmandu::Fix::move_field - move a field to another place in the data structure
79  
80 =head1 SYNOPSIS
81  
82 # Move 'foo.bar' to 'bar.foo'
83 move_field(foo.bar, bar.foo)
84  
85 =head1 SEE ALSO
86  
87 L<Catmandu::Fix>
88  
89 =cut
« blib/lib/Catmandu/Fix/trim.pm ↑ Summary blib/lib/Catmandu/Fix/Bind.pm »