Modern/ResultNode.pm

filter: Statementstmt 96.0% 73 / 76 Branchbran 85.0% 17 / 20 Conditioncond 78.9% 15 / 19 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 3 totaltotal 88.5% 132 / 149 CC 18 SCAR 18.3
CC
18
Cov
91%
__ANON__
14.4
dump
6.0
TO_JSON
3.0
CRAP 6.3
« Modern/Vocabulary/Validation.pm ↑ Summary Modern/Document.pm »
1 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package JSON::Schema::Modern::ResultNode;
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Common code for nodes of a JSON::Schema::Modern::Result
6  
7 46 our $VERSION = '0.654';
8  
9 46 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 46 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 46 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 46 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 46 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 46 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 46 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 46 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 46 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 46 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 46 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 46 ▶use Types::Standard qw(Str Undef InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 46 ▶use Types::Common::Numeric 'PositiveOrZeroInt';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 46 ▶use JSON::Schema::Modern::Utilities qw(jsonp json_pointer_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 46 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # not provided when Error and mode = traverse
27 46 has instance_location => (
28 is => 'ro',
29 isa => json_pointer_type,
30 );
31  
32 46 has keyword_location => (
33 is => 'ro',
34 isa => json_pointer_type,
35 required => 1,
36 );
37  
38 has absolute_keyword_location => (
39 is => 'ro',
40 isa => InstanceOf['Mojo::URL']|Undef,
41 lazy => 1,
42 12754 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=14 SCAR=26.6
43 # _uri contains data as populated from A() and E():
44 # [ $state->{initial_schema_uri}, $state->{keyword_path}, @extra_path ]
45 # we do the equivalent of:
46 # canonical_uri($state, @extra_path);
47 12754 ▶ if (my $uri_bits = delete $self->{_uri}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $uri_bits = delete $$self{"_uri"}) 12743 11 12754
48 12743 my ($initial_schema_uri, $keyword_path, @extra_path) = @$uri_bits;
49  
50 12743 ▶ return($initial_schema_uri eq '' && $self->{keyword_location} eq '' ? undef : $initial_schema_uri)
Branch: 2 branches
BranchTrueFalseTotal
unless @extra_path or length $keyword_path 124 12619 12743
$initial_schema_uri eq '' && $$self{'keyword_location'} eq '' ? : 94 30 124
Condition100%6/6
@extra_path or length $keyword_path
l!l&&r!l&&!r
12306313124
$initial_schema_uri eq "" and $$self{"keyword_location"} eq ""
!ll&&!rl&&r
29194
MC/DC100%2/2
@extra_path or length $keyword_path
@extra_path length $keyword_path
MC/DC100%2/2
$initial_schema_uri eq "" and $$self{"keyword_location"} eq ""
$initial_schema_uri eq "" $$self{"keyword_location"} eq ""
Truth table100%3/3
A or B
A= @extra_pathB= length $keyword_path
ABresult
1X1
011
000
Truth table100%3/3
A and B
A= $initial_schema_uri eq ""B= $$self{"keyword_location"} eq ""
ABresult
0X0
100
111
51 if not @extra_path and not length($keyword_path);
52  
53 12619 my $uri = $initial_schema_uri->clone;
54 12619 ▶ my $fragment = ($uri->fragment//'').(@extra_path ? jsonp($keyword_path, @extra_path) : $keyword_path);
Branch: 1 branch
BranchTrueFalseTotal
@extra_path ? : 12306 313 12619
Condition100%2/2
$uri->fragment // ""
l!l
73011889
MC/DC100%1/1
$uri->fragment // ""
$uri->fragment
Truth table100%2/2
A
A= $uri->fragment
Aresult
11
00
55 12619 ▶ undef $fragment if not length($fragment);
Branch: 1 branch
BranchTrueFalseTotal
unless length $fragment 0 12619 12619
56 12619 $uri->fragment($fragment);
57  
58 undef $uri if $uri eq '' and $self->{keyword_location} eq ''
59 12619 ▶ or ($uri->fragment // '') eq $self->{keyword_location} and $uri->clone->fragment(undef) eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq "" and $$self{"keyword_location"} eq "" or ($uri->fragment // "") eq $$self{"keyword_location"} and $uri->clone->fragment(undef) eq "" 10584 2035 12619
Condition63%7/11
$uri eq "" and $$self{"keyword_location"} eq "" or ($uri->fragment // "") eq $$self{"keyword_location"} and $uri->clone->fragment(undef) eq ""
l!l&&r!l&&!r
0105842035
$uri eq "" and $$self{"keyword_location"} eq ""
!ll&&!rl&&r
1261900
($uri->fragment // "") eq $$self{"keyword_location"} and $uri->clone->fragment(undef) eq ""
!ll&&!rl&&r
152151410584
$uri->fragment // ""
l!l
126190
MC/DC25%1/4
$uri eq "" and $$self{"keyword_location"} eq "" or ($uri->fragment // "") eq $$self{"keyword_location"} and $uri->clone->fragment(undef) eq ""
$uri eq "" $$self{"keyword_location"} eq "" $uri->fragment $uri->clone->fragment(undef) eq ""
Truth table28%2/7
A and B or C and D
A= $uri eq ""B= $$self{"keyword_location"} eq ""C= $uri->fragmentD= $uri->clone->fragment(undef) eq ""
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
60 12619 return $uri;
61 }
62  
63 11 return;
64 },
65 46 );
66  
67 46 has keyword => (
68 is => 'ro',
69 isa => Str|Undef,
70 required => 1,
71 );
72  
73 46 has depth => (
74 is => 'ro',
75 isa => PositiveOrZeroInt,
76 required => 1,
77 );
78  
79 # TODO: maybe need to support being passed an already-blessed object
80  
81 14201 ▶sub BUILD ($self, $args) {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
82 14201 ▶ $self->{_uri} = $args->{_uri} if exists $args->{_uri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$args{"_uri"} 14180 21 14201
83 }
84  
85 18861 ▶sub TO_JSON ($self) {
Subroutine TO_JSON: called CC=3 SCAR=11.0
Pod undocumented
86 18861 my $thing = $self->__thing; # annotation or error
87  
88 return +{
89 # note that locations are JSON pointers, not uri fragments!
90 18861 ▶ !defined($self->instance_location) ? () : (instanceLocation => $self->instance_location),
Branch: 2 branches
BranchTrueFalseTotal
!defined($self->instance_location) ? : 286 18575 18861
!defined($self->absolute_keyword_location) ? : 15930 2931 18861
91 keywordLocation => $self->keyword_location,
92 !defined($self->absolute_keyword_location) ? ()
93 : (absoluteKeywordLocation => $self->absolute_keyword_location->to_string),
94 $thing => $self->$thing, # TODO: allow localization in error message
95 };
96 }
97  
98 0 ▶sub dump ($self) {
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
99 0 my $encoder = JSON::Schema::Modern::_JSON_BACKEND()->new
100 ->utf8(0)
101 ->convert_blessed(1)
102 ->canonical(1)
103 ->indent(1)
104 ->space_after(1);
105 0 ▶ $encoder->indent_length(2) if $encoder->can('indent_length');
Branch: 1 branch
BranchTrueFalseTotal
if $encoder->can("indent_length") 0 0 0
106 0 $encoder->encode($self);
107 }
108  
109 46 1;
110  
111 __END__
« Modern/Vocabulary/Validation.pm ↑ Summary Modern/Document.pm »