| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($type[$i] eq 'k') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (ref $$p && ref $$p ne 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $$p and ref $$p ne "HASH"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 80 | 0 | $p = \$$p->{$path[$i]}; | |||||||||||||||||||||||||||||||
| 81 | } elsif ($type[$i] eq 'i') { | ||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (ref $$p && ref $$p ne 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $$p and ref $$p ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$error eq "missing" or $error eq "unexpected"
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"
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (defined $$p && ref $$p ne 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $$p and ref $$p ne "HASH"
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"
| |||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$$p ||= {}
$$p
Truth table0%0/2
A
A= $$p
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $$p and ref $$p ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||
| 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 ||= []
MC/DC0%0/1
$$p ||= []
$$p
Truth table0%0/2
A
A= $$p
| |||||||||||||||||||||||||||||||||
| 119 | 0 | $$p->[$size] = $error; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (ref $$p) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 128 | 0 | $$p .= $error; | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 0 | return $data; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||||||