Catmandu/Fix/Bind/each.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 92.3% 85 / 92 CC 11 SCAR 16.3
CC
11
Cov
95%
bind
9.0
unit
3.0
BEGIN
1.0
CRAP 5.1
« Catmandu/Fix/Bind.pm ↑ Summary Catmandu/Fix/Bind/iterate.pm »
1 package Catmandu::Fix::Bind::each;
2  
3 1 our $VERSION = '1.2025';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Catmandu::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group';
16  
17 1 has path => (fix_opt => 1);
18 1 has var => (fix_opt => 1);
19  
20 1 has _root_ => (is => 'rw');
21  
22 13 ▶sub unit {
Subroutine unit: called CC=3 SCAR=11.0
Pod undocumented
23 13 my ($self, $data) = @_;
24  
25 13 $self->_root_($data);
26  
27 13 ▶ if ($self->path && $self->path ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->path and $self->path ne '.') { } 2 11 13
Condition66%2/3
$self->path and $self->path ne "."
!ll&&!rl&&r
0112
MC/DC50%1/2
$self->path and $self->path ne "."
$self->path $self->path ne "."
Truth table66%2/3
A and B
A= $self->pathB= $self->path ne "."
ABresult
0X0
100
111
28 2 return Catmandu::Util::data_at($self->path, $data);
29 }
30 else {
31 11 return $data;
32 }
33 }
34  
35 13 ▶sub bind {
Subroutine bind: called CC=9 SCAR=22.0
Pod undocumented
36 13 my ($self, $data, $code) = @_;
37  
38 13 ▶ if (!Catmandu::Util::is_hash_ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not Catmandu::Util::is_hash_ref($data)) { } 0 13 13
39 0 $code->($data);
40 }
41 else {
42 13 my @keys = sort keys %{$data};
43 13 for my $key (@keys) {
44 19 my $value = $data->{$key};
45 19 my $scope;
46  
47 19 ▶ if ($self->var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->var) { } 17 2 19
48 17 $scope = $self->_root_;
49  
50 17 $scope->{$self->var} = {'key' => $key, 'value' => $value};
51 }
52 else {
53 2 $scope = $data;
54 2 $scope->{'key'} = $key;
55 2 $scope->{'value'} = $value;
56 }
57  
58 19 $code->($scope);
59  
60 18 ▶ if ($self->var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->var) { } 16 2 18
61  
62 # Key and values can be updated
63 16 ▶ if (my $mkey = $scope->{$self->var}->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mkey = $$scope{$self->var}{"key"}) 13 3 16
64 13 $data->{$mkey} = $scope->{$self->var}->{value};
65 13 ▶ if ($mkey ne $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mkey ne $key) 1 12 13
66 1 delete $data->{$key};
67 }
68 }
69  
70 16 delete $scope->{$self->var};
71 }
72 else {
73 2 ▶ if (my $mkey = $scope->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mkey = $scope->{"key"}) 2 0 2
74 2 $data->{$mkey} = $scope->{value};
75 2 ▶ if ($mkey ne $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mkey ne $key) 1 1 2
76 1 delete $data->{$key};
77 }
78 }
79  
80 2 delete $scope->{'key'};
81 2 delete $scope->{'value'};
82 }
83 }
84 }
85  
86 12 return $data;
87 }
88  
89 1 1;
90 __END__
« Catmandu/Fix/Bind.pm ↑ Summary Catmandu/Fix/Bind/iterate.pm »