| 1 | package JSONSchema::Validator::Error; | ||||||||||||
| 2 | |||||||||||||
| 3 | # ABSTRACT: Error class | ||||||||||||
| 4 | |||||||||||||
| 5 | 16 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 16 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | use overload | ||||||||||||
| 9 | 4 | ▶ | '""' => sub { $_[0]->to_string }, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 16 | fallback => 1; | |||||||||||
| 11 | |||||||||||||
| 12 | 16 | our @ISA = 'Exporter'; | |||||||||||
| 13 | 16 | our @EXPORT_OK = qw(error); | |||||||||||
| 14 | |||||||||||||
| 15 | 498 | ▶ | sub error { | ||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 16 | 498 | return __PACKAGE__->new(@_); | |||||||||||
| 17 | } | ||||||||||||
| 18 | |||||||||||||
| 19 | 498 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 20 | 498 | my ($class, %params) = @_; | |||||||||||
| 21 | |||||||||||||
| 22 | return bless { | ||||||||||||
| 23 | message => $params{message}, | ||||||||||||
| 24 | context => $params{context} // [], | ||||||||||||
| 25 | # parent => $params{parent}, | ||||||||||||
| 26 | instance_path => $params{instance_path}, | ||||||||||||
| 27 | schema_path => $params{schema_path} | ||||||||||||
| 28 | 498 | ▶ | }, $class; | ||||||||||
|
Condition100%2/2
$params{"context"} // []
MC/DC100%1/1
$params{"context"} // []
$params{"context"}
Truth table100%2/2
A
A= $params{"context"}
| |||||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 0 | ▶ | sub context { shift->{context} } | ||||||||||
|
Subroutine
context: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 32 | 4 | ▶ | sub message { shift->{message} } | ||||||||||
|
Subroutine
message: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 33 | 4 | ▶ | sub instance_path { shift->{instance_path} } | ||||||||||
|
Subroutine
instance_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 34 | 4 | ▶ | sub schema_path { shift->{schema_path} } | ||||||||||
|
Subroutine
schema_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 35 | |||||||||||||
| 36 | 4 | ▶ | sub to_string { | ||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||
| 37 | 4 | my $self = shift; | |||||||||||
| 38 | 4 | my $msg = $self->message; | |||||||||||
| 39 | 4 | my $instance_path = $self->instance_path; | |||||||||||
| 40 | 4 | my $schema_path = $self->schema_path; | |||||||||||
| 41 | 4 | ▶ | $msg .= " [instance path: ${instance_path}]" if $instance_path; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 4 | ▶ | $msg .= " [schema path: ${schema_path}]" if $schema_path; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 4 | return $msg; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | sub unwind_to_string_list { | ||||||||||
|
Subroutine
unwind_to_string_list: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||
| 48 | 0 | ▶ | return [$self->to_string] unless @{$self->context}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | |||||||||||||
| 50 | 0 | my $res = []; | |||||||||||
| 51 | 0 | my $msg = $self->message; | |||||||||||
| 52 | |||||||||||||
| 53 | 0 | for my $err (@{$self->context}) { | |||||||||||
| 54 | 0 | for my $err_str (@{$err->unwind_to_string_list}) { | |||||||||||
| 55 | 0 | push @$res, "$msg: $err_str"; | |||||||||||
| 56 | } | ||||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 0 | return $res; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 0 | ▶ | sub TO_JSON { | ||||||||||
|
Subroutine
TO_JSON: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||
| 64 | 0 | my $res = { | |||||||||||
| 65 | message => $self->message | ||||||||||||
| 66 | }; | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | $res->{instance_path} = $self->instance_path | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | if $self->instance_path; | ||||||||||||
| 70 | 0 | ▶ | $res->{schema_path} = $self->schema_path | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | if $self->schema_path; | ||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | if (@{$self->context}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | $res->{context} = [ | ||||||||||||
| 75 | 0 | map { $_->TO_JSON } | |||||||||||
| 76 | 0 | @{$self->context} | |||||||||||
| 77 | ]; | ||||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 0 | return $res; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 16 | 1; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||