Rx/FailureSet.pm

filter: Statementstmt 34.3% 23 / 67 Branchbran 8.3% 3 / 36 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 5 totaltotal 21.7% 32 / 147 CC 28 SCAR 60.2
CC
28
Cov
21%
build_struct
600.0
stringify
6.0
new
3.0
CRAP 412.3
↑ Summary Rx/CoreType/rec.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Data::Rx::FailureSet;
4 # ABSTRACT: multiple structured failure reports from an Rx checker
5 1 $Data::Rx::FailureSet::VERSION = '0.200007';
6 #pod =head1 SYNOPSIS
7 #pod
8 #pod This is what is thrown when a schema's C<assert_valid> method finds a problem
9 #pod with the input. For more information on it, look at the documentation for
10 #pod L<Data::Rx>.
11 #pod
12 #pod =cut
13  
14 1 ▶use overload '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub new {
17 1632 ▶ my ($class, $arg) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
18  
19 1632 my $failures;
20  
21 my $guts = {
22 failures => [ map $_->isa('Data::Rx::FailureSet')
23 195 ? @{ $_->{failures} }
24 : $_,
25 1632 ▶ @{ $arg->{failures} || [] },
Branch: 2 branches
BranchTrueFalseTotal
$_->isa('Data::Rx::FailureSet') ? : 195 1507 1702
$arg->{"failures"} or [] 0 1632 1632
26 ]
27 };
28  
29 1632 bless $guts => $class;
30 }
31  
32 1334 ▶sub failures { $_[0]->{failures} }
Subroutine failures: called CC=1 SCAR=0.0
Pod undocumented
33  
34 sub contextualize {
35 251 ▶ my ($self, $struct) = @_;
Subroutine contextualize: called CC=2 SCAR=6.9
Pod undocumented
36  
37 251 foreach my $failure (@{ $self->{failures} }) {
38 253 $failure->contextualize($struct);
39 }
40  
41 251 return $self;
42 }
43  
44 sub stringify {
45 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=2 SCAR=17.9
Pod undocumented
46  
47 0 ▶ if (@{$self->{failures}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'failures'};}) { } 0 0 0
48 0 return join "\n", map "$_", @{$self->{failures}};
49 } else {
50 0 return "No failures\n";
51 }
52 }
53  
54 sub build_struct {
55 0 ▶ my ($self) = @_;
Subroutine build_struct: not called CC=24 SCAR=64.0
Pod undocumented
56  
57 0 ▶ return unless @{$self->{failures}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"failures"};} 0 0 0
58  
59 0 my $data;
60  
61 0 foreach my $failure (@{$self->{failures}}) {
62  
63 0 my @path = $failure->data_path;
64 0 my @type = $failure->data_path_type;
65  
66 0 ▶ @path == @type or die "bad path info in build_struct()";
Branch: 1 branch
BranchTrueFalseTotal
@path == @type or die "bad path info in build_struct()" 0 0 0
67  
68 # go to the appropriate location in the struct, vivifying as necessary
69  
70 0 my $p = \$data;
71  
72 0 ▶ for (my $i = 0; $i < @path; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @path) 0 0 0
73 0 ▶ if ($type[$i] eq 'k') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type[$i] eq 'k') { } 0 0 0
elsif ($type[$i] eq 'i') { } 0 0 0
74 0 ▶ if (ref $$p && ref $$p ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$p and ref $$p ne "HASH") 0 0 0
Condition0%0/3
ref $$p and ref $$p ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $$p and ref $$p ne "HASH"
ref $$p ref $$p ne "HASH"
Truth table0%0/3
A and B
A= ref $$pB= ref $$p ne "HASH"
ABresult
0X0
100
111
75 0 die "conflict in path info in build_struct()";
76 }
77 # if $$p already points to an error, replace it with the ref
78 # I believe this can only happen with type errors in //all -- rjk
79 0 ▶ $$p = {} unless ref $$p;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$p 0 0 0
80 0 $p = \$$p->{$path[$i]};
81 } elsif ($type[$i] eq 'i') {
82 0 ▶ if (ref $$p && ref $$p ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$p and ref $$p ne "ARRAY") 0 0 0
Condition0%0/3
ref $$p and ref $$p ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $$p and ref $$p ne "ARRAY"
ref $$p ref $$p ne "ARRAY"
Truth table0%0/3
A and B
A= ref $$pB= ref $$p ne "ARRAY"
ABresult
0X0
100
111
83 0 die "conflict in path info in build_struct()";
84 }
85 # if $$p already points to an error, replace it with the ref
86 # I believe this can only happen with type errors in //all -- rjk
87 0 ▶ $$p = [] unless ref $$p;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$p 0 0 0
88 0 $p = \$$p->[$path[$i]];
89 } else {
90 0 die "bad path type in build_struct()";
91 }
92 }
93  
94  
95 # insert the errors into the struct at the current location
96  
97 0 my $error = ($failure->error_types)[0];
98  
99 0 ▶ if ($error eq 'missing' || $error eq 'unexpected') {
Branch: 2 branches
BranchTrueFalseTotal
if ($error eq 'missing' or $error eq 'unexpected') { } 0 0 0
elsif ($error eq 'size') { } 0 0 0
Condition0%0/3
$error eq "missing" or $error eq "unexpected"
l!l&&r!l&&!r
000
MC/DC0%0/2
$error eq "missing" or $error eq "unexpected"
$error eq "missing" $error eq "unexpected"
Truth table0%0/3
A or B
A= $error eq "missing"B= $error eq "unexpected"
ABresult
1X1
011
000
100  
101 0 ▶ if (defined $$p && ref $$p ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$p and ref $$p ne "HASH") 0 0 0
Condition0%0/3
defined $$p and ref $$p ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$p and ref $$p ne "HASH"
defined $$p ref $$p ne "HASH"
Truth table0%0/3
A and B
A= defined $$pB= ref $$p ne "HASH"
ABresult
0X0
100
111
102 0 die "conflict in path info in build_struct()";
103 }
104  
105 0 my @keys = $failure->keys;
106  
107 0 ▶ $$p ||= {};
Condition0%0/2
$$p ||= {}
l!l
00
MC/DC0%0/1
$$p ||= {}
$$p
Truth table0%0/2
A
A= $$p
Aresult
11
00
108 0 @{$$p}{@keys} = ($error) x @keys;
109  
110 } elsif ($error eq 'size') {
111  
112 0 ▶ if (defined $$p && ref $$p ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$p and ref $$p ne "ARRAY") 0 0 0
Condition0%0/3
defined $$p and ref $$p ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$p and ref $$p ne "ARRAY"
defined $$p ref $$p ne "ARRAY"
Truth table0%0/3
A and B
A= defined $$pB= ref $$p ne "ARRAY"
ABresult
0X0
100
111
113 0 die "conflict in path info in build_struct()";
114 }
115  
116 0 my $size = $failure->size;
117  
118 0 ▶ $$p ||= [];
Condition0%0/2
$$p ||= []
l!l
00
MC/DC0%0/1
$$p ||= []
$$p
Truth table0%0/2
A
A= $$p
Aresult
11
00
119 0 $$p->[$size] = $error;
120  
121 } else {
122  
123 0 ▶ if (ref $$p) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$p) { } 0 0 0
124 # if $$p already points to a ref, leave it and skip the error
125 # I believe this can only happen with type errors in //all -- rjk
126 } else {
127 0 ▶ $$p .= ',' if defined $$p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p 0 0 0
128 0 $$p .= $error;
129 }
130  
131 }
132 }
133  
134 0 return $data;
135 }
136  
137 1 1;
138  
139 __END__
↑ Summary Rx/CoreType/rec.pm »