blib/lib/GraphQL/Houtou/Type/Object.pm

filter: Statementstmt 58.1% 75 / 129 Branchbran 23.9% 11 / 46 Conditioncond 24.4% 11 / 45 MC/DCmcdc 7.4% 2 / 27 Subroutinesub 79.3% 23 / 29 Podpod 0.0% 0 / 13 totaltotal 42.2% 122 / 289 CC 42 SCAR 40.6
CC
42
Cov
44%
_collect_fields
182.0
_fragment_condition_match
132.0
_should_include_node
30.0
CRAP 58.2
« blib/lib/GraphQL/Houtou/Runtime/VMOp.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/OperationCompiler.pm »
1 package GraphQL::Houtou::Type::Object;
2  
3 62 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 62 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 62 ▶use parent 'GraphQL::Houtou::Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 62 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 62 ▶use GraphQL::Houtou::Directive ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 62 ▶use GraphQL::Houtou::Error ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 62 ▶use GraphQL::Houtou::Internal::TypeSupport qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 apply_fields_deprecation
13 description_doc_lines
14 from_ast_fields
15 from_ast_maptype
16 make_fieldtuples
17 named_from_ast
18 62 );
19 62 ▶use GraphQL::Houtou::Type::List ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 62 ▶use GraphQL::Houtou::Type::NonNull ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 62 with qw(
23 GraphQL::Houtou::Role::Output
24 GraphQL::Houtou::Role::Composite
25 GraphQL::Houtou::Role::Named
26 GraphQL::Houtou::Role::FieldsOutput
27 GraphQL::Houtou::Role::HashMappable
28 );
29  
30 144 ▶sub list {
Subroutine list: called CC=2 SCAR=7.2
Pod undocumented
31 144 ▶ $_[0]->{_houtou_list} ||= GraphQL::Houtou::Type::List->new(of => $_[0]);
Condition66%2/3
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
l!l&&r!l&&!r
51930
MC/DC0%0/2
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
$_[0]{"_houtou_list"} "GraphQL::Houtou::Type::List"->new("of", $_[0])
Truth table66%2/3
A ||= B
A= $_[0]{"_houtou_list"}B= "GraphQL::Houtou::Type::List"->new("of", $_[0])
ABresult
1X1
011
000
32 }
33  
34 791 ▶sub non_null {
Subroutine non_null: called CC=2 SCAR=7.2
Pod undocumented
35 791 ▶ $_[0]->{_houtou_non_null} ||= GraphQL::Houtou::Type::NonNull->new(of => $_[0]);
Condition66%2/3
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
l!l&&r!l&&!r
4263650
MC/DC0%0/2
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
$_[0]{"_houtou_non_null"} "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
Truth table66%2/3
A ||= B
A= $_[0]{"_houtou_non_null"}B= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
ABresult
1X1
011
000
36 }
37  
38 62 ▶use constant DEBUG => $ENV{GRAPHQL_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 985 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
41 985 my ($class, %args) = @_;
42 985 ▶ die "GraphQL::Houtou::Type::Object requires name" if !defined $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"name"} 0 985 985
43 985 ▶ die "GraphQL::Houtou::Type::Object requires fields" if !exists $args{fields};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"fields"} 0 985 985
44 985 my $self = $class->SUPER::new(%args);
45 985 $self->{name} = $args{name};
46 985 $self->{description} = $args{description};
47 985 $self->{fields} = $args{fields};
48 985 ▶ $self->{interfaces} = $args{interfaces} || [];
Condition100%2/2
$args{'interfaces'} || []
l!l
165820
MC/DC100%1/1
$args{'interfaces'} || []
$args{'interfaces'}
Truth table100%2/2
A
A= $args{'interfaces'}
Aresult
11
00
49 985 $self->{is_type_of} = $args{is_type_of};
50 985 $self->{runtime_tag} = $args{runtime_tag};
51 985 return $self;
52 }
53  
54 59330 ▶sub name { return $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
55 9424 ▶sub description { return $_[0]->{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
56 28980 ▶sub to_string { return $_[0]->{to_string} ||= $_[0]->name }
Subroutine to_string: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0]{"to_string"} ||= $_[0]->name
l!l&&r!l&&!r
282357450
MC/DC0%0/2
$_[0]{"to_string"} ||= $_[0]->name
$_[0]{"to_string"} $_[0]->name
Truth table66%2/3
A ||= B
A= $_[0]{"to_string"}B= $_[0]->name
ABresult
1X1
011
000
57 10944 ▶sub is_type_of { return $_[0]->{is_type_of} }
Subroutine is_type_of: called CC=1 SCAR=0.0
Pod undocumented
58 1821 ▶sub runtime_tag { return $_[0]->{runtime_tag} }
Subroutine runtime_tag: called CC=1 SCAR=0.0
Pod undocumented
59  
60 23545 ▶sub interfaces {
Subroutine interfaces: called CC=2 SCAR=6.9
Pod undocumented
61 23545 my ($self) = @_;
62 23545 ▶ if (ref($self->{interfaces}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"interfaces"} eq "CODE") 137 23408 23545
63 137 $self->{interfaces} = $self->{interfaces}->();
64 }
65 23545 return $self->{interfaces};
66 }
67  
68 127 ▶sub from_ast {
Subroutine from_ast: called CC=1 SCAR=0.0
Pod undocumented
69 127 my ($class, $name2type, $ast_node) = @_;
70 127 return $class->new(
71 named_from_ast($ast_node),
72 from_ast_maptype($name2type, $ast_node, 'interfaces'),
73 from_ast_fields($name2type, $ast_node, 'fields'),
74 );
75 }
76  
77 24684 ▶sub fields {
Subroutine fields: called CC=3 SCAR=11.0
Pod undocumented
78 24684 my ($self) = @_;
79 24684 ▶ if (ref($self->{fields}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"fields"} eq "CODE") 294 24390 24684
80 294 $self->{fields} = $self->{fields}->();
81 }
82 24683 ▶ if (!$self->{_fields_deprecation_applied}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_fields_deprecation_applied"}) 909 23774 24683
83 909 $self->{fields} = apply_fields_deprecation($self->{fields});
84 909 $self->{_fields_deprecation_applied} = 1;
85 }
86 24683 return $self->{fields};
87 }
88  
89 0 ▶sub graphql_to_perl {
Subroutine graphql_to_perl: not called CC=2 SCAR=17.9
Pod undocumented
90 0 my ($self, $item) = @_;
91 0 my $fields = $self->fields;
92  
93 0 ▶ return $item if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 0 0
94 0 $item = $self->uplift($item);
95 0 ▶ return $self->hashmap($item, $fields, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
96 0 my ($key, $value) = @_;
97 0 ▶ return $fields->{$key}{type}->graphql_to_perl($value // $fields->{$key}{default_value});
Condition0%0/3
$value // $fields->{$key}{"default_value"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$value // $fields->{$key}{"default_value"}
$value $fields->{$key}{"default_value"}
Truth table0%0/3
A // B
A= $valueB= $fields->{$key}{"default_value"}
ABresult
1X1
011
000
98 0 });
99 }
100  
101 0 ▶sub _collect_fields {
Subroutine _collect_fields: not called CC=13 SCAR=52.0
102 0 my ($self, $context, $selections, $fields_got, $visited_fragments) = @_;
103  
104 0 for my $selection (@$selections) {
105 0 my $node = $selection;
106 0 ▶ next if !_should_include_node($context->{variable_values}, $node);
Branch: 1 branch
BranchTrueFalseTotal
unless _should_include_node($context->{"variable_values"}, $node) 0 0 0
107  
108 0 ▶ if ($selection->{kind} eq 'field') {
Branch: 1 branch
BranchTrueFalseTotal
if ($selection->{"kind"} eq "field") 0 0 0
109 0 ▶ my $use_name = $node->{alias} || $node->{name};
Condition0%0/3
$node->{'alias'} || $node->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{'alias'} || $node->{'name'}
$node->{'alias'} $node->{'name'}
Truth table0%0/3
A || B
A= $node->{'alias'}B= $node->{'name'}
ABresult
1X1
011
000
110 0 my ($field_names, $nodes_defs) = @$fields_got;
111 0 ▶ $field_names = [ @$field_names, $use_name ] if !exists $nodes_defs->{$use_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $nodes_defs->{$use_name} 0 0 0
112 $nodes_defs = {
113 %$nodes_defs,
114 0 ▶ $use_name => [ @{ $nodes_defs->{$use_name} || [] }, $node ],
Condition0%0/2
$nodes_defs->{$use_name} || []
l!l
00
MC/DC0%0/1
$nodes_defs->{$use_name} || []
$nodes_defs->{$use_name}
Truth table0%0/2
A
A= $nodes_defs->{$use_name}
Aresult
11
00
115 };
116 0 $fields_got = [ $field_names, $nodes_defs ];
117 0 next;
118 }
119  
120 0 ▶ if ($selection->{kind} eq 'inline_fragment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($selection->{"kind"} eq "inline_fragment") 0 0 0
121 0 ▶ next if !$self->_fragment_condition_match($context, $node);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fragment_condition_match($context, $node) 0 0 0
122 ($fields_got, $visited_fragments) = $self->_collect_fields(
123 $context,
124 $node->{selections},
125 0 $fields_got,
126 $visited_fragments,
127 );
128 0 next;
129 }
130  
131 0 ▶ if ($selection->{kind} eq 'fragment_spread') {
Branch: 1 branch
BranchTrueFalseTotal
if ($selection->{"kind"} eq "fragment_spread") 0 0 0
132 0 my $frag_name = $node->{name};
133 0 my $fragment;
134 0 ▶ next if $visited_fragments->{$frag_name};
Branch: 1 branch
BranchTrueFalseTotal
if $visited_fragments->{$frag_name} 0 0 0
135 0 $visited_fragments = { %$visited_fragments, $frag_name => 1 };
136 0 $fragment = $context->{fragments}{$frag_name};
137 0 ▶ next if !$fragment;
Branch: 1 branch
BranchTrueFalseTotal
unless $fragment 0 0 0
138 0 ▶ next if !$self->_fragment_condition_match($context, $fragment);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fragment_condition_match($context, $fragment) 0 0 0
139 ($fields_got, $visited_fragments) = $self->_collect_fields(
140 $context,
141 $fragment->{selections},
142 0 $fields_got,
143 $visited_fragments,
144 );
145 }
146 }
147  
148 0 return ($fields_got, $visited_fragments);
149 }
150  
151 0 ▶sub _fragment_condition_match {
Subroutine _fragment_condition_match: not called CC=11 SCAR=48.8
152 0 my ($self, $context, $node) = @_;
153 0 my $condition_type;
154 0 my $schema = $context->{schema};
155 0 ▶ my $runtime_cache = $context->{runtime_cache} || $schema->runtime_cache || $schema->prepare_runtime;
Condition0%0/6
$context->{'runtime_cache'} || $schema->runtime_cache || $schema->prepare_runtime
l!l&&r!l&&!r
000
$context->{"runtime_cache"} or $schema->runtime_cache
l!l&&r!l&&!r
000
MC/DC0%0/3
$context->{'runtime_cache'} || $schema->runtime_cache || $schema->prepare_runtime
$context->{"runtime_cache"} $schema->runtime_cache $schema->prepare_runtime
Truth table0%0/4
A or B || C
A= $context->{"runtime_cache"}B= $schema->runtime_cacheC= $schema->prepare_runtime
ABCresult
1XX1
01X1
0011
0000
156 0 ▶ my $name2type = $runtime_cache->{name2type} || $schema->name2type;
Condition0%0/3
$runtime_cache->{'name2type'} || $schema->name2type
l!l&&r!l&&!r
000
MC/DC0%0/2
$runtime_cache->{'name2type'} || $schema->name2type
$runtime_cache->{'name2type'} $schema->name2type
Truth table0%0/3
A || B
A= $runtime_cache->{'name2type'}B= $schema->name2type
ABresult
1X1
011
000
157 0 ▶ my $possible_type_map = $runtime_cache->{possible_type_map} ||= {};
Condition0%0/2
$runtime_cache->{"possible_type_map"} ||= {}
l!l
00
MC/DC0%0/1
$runtime_cache->{"possible_type_map"} ||= {}
$runtime_cache->{"possible_type_map"}
Truth table0%0/2
A
A= $runtime_cache->{"possible_type_map"}
Aresult
11
00
158  
159 0 ▶ return 1 if !$node->{on};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"on"} 0 0 0
160 0 ▶ return 1 if $node->{on} eq $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"on"} eq $self->name 0 0 0
161 $condition_type = $name2type->{ $node->{on} }
162 0 ▶ // die GraphQL::Houtou::Error->new(
Condition0%0/2
$$name2type{$node->{"on"}} // die("GraphQL::Houtou::Error"->new("message", qq[Unknown type for fragment condition '$node->{"on"}'.]))
l!l
00
MC/DC0%0/1
$$name2type{$node->{"on"}} // die("GraphQL::Houtou::Error"->new("message", qq[Unknown type for fragment condition '$node->{"on"}'.]))
$$name2type{$node->{"on"}}
Truth table0%0/2
A
A= $$name2type{$node->{"on"}}
Aresult
11
00
163 message => "Unknown type for fragment condition '$node->{on}'."
164 );
165 0 ▶ return '' if !$condition_type->DOES('GraphQL::Houtou::Role::Abstract')
Branch: 1 branch
BranchTrueFalseTotal
unless $condition_type->DOES("GraphQL::Houtou::Role::Abstract") or $condition_type->DOES("GraphQL::Role::Abstract") 0 0 0
Condition0%0/3
$condition_type->DOES("GraphQL::Houtou::Role::Abstract") or $condition_type->DOES("GraphQL::Role::Abstract")
l!l&&r!l&&!r
000
MC/DC0%0/2
$condition_type->DOES("GraphQL::Houtou::Role::Abstract") or $condition_type->DOES("GraphQL::Role::Abstract")
$condition_type->DOES("GraphQL::Houtou::Role::Abstract") $condition_type->DOES("GraphQL::Role::Abstract")
Truth table0%0/3
A or B
A= $condition_type->DOES("GraphQL::Houtou::Role::Abstract")B= $condition_type->DOES("GraphQL::Role::Abstract")
ABresult
1X1
011
000
166 && !$condition_type->DOES('GraphQL::Role::Abstract');
167 return $possible_type_map->{ $condition_type->name }{ $self->name }
168 0 ▶ if exists $possible_type_map->{ $condition_type->name };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$possible_type_map{$condition_type->name} 0 0 0
169 0 return $schema->is_possible_type($condition_type, $self);
170 }
171  
172 0 ▶sub _should_include_node {
Subroutine _should_include_node: not called CC=5 SCAR=34.0
173 0 my ($variables, $node) = @_;
174 0 my $skip = $GraphQL::Houtou::Directive::SKIP->_get_directive_values($node, $variables);
175 0 ▶ return '' if $skip && $skip->{if};
Branch: 1 branch
BranchTrueFalseTotal
if $skip and $skip->{"if"} 0 0 0
Condition0%0/3
$skip and $skip->{"if"}
!ll&&!rl&&r
000
MC/DC0%0/2
$skip and $skip->{"if"}
$skip $skip->{"if"}
Truth table0%0/3
A and B
A= $skipB= $skip->{"if"}
ABresult
0X0
100
111
176 0 my $include = $GraphQL::Houtou::Directive::INCLUDE->_get_directive_values($node, $variables);
177 0 ▶ return '' if $include && !$include->{if};
Branch: 1 branch
BranchTrueFalseTotal
if $include and not $include->{"if"} 0 0 0
Condition0%0/3
$include and not $include->{"if"}
!ll&&!rl&&r
000
MC/DC0%0/2
$include and not $include->{"if"}
$include not $include->{"if"}
Truth table0%0/3
A and not(B)
A= $includeB= not $include->{"if"}
ABresult
0X0
100
111
178 0 return 1;
179 }
180  
181 0 ▶sub _complete_value {
Subroutine _complete_value: not called CC=1 SCAR=6.9
182 0 my ($self) = @_;
183 0 die "Type::Object->_complete_value is part of the removed legacy execution path; use GraphQL::Houtou::Schema->build_runtime or ->build_native_runtime for object completion on '@{[$self->name]}'.\n";
184 }
185  
186 219 ▶sub to_doc {
Subroutine to_doc: called CC=5 SCAR=16.2
Pod undocumented
187 219 my ($self) = @_;
188 219 ▶ return $self->{to_doc} if exists $self->{to_doc};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"to_doc"} 104 115 219
189 my @fieldlines = map {
190 115 my ($main, @description) = @$_;
191 516 (@description, $main);
192 } make_fieldtuples($self->fields);
193 115 ▶ my $implements = join ' & ', map $_->name, @{ $self->interfaces || [] };
Condition50%1/2
$self->interfaces || []
l!l
1150
MC/DC0%0/1
$self->interfaces || []
$self->interfaces
Truth table50%1/2
A
A= $self->interfaces
Aresult
11
00
194 115 ▶ $implements &&= 'implements ' . $implements . ' ';
Condition100%2/2
$implements &&= 'implements ' . $implements . ' '
!ll
10015
MC/DC100%1/1
$implements &&= 'implements ' . $implements . ' '
$implements
Truth table100%2/2
A
A= $implements
Aresult
00
11
195 115 return $self->{to_doc} = join '', map "$_\n",
196 description_doc_lines($self->description),
197 115 ▶ "type @{[$self->name]} $implements\{",
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 1594 0 1594
198 (map length() ? " $_" : "", @fieldlines),
199 "}";
200 }
201  
202 62 1;
203  
204 __END__
« blib/lib/GraphQL/Houtou/Runtime/VMOp.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/OperationCompiler.pm »