Rx/Failure.pm

filter: Statementstmt 71.0% 49 / 69 Branchbran 20.0% 2 / 10 Conditioncond 62.5% 5 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 13 totaltotal 58.6% 71 / 121 CC 14 SCAR 17.9
CC
14
Cov
64%
_path_string
17.6
keys
6.0
stringify
4.1
CRAP 6.0
« Rx/CoreType/num.pm ↑ Summary Rx/CoreType/str.pm »
1 1 ▶use v5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Data::Rx::Failure 0.200008;
4 # ABSTRACT: structured failure report from an Rx checker
5  
6 #pod =head1 SYNOPSIS
7 #pod
8 #pod This is part of a L<Data::Rx::FailureSet>, which is what is thrown when a
9 #pod schema's C<assert_valid> method finds a problem with the input. For more
10 #pod information on it, look at the documentation for L<Data::Rx>.
11 #pod
12 #pod =cut
13  
14 1 ▶use overload '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1507 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 1507 my ($class, $arg) = @_;
18  
19 my $guts = {
20 rx => $arg->{rx},
21 1507 struct => [ $arg->{struct} ],
22 };
23  
24 1507 bless $guts => $class;
25 }
26  
27 4780 ▶sub struct { $_[0]->{struct} }
Subroutine struct: called CC=1 SCAR=0.0
Pod undocumented
28  
29 253 ▶sub contextualize {
Subroutine contextualize: called CC=3 SCAR=11.4
Pod undocumented
30 253 my ($self, $struct) = @_;
31  
32 253 push @{ $self->struct }, $struct;
33  
34 253 ▶ if (my $failures = $self->struct->[0]{failures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $failures = $self->struct->[0]{"failures"}) 0 253 253
35 0 $_->contextualize($struct) foreach @$failures;
36 }
37  
38 253 return $self;
39 }
40  
41 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my ($self) = @_;
43  
44 0 return $self->struct->[0]{value};
45 }
46  
47 1488 ▶sub error_types {
Subroutine error_types: called CC=1 SCAR=0.0
Pod undocumented
48 1488 my ($self) = @_;
49  
50 1488 return @{ $self->struct->[0]{error} };
51 }
52  
53 47 ▶sub error_string {
Subroutine error_string: called CC=1 SCAR=0.0
Pod undocumented
54 47 my ($self) = @_;
55  
56 47 join ', ', $self->error_types;
57 }
58  
59 0 ▶sub keys {
Subroutine keys: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my ($self) = @_;
61  
62 0 ▶ return @{ $self->struct->[0]{keys} || [] };
Condition0%0/2
$self->struct->[0]{'keys'} || []
l!l
00
MC/DC0%0/1
$self->struct->[0]{'keys'} || []
$self->struct->[0]{'keys'}
Truth table0%0/2
A
A= $self->struct->[0]{'keys'}
Aresult
11
00
63 }
64  
65 0 ▶sub size {
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ($self) = @_;
67  
68 0 return $self->struct->[0]{size};
69 }
70  
71 1347 ▶sub data_path {
Subroutine data_path: called CC=2 SCAR=6.9
Pod undocumented
72 1347 my ($self) = @_;
73  
74 1452 ▶ map {; map { $_->[0] } @{ $_->{data_path} || [] } }
Condition100%2/2
$_->{'data_path'} || []
l!l
381414
MC/DC100%1/1
$_->{'data_path'} || []
$_->{'data_path'}
Truth table100%2/2
A
A= $_->{'data_path'}
Aresult
11
00
75 1347 reverse @{ $self->struct };
76 }
77  
78 47 ▶sub data_string {
Subroutine data_string: called CC=1 SCAR=0.0
Pod undocumented
79 47 my ($self) = @_;
80  
81 47 return $self->_path_string('$data', 'data_path');
82 }
83  
84 1345 ▶sub check_path {
Subroutine check_path: called CC=2 SCAR=6.9
Pod undocumented
85 1345 my ($self) = @_;
86  
87 1450 ▶ map {; map { $_->[0] } @{ $_->{check_path} || [] } }
Condition100%2/2
$_->{'check_path'} || []
l!l
1051345
MC/DC100%1/1
$_->{'check_path'} || []
$_->{'check_path'}
Truth table100%2/2
A
A= $_->{'check_path'}
Aresult
11
00
88 1345 reverse @{ $self->struct };
89 }
90  
91 0 ▶sub check_string {
Subroutine check_string: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my ($self) = @_;
93  
94 0 return $self->_path_string('$schema', 'check_path');
95 }
96  
97 47 ▶sub _path_string {
Subroutine _path_string: called CC=7 SCAR=28.7
98 47 my ($self, $base, $key) = @_;
99  
100 47 my $str = $base;
101  
102 47 ▶ for my $frame (reverse @{ $self->struct || [] }) {
Condition50%1/2
$self->struct || []
l!l
470
MC/DC0%0/1
$self->struct || []
$self->struct
Truth table50%1/2
A
A= $self->struct
Aresult
11
00
103 47 my $hunk = $frame->{ $key };
104 47 for my $entry (@$hunk) {
105 0 ▶ if ($entry->[1] eq 'key') { $str .= "->{$entry->[0]}"; }
Branch: 3 branches
BranchTrueFalseTotal
if ($entry->[1] eq 'key') { } 0 0 0
elsif ($entry->[1] eq 'index') { } 0 0 0
elsif ($entry->[2]) { } 0 0 0
106 0 elsif ($entry->[1] eq 'index') { $str .= "->[$entry->[0]]"; }
107 0 elsif ($entry->[2]) { $str = $entry->[2]->($str, @$entry) }
108 0 else { $str .= "->? $entry->[0] ?"; }
109 }
110 }
111  
112 47 return $str;
113 }
114  
115 47 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=14.2
Pod undocumented
116 47 my ($self) = @_;
117  
118 47 my $struct = $self->struct;
119  
120 my $str = sprintf "Failed %s: %s (error: %s at %s)",
121 $struct->[0]{type},
122 $struct->[0]{message},
123 47 $self->error_string,
124 $self->data_string;
125  
126 # also stringify failures under the current failure (as for //any),
127 # with indentation
128 47 ▶ if (my $failures = $struct->[0]{failures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $failures = $struct->[0]{"failures"}) 0 47 47
129 0 foreach my $fail (@$failures) {
130 0 my $tmp = "$fail";
131 0 $tmp =~ s/\A/ - /;
132 0 $tmp =~ s/(?<=\n)^/ /mg;
133 0 $str .= "\n$tmp";
134 }
135 }
136  
137 47 return $str;
138 }
139  
140 1 1;
141  
142 __END__
« Rx/CoreType/num.pm ↑ Summary Rx/CoreType/str.pm »