blib/lib/GraphQL/Houtou/Runtime/NativeRuntime.pm

filter: Statementstmt 94.1% 438 / 465 Branchbran 75.3% 214 / 284 Conditioncond 67.8% 154 / 227 MC/DCmcdc 49.1% 60 / 122 Subroutinesub 98.5% 67 / 68 Podpod 26.9% 7 / 26 totaltotal 78.8% 940 / 1192 CC 227 SCAR 29.8
CC
227
Cov
83%
_document_request_errors
51.5
_specialize_runtime_directives_op
34.2
execute_document_to_json
32.8
CRAP 19.6
« blib/lib/GraphQL/Houtou/Runtime/VMBlock.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/SchemaGraph.pm »
1 package GraphQL::Houtou::Runtime::NativeRuntime;
2  
3 45 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 45 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 45 ▶use GraphQL::Houtou::Runtime::InputCoercion ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 45 ▶use GraphQL::Houtou::Runtime::DirectiveRuntime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 45 ▶use GraphQL::Houtou::Runtime::OperationCompiler ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 45 ▶use GraphQL::Houtou::Runtime::VMCompiler ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 45 ▶use GraphQL::Houtou::Async::Adapter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 45 ▶use GraphQL::Houtou::Schema ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 45 ▶use JSON::MaybeXS qw(decode_json encode_json is_bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 45 ▶use GraphQL::Houtou::Validation::DepthLimit ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 45 ▶use GraphQL::Houtou::Validation::NodeLimit ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 45 ▶use constant DEFAULT_MAX_DEPTH => GraphQL::Houtou::Validation::DepthLimit::DEFAULT_MAX_DEPTH();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 45 ▶use constant DEFAULT_MAX_NODES => GraphQL::Houtou::Validation::NodeLimit::DEFAULT_MAX_NODES();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 45 ▶use constant DEFAULT_MAX_COST => 10_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 45 ▶use constant DEFAULT_LIST_SIZE => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 248 ▶sub new {
Subroutine new: called CC=13 SCAR=25.8
Pod undocumented
26 248 my ($class, %args) = @_;
27 248 ▶ die "runtime_schema is required\n" if !$args{runtime_schema};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"runtime_schema"} 0 248 248
28 248 my $async_adapter = _async_adapter($args{async_adapter});
29 248 my $has_async_adapter = defined $args{async_adapter};
30 248 ▶ my $cache_max = exists $args{program_cache_max} ? $args{program_cache_max} : 1000;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'program_cache_max'} ? : 33 215 248
31 248 ▶ my $max_depth = exists $args{max_depth} ? $args{max_depth} : DEFAULT_MAX_DEPTH;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_depth'} ? : 5 243 248
32 248 ▶ my $max_nodes = exists $args{max_nodes} ? $args{max_nodes} : DEFAULT_MAX_NODES;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_nodes'} ? : 1 247 248
33 248 ▶ my $max_cost = exists $args{max_cost} ? $args{max_cost} : DEFAULT_MAX_COST;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_cost'} ? : 2 246 248
34 my $default_list_size = exists $args{default_list_size}
35 248 ▶ ? $args{default_list_size} : DEFAULT_LIST_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'default_list_size'} ? : 0 248 248
36 return bless {
37 runtime_schema => $args{runtime_schema},
38 native_runtime_struct => $args{native_runtime_struct},
39 native_runtime_compact_struct => $args{native_runtime_compact_struct},
40 native_runtime_handle => $args{native_runtime_handle},
41 _program_cache => {},
42 _program_cache_order => [],
43 _limit_signatures => {},
44 _program_cache_max => $cache_max,
45 _specialized_program_cache => {},
46 _specialized_program_cache_order => [],
47 _specialized_program_cache_max => $cache_max,
48 _max_depth => $max_depth,
49 _max_nodes => $max_nodes,
50 _max_cost => $max_cost,
51 _default_list_size => $default_list_size,
52 _validate => exists $args{validate} ? ($args{validate} ? 1 : 0) : 1,
53 _allow_introspection => exists $args{allow_introspection}
54 ? ($args{allow_introspection} ? 1 : 0) : 1,
55 248 ▶ _async => ($args{async} || $has_async_adapter) ? 1 : 0,
Branch: 5 branches
BranchTrueFalseTotal
exists $args{'validate'} ? : 6 242 248
$args{'validate'} ? : 0 6 6
exists $args{'allow_introspection'} ? : 3 245 248
$args{'allow_introspection'} ? : 0 3 3
$args{'async'} || $has_async_adapter ? : 112 136 248
Condition100%3/3
$args{"async"} or $has_async_adapter
l!l&&r!l&&!r
9121136
MC/DC100%2/2
$args{"async"} or $has_async_adapter
$args{"async"} $has_async_adapter
Truth table100%3/3
A or B
A= $args{"async"}B= $has_async_adapter
ABresult
1X1
011
000
56 _async_adapter => $async_adapter,
57 }, $class;
58 }
59  
60 2427 ▶sub runtime_schema { return $_[0]{runtime_schema} }
Subroutine runtime_schema: called CC=1 SCAR=0.0
Pod undocumented
61  
62 240 ▶sub _native_runtime_struct {
Subroutine _native_runtime_struct: called CC=2 SCAR=7.6
63 240 my ($self) = @_;
64 240 ▶ $self->{native_runtime_struct} ||= $self->runtime_schema->to_native_exec_struct;
Condition33%1/3
$self->{"native_runtime_struct"} ||= $self->runtime_schema->to_native_exec_struct
l!l&&r!l&&!r
02400
MC/DC0%0/2
$self->{"native_runtime_struct"} ||= $self->runtime_schema->to_native_exec_struct
$self->{"native_runtime_struct"} $self->runtime_schema->to_native_exec_struct
Truth table33%1/3
A ||= B
A= $self->{"native_runtime_struct"}B= $self->runtime_schema->to_native_exec_struct
ABresult
1X1
011
000
65 240 return $self->{native_runtime_struct};
66 }
67  
68 32 ▶sub _native_runtime_compact_struct {
Subroutine _native_runtime_compact_struct: called CC=2 SCAR=7.0
69 32 my ($self) = @_;
70 32 ▶ $self->{native_runtime_compact_struct} ||= $self->runtime_schema->to_native_compact_struct;
Condition66%2/3
$self->{"native_runtime_compact_struct"} ||= $self->runtime_schema->to_native_compact_struct
l!l&&r!l&&!r
12200
MC/DC0%0/2
$self->{"native_runtime_compact_struct"} ||= $self->runtime_schema->to_native_compact_struct
$self->{"native_runtime_compact_struct"} $self->runtime_schema->to_native_compact_struct
Truth table66%2/3
A ||= B
A= $self->{"native_runtime_compact_struct"}B= $self->runtime_schema->to_native_compact_struct
ABresult
1X1
011
000
71 32 return $self->{native_runtime_compact_struct};
72 }
73  
74 3766 ▶sub _native_runtime_handle {
Subroutine _native_runtime_handle: called CC=2 SCAR=7.0
75 3766 my ($self) = @_;
76 3766 GraphQL::Houtou::_bootstrap_xs();
77 $self->{native_runtime_handle} ||= GraphQL::Houtou::XS::VM::load_native_runtime_xs(
78 $self->_native_runtime_struct,
79 $self->{_async_adapter}->_spec,
80 3766 ▶ );
Condition66%2/3
$self->{"native_runtime_handle"} ||= GraphQL::Houtou::XS::VM::load_native_runtime_xs($self->_native_runtime_struct, $self->{"_async_adapter"}->_spec)
l!l&&r!l&&!r
35262400
MC/DC0%0/2
$self->{"native_runtime_handle"} ||= GraphQL::Houtou::XS::VM::load_native_runtime_xs($self->_native_runtime_struct, $self->{"_async_adapter"}->_spec)
$self->{"native_runtime_handle"} GraphQL::Houtou::XS::VM::load_native_runtime_xs($self->_native_runtime_struct, $self->{"_async_adapter"}->_spec)
Truth table66%2/3
A ||= B
A= $self->{"native_runtime_handle"}B= GraphQL::Houtou::XS::VM::load_native_runtime_xs($self->_native_runtime_struct, $self->{"_async_adapter"}->_spec)
ABresult
1X1
011
000
81 3765 return $self->{native_runtime_handle};
82 }
83  
84 248 ▶sub _async_adapter {
Subroutine _async_adapter: called CC=1 SCAR=0.0
85 248 my ($adapter) = @_;
86 248 return GraphQL::Houtou::Async::Adapter->coerce($adapter);
87 }
88  
89 1594 ▶sub _uses_promise_xs { $_[0]{_async_adapter}->is_builtin }
Subroutine _uses_promise_xs: called CC=1 SCAR=0.0
90  
91 420 ▶sub compile_program {
Subroutine compile_program: called CC=7 SCAR=19.6
Pod undocumented
92 420 my ($self, $document, %opts) = @_;
93 420 my $operation_name = delete $opts{operation_name};
94 420 ▶ if (!ref($document) && $self->{_program_cache_max}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $document and $self->{"_program_cache_max"}) 417 3 420
Condition100%3/3
not ref $document and $self->{"_program_cache_max"}
!ll&&!rl&&r
12417
MC/DC100%2/2
not ref $document and $self->{"_program_cache_max"}
not ref $document $self->{"_program_cache_max"}
Truth table100%3/3
not(A) and B
A= not ref $documentB= $self->{"_program_cache_max"}
ABresult
0X0
100
111
95 417 my $key = _document_cache_key($document, $operation_name);
96 417 my $cached = $self->{_program_cache}{$key};
97 417 ▶ return $cached if $cached;
Branch: 1 branch
BranchTrueFalseTotal
if $cached 33 384 417
98 384 ▶ my $source = defined $operation_name
Branch: 1 branch
BranchTrueFalseTotal
defined $operation_name ? : 6 378 384
99 ? _select_operation_ast(GraphQL::Houtou::parse($document), $operation_name)
100 : $document;
101 384 my $program = $self->runtime_schema->compile_program($source, %opts);
102 379 $self->_store_program_cache($key, $program);
103 379 return $program;
104 }
105 3 ▶ my $source = defined $operation_name
Branch: 2 branches
BranchTrueFalseTotal
defined $operation_name ? : 0 3 3
ref $document ? : 0 0 0
106 ? _select_operation_ast(
107 ref($document) ? $document : GraphQL::Houtou::parse($document),
108 $operation_name,
109 )
110 : $document;
111 3 return $self->runtime_schema->compile_program($source, %opts);
112 }
113  
114 # NUL is not a valid GraphQL source character, so joining on it cannot
115 # collide with a plain document key.
116 3099 ▶sub _document_cache_key {
Subroutine _document_cache_key: called CC=2 SCAR=6.9
117 3099 my ($document, $operation_name) = @_;
118 3099 ▶ return defined $operation_name ? $document . "\0" . $operation_name : $document;
Branch: 1 branch
BranchTrueFalseTotal
defined $operation_name ? : 28 3071 3099
119 }
120  
121 # The operation compiler executes the first operation in a document, so a
122 # request naming an operationName compiles a filtered AST: the named
123 # operation plus every fragment. Dies are GraphQL request errors (the
124 # document, not the server, is at fault) and become errors-only envelopes.
125 15 ▶sub _select_operation_ast {
Subroutine _select_operation_ast: called CC=7 SCAR=20.5
126 15 my ($ast, $operation_name) = @_;
127 15 ▶ die "GraphQL document must parse to a list of definitions\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $ast ne "ARRAY" 0 15 15
128 if ref($ast) ne 'ARRAY';
129 my ($selected) = grep {
130 15 ▶ ($_->{kind} || '') eq 'operation' && ($_->{name} || '') eq $operation_name
Condition57%4/7
($_->{'kind'} || '') eq 'operation' && ($_->{'name'} || '') eq $operation_name
!ll&&!rl&&r
01612
$_->{'kind'} || ''
l!l
280
$_->{'name'} || ''
l!l
280
MC/DC0%0/2
($_->{'kind'} || '') eq 'operation' && ($_->{'name'} || '') eq $operation_name
$_->{'kind'} $_->{'name'}
Truth table33%1/3
A && B
A= $_->{'kind'}B= $_->{'name'}
ABresult
0X0
100
111
131 } @$ast;
132 15 ▶ die qq{Operation "$operation_name" was not found in the document\n}
Branch: 1 branch
BranchTrueFalseTotal
unless $selected 3 12 15
133 if !$selected;
134 12 ▶ return [ $selected, grep { ($_->{kind} || '') eq 'fragment' } @$ast ];
Condition50%1/2
$_->{'kind'} || ''
l!l
240
MC/DC0%0/1
$_->{'kind'} || ''
$_->{'kind'}
Truth table50%1/2
A
A= $_->{'kind'}
Aresult
11
00
135 }
136  
137 379 ▶sub _store_program_cache {
Subroutine _store_program_cache: called CC=2 SCAR=6.9
138 379 my ($self, $key, $program) = @_;
139 379 my $cache = $self->{_program_cache};
140 379 my $order = $self->{_program_cache_order};
141 379 ▶ if (scalar(@$order) >= $self->{_program_cache_max}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$order >= $self->{"_program_cache_max"}) 1 378 379
142 1 my $evicted = shift @$order;
143 1 delete $cache->{$evicted};
144 1 delete $self->{_validated_documents}{$evicted};
145 1 delete $self->{_limit_signatures}{$evicted};
146 }
147 379 $cache->{$key} = $program;
148 379 push @$order, $key;
149 }
150  
151 22 ▶sub program_cache_size { scalar keys %{ $_[0]{_program_cache} } }
Subroutine program_cache_size: called CC=1 SCAR=0.0
Pod undocumented
152  
153 4 ▶sub clear_program_cache {
Subroutine clear_program_cache: called CC=1 SCAR=0.0
Pod undocumented
154 4 my ($self) = @_;
155 4 $self->{_program_cache} = {};
156 4 $self->{_program_cache_order} = [];
157 4 $self->{_specialized_program_cache} = {};
158 4 $self->{_specialized_program_cache_order} = [];
159 4 $self->{_validated_documents} = {};
160 4 $self->{_limit_signatures} = {};
161 }
162  
163 2227 ▶sub _limit_signature {
Subroutine _limit_signature: called CC=2 SCAR=6.9
164 2227 ▶ return join "\0", map { defined $_ ? $_ : 'off' } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 11133 2 11135
165 }
166  
167 8 ▶sub _introspection_errors {
Subroutine _introspection_errors: called CC=12 SCAR=25.4
168 8 my ($ast) = @_;
169 8 ▶ my @pending = ref($ast) eq 'ARRAY' ? @$ast : ($ast);
Branch: 1 branch
BranchTrueFalseTotal
ref $ast eq 'ARRAY' ? : 8 0 8
170 8 ▶ for (my $cursor = 0; $cursor < @pending; $cursor++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor < @pending) 19 1 20
171 19 my $node = $pending[$cursor];
172 19 ▶ next if ref($node) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $node ne "HASH" 0 19 19
173 19 ▶ if (($node->{kind} || q()) eq 'field'
Branch: 1 branch
BranchTrueFalseTotal
if (($node->{"kind"} || "") eq "field" and ($node->{"name"} || "") eq "__schema" || ($node->{"name"} || "") eq "__type") 7 12 19
Condition75%9/12
($node->{"kind"} || "") eq "field" and ($node->{"name"} || "") eq "__schema" || ($node->{"name"} || "") eq "__type"
!ll&&!rl&&r
1027
$node->{'kind'} || ''
l!l
190
($node->{"name"} || "") eq "__schema" or ($node->{"name"} || "") eq "__type"
l!l&&r!l&&!r
522
$node->{'name'} || ''
l!l
90
$node->{'name'} || ''
l!l
40
MC/DC0%0/3
($node->{"kind"} || "") eq "field" and ($node->{"name"} || "") eq "__schema" || ($node->{"name"} || "") eq "__type"
$node->{'kind'} $node->{'name'} $node->{'name'}
Truth table25%1/4
A and B or C
A= $node->{'kind'}B= $node->{'name'}C= $node->{'name'}
ABCresult
0XX0
1000
11X1
1011
174 && (($node->{name} || q()) eq '__schema'
175 || ($node->{name} || q()) eq '__type')) {
176 7 my $field_name = $node->{name};
177 return [ {
178 message => qq{Introspection field "$field_name" is disabled},
179 7 ▶ (defined $node->{location} ? (locations => [ $node->{location} ]) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $node->{'location'} ? : 7 0 7
180 extensions => { code => 'INTROSPECTION_DISABLED' },
181 } ];
182 }
183 12 ▶ push @pending, @{ $node->{selections} || [] };
Condition100%2/2
$node->{'selections'} || []
l!l
93
MC/DC100%1/1
$node->{'selections'} || []
$node->{'selections'}
Truth table100%2/2
A
A= $node->{'selections'}
Aresult
11
00
184 }
185 1 return [];
186 }
187  
188 21 ▶sub compile_bundle_for_document {
Subroutine compile_bundle_for_document: called CC=1 SCAR=0.0
Pod undocumented
189 21 my ($self, $document, %opts) = @_;
190 21 my $descriptor = $self->compile_bundle_descriptor_for_document($document, %opts);
191 21 return $self->load_bundle_descriptor($descriptor);
192 }
193  
194 37 ▶sub specialize_program {
Subroutine specialize_program: called CC=2 SCAR=7.0
Pod undocumented
195 37 my ($self, $program, %opts) = @_;
196 37 my $candidate = $self->specialize_program_for_native(
197 $program,
198 %opts,
199 );
200 37 my $struct = _require_native_program($candidate);
201 37 GraphQL::Houtou::_bootstrap_xs();
202 37 ▶ die "Program cannot be specialized into the native VM path.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless GraphQL::Houtou::XS::VM::program_native_eligible_xs($struct, 0) 0 37 37
203 if !GraphQL::Houtou::XS::VM::program_native_eligible_xs($struct, 0);
204 37 return $candidate;
205 }
206  
207 38 ▶sub specialize_program_for_native {
Subroutine specialize_program_for_native: called CC=3 SCAR=11.0
Pod undocumented
208 38 my ($self, $program, %opts) = @_;
209 38 ▶ return $program if !$program;
Branch: 1 branch
BranchTrueFalseTotal
unless $program 0 38 38
210  
211 38 my $native_program = _require_native_program($program);
212 my $variables = GraphQL::Houtou::Runtime::InputCoercion::prepare_variables(
213 $self->runtime_schema,
214 $native_program,
215 $opts{variables} || {},
216 38 ▶ );
Condition100%2/2
$opts{'variables'} || {}
l!l
236
MC/DC100%1/1
$opts{'variables'} || {}
$opts{'variables'}
Truth table100%2/2
A
A= $opts{'variables'}
Aresult
11
00
217 38 GraphQL::Houtou::_bootstrap_xs();
218 38 return $self->_specialize_program_descriptor(
219 $native_program,
220 $variables,
221 );
222 }
223  
224 41 ▶sub _specialize_program_descriptor {
Subroutine _specialize_program_descriptor: called CC=3 SCAR=11.6
225 41 my ($self, $native_program, $variables) = @_;
226 41 my $specialized = GraphQL::Houtou::XS::VM::specialize_native_program_xs(
227 $self->_native_runtime_handle,
228 $native_program,
229 $variables,
230 );
231 41 ▶ my $descriptor = ref($specialized) && eval { $specialized->isa('GraphQL::Houtou::Runtime::NativeProgram') }
Branch: 1 branch
BranchTrueFalseTotal
ref $specialized && eval { do { $specialized->isa('GraphQL::Houtou::Runtime::NativeProgram') } } ? : 41 0 41
Condition33%1/3
ref $specialized and eval { do { $specialized->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
!ll&&!rl&&r
0041
MC/DC0%0/2
ref $specialized and eval { do { $specialized->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
ref $specialized eval { do { $specialized->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
Truth table33%1/3
A and B
A= ref $specializedB= eval { do { $specialized->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
ABresult
0X0
100
111
232 ? GraphQL::Houtou::XS::VM::native_program_descriptor_xs($specialized)
233 : $specialized;
234 41 _specialize_runtime_directives_payloads($descriptor, $variables);
235 41 return GraphQL::Houtou::XS::VM::load_native_program_xs($descriptor);
236 }
237  
238 1 ▶sub compile_bundle {
Subroutine compile_bundle: called CC=1 SCAR=0.0
Pod undocumented
239 1 my ($self, $program, %opts) = @_;
240 1 my $candidate = $self->specialize_program($program, %opts);
241 1 return $self->_load_bundle_parts(_require_native_program($candidate));
242 }
243  
244 32 ▶sub compile_bundle_descriptor {
Subroutine compile_bundle_descriptor: called CC=1 SCAR=0.0
Pod undocumented
245 32 my ($self, $program, %opts) = @_;
246 32 my $candidate = $self->specialize_program($program, %opts);
247 32 GraphQL::Houtou::_bootstrap_xs();
248 return {
249 32 runtime => $self->_native_runtime_compact_struct,
250 program => GraphQL::Houtou::XS::VM::native_program_descriptor_xs($candidate),
251 };
252 }
253  
254 4 ▶sub compile_program_descriptor {
Subroutine compile_program_descriptor: called CC=1 SCAR=0.0
Pod undocumented
255 4 my ($self, $program, %opts) = @_;
256 4 my $candidate = $self->specialize_program($program, %opts);
257 4 GraphQL::Houtou::_bootstrap_xs();
258 4 return GraphQL::Houtou::XS::VM::native_program_descriptor_xs($candidate);
259 }
260  
261 4 ▶sub compile_program_descriptor_for_document {
Subroutine compile_program_descriptor_for_document: called CC=1 SCAR=0.0
Pod undocumented
262 4 my ($self, $document, %opts) = @_;
263 4 my $program = $self->compile_program($document, %opts);
264 4 return $self->compile_program_descriptor($program, %opts);
265 }
266  
267 31 ▶sub compile_bundle_descriptor_for_document {
Subroutine compile_bundle_descriptor_for_document: called CC=1 SCAR=0.0
Pod undocumented
268 31 my ($self, $document, %opts) = @_;
269 31 my $program = $self->compile_program($document, %opts);
270 31 return $self->compile_bundle_descriptor($program, %opts);
271 }
272  
273 1 ▶sub _load_bundle_parts {
Subroutine _load_bundle_parts: called CC=1 SCAR=0.0
274 1 my ($self, $program) = @_;
275 1 GraphQL::Houtou::_bootstrap_xs();
276 1 return GraphQL::Houtou::XS::VM::load_native_bundle_from_handles_xs(
277 $self->_native_runtime_handle,
278 $program,
279 );
280 }
281  
282 2229 ▶sub _require_native_program {
Subroutine _require_native_program: called CC=3 SCAR=13.3
283 2229 my ($program) = @_;
284 return $program
285 2229 ▶ if ref($program) && eval { $program->isa('GraphQL::Houtou::Runtime::NativeProgram') };
Branch: 1 branch
BranchTrueFalseTotal
if ref $program and eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } } 2229 0 2229
Condition33%1/3
ref $program and eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
!ll&&!rl&&r
002229
MC/DC0%0/2
ref $program and eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
ref $program eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
Truth table33%1/3
A and B
A= ref $programB= eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
ABresult
0X0
100
111
286 0 die "Active runtime paths expect a GraphQL::Houtou::Runtime::NativeProgram.\n";
287 }
288  
289 27 ▶sub load_bundle_descriptor {
Subroutine load_bundle_descriptor: called CC=2 SCAR=7.0
Pod undocumented
290 27 my ($self, $descriptor) = @_;
291 GraphQL::Houtou::Runtime::OperationCompiler::assert_supported_operation_descriptor(
292 ref($descriptor) eq 'HASH' ? $descriptor->{program} : undef,
293 27 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
ref $descriptor eq 'HASH' ? : 27 0 27
294 25 GraphQL::Houtou::_bootstrap_xs();
295 25 return GraphQL::Houtou::XS::VM::load_native_bundle_xs($descriptor);
296 }
297  
298 2 ▶sub inflate_bundle_descriptor {
Subroutine inflate_bundle_descriptor: called CC=2 SCAR=7.1
Pod undocumented
299 2 my ($self, $descriptor) = @_;
300 GraphQL::Houtou::Runtime::OperationCompiler::assert_supported_operation_descriptor(
301 ref($descriptor) eq 'HASH' ? $descriptor->{program} : undef,
302 2 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
ref $descriptor eq 'HASH' ? : 2 0 2
303 1 return GraphQL::Houtou::Runtime::VMCompiler->inflate_native_bundle(
304 $self->runtime_schema,
305 $descriptor,
306 );
307 }
308  
309 1 ▶sub dump_bundle_descriptor {
Subroutine dump_bundle_descriptor: called CC=2 SCAR=7.0
Pod undocumented
310 1 my ($self, $program, $path, %opts) = @_;
311 1 my $descriptor = $self->compile_bundle_descriptor($program, %opts);
312 1 ▶ open my $fh, '>', $path or die "Cannot open $path for write: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "Cannot open $path for write: $!" 1 0 1
313 1 print {$fh} encode_json($descriptor);
314 1 close $fh;
315 1 return $descriptor;
316 }
317  
318 2 ▶sub dump_bundle_descriptor_for_document {
Subroutine dump_bundle_descriptor_for_document: called CC=2 SCAR=7.0
Pod undocumented
319 2 my ($self, $document, $path, %opts) = @_;
320 2 my $descriptor = $self->compile_bundle_descriptor_for_document($document, %opts);
321 2 ▶ open my $fh, '>', $path or die "Cannot open $path for write: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "Cannot open $path for write: $!" 2 0 2
322 2 print {$fh} encode_json($descriptor);
323 2 close $fh;
324 2 return $descriptor;
325 }
326  
327 2 ▶sub load_bundle_descriptor_file {
Subroutine load_bundle_descriptor_file: called CC=2 SCAR=7.0
Pod undocumented
328 2 my ($self, $path) = @_;
329 2 ▶ open my $fh, '<', $path or die "Cannot open $path for read: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or die "Cannot open $path for read: $!" 2 0 2
330 2 local $/;
331 2 my $json = <$fh>;
332 2 close $fh;
333 2 my $descriptor = decode_json($json);
334 2 return $self->load_bundle_descriptor($descriptor);
335 }
336  
337 2062 ▶sub execute_program {
Subroutine execute_program: called CC=20 SCAR=30.0
Pod documented
338 2062 my ($self, $program, %opts) = @_;
339 2062 my $native_program = _require_native_program($program);
340 2062 my $runtime_handle = $self->_native_runtime_handle;
341 2062 my $on_stall = delete $opts{on_stall};
342 2062 my $has_root_value = exists $opts{root_value};
343 2062 my $has_context_value = exists $opts{context};
344 2062 my $has_variables = exists $opts{variables};
345 2062 ▶ my $root_value = $has_root_value ? $opts{root_value} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has_root_value ? : 14 2048 2062
346 2062 ▶ my $context_value = $has_context_value ? $opts{context} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has_context_value ? : 1474 588 2062
347 2062 ▶ my $variables = $has_variables ? $opts{variables} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$has_variables ? : 1793 269 2062
348 2062 ▶ my $strict_sync = delete $opts{strict_sync} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $opts{'strict_sync'} ? : 15 2047 2062
349  
350 die "promise_code is no longer supported; Promise::XS is built in and custom backends use async_adapter.\n"
351 2062 ▶ if exists $opts{promise_code};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"promise_code"} 0 2062 2062
352  
353 2062 ▶ if ($on_stall && !$strict_sync) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_stall and not $strict_sync) 1490 572 2062
Condition100%3/3
$on_stall and not $strict_sync
!ll&&!rl&&r
57111490
MC/DC100%2/2
$on_stall and not $strict_sync
$on_stall not $strict_sync
Truth table100%3/3
A and not(B)
A= $on_stallB= not $strict_sync
ABresult
0X0
100
111
354 1490 ▶ require GraphQL::Houtou::Promise::PromiseXS if $self->_uses_promise_xs;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_uses_promise_xs 1490 0 1490
355 # Batching resolvers return promises, so the request must run on the
356 # async-capable lane regardless of variables. When the fast lane covers
357 # this shape (Phase 3-7's eligibility work), it drives on_stall itself
358 # in C and returns the finished envelope directly - no Promise::XS is
359 # ever created for the response (see gql_runtime_vm_drive_with_on_stall_sv).
360 # A shape the fast lane does not cover (runtime directives present, the
361 # nesting-depth guard exceeded, ...) falls back to the same
362 # Promise::XS-returning generic executor as before; _settle_result's own
363 # first line already short-circuits on a non-promise result, so calling
364 # it here is correct either way.
365 1490 my $result = GraphQL::Houtou::XS::VM::execute_native_program_auto_with_on_stall_xs(
366 $runtime_handle,
367 $native_program,
368 $root_value,
369 $context_value,
370 $variables,
371 $on_stall,
372 );
373 1479 return $self->_settle_result($result, $on_stall);
374 }
375 # Runtimes built with async => 1 declare that resolvers return promises
376 # (the DataLoader deployment shape); every request starts on the
377 # async-capable lane, exactly like the no-variables path. A strict
378 # synchronous request still wins.
379 572 ▶ if ($self->{_async} && !$strict_sync) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_async"} and not $strict_sync) 68 504 572
Condition100%3/3
$self->{"_async"} and not $strict_sync
!ll&&!rl&&r
502268
MC/DC100%2/2
$self->{"_async"} and not $strict_sync
$self->{"_async"} not $strict_sync
Truth table100%3/3
A and not(B)
A= $self->{"_async"}B= not $strict_sync
ABresult
0X0
100
111
380 68 ▶ require GraphQL::Houtou::Promise::PromiseXS if $self->_uses_promise_xs;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_uses_promise_xs 65 3 68
381 68 return GraphQL::Houtou::XS::VM::execute_native_program_auto_xs(
382 $runtime_handle,
383 $native_program,
384 $root_value,
385 $context_value,
386 $variables,
387 );
388 }
389 504 ▶ if ($strict_sync || $has_variables) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict_sync or $has_variables) 299 205 504
Condition100%3/3
$strict_sync or $has_variables
l!l&&r!l&&!r
15284205
MC/DC100%2/2
$strict_sync or $has_variables
$strict_sync $has_variables
Truth table100%3/3
A or B
A= $strict_syncB= $has_variables
ABresult
1X1
011
000
390 # Variable-invariant programs need no per-request clone. Keep variable
391 # coercion and execution inside one XSUB so the prepared variables HV
392 # does not make an otherwise redundant XS -> Perl -> XS round trip.
393 299 ▶ if (!GraphQL::Houtou::XS::VM::native_program_needs_variable_specialization_xs($native_program)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (GraphQL::Houtou::XS::VM::native_program_needs_variable_specialization_xs($native_program)) 296 3 299
394 296 ▶ return GraphQL::Houtou::XS::VM::execute_native_program_prepared_fast_xs(
Condition100%2/2
$variables || {}
l!l
28511
MC/DC100%1/1
$variables || {}
$variables
Truth table100%2/2
A
A= $variables
Aresult
11
00
395 $runtime_handle,
396 $native_program,
397 $root_value,
398 $context_value,
399 $variables || {},
400 );
401 }
402 3 ▶ my $prepared_variables = GraphQL::Houtou::Runtime::InputCoercion::prepare_variables(
Condition50%1/2
$variables || {}
l!l
30
MC/DC0%0/1
$variables || {}
$variables
Truth table50%1/2
A
A= $variables
Aresult
11
00
403 $self->runtime_schema,
404 $native_program,
405 $variables || {},
406 );
407 3 my $specialized = $self->_cached_specialized_program(
408 $native_program,
409 $prepared_variables,
410 );
411 3 return $self->execute_compact_program($specialized, %opts, variables => $prepared_variables);
412 }
413 205 ▶ if (!$has_root_value && !$has_context_value && !$has_variables) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_root_value or $has_context_value or $has_variables) 196 9 205
Condition83%5/6
$has_root_value or $has_context_value or $has_variables
l!l&&r!l&&!r
90196
$has_root_value or $has_context_value
l!l&&r!l&&!r
81196
MC/DC66%2/3
$has_root_value or $has_context_value or $has_variables
$has_root_value $has_context_value $has_variables
Truth table75%3/4
A or B or C
A= $has_root_valueB= $has_context_valueC= $has_variables
ABCresult
1XX1
01X1
0011
0000
414 196 return GraphQL::Houtou::XS::VM::execute_native_program_auto_simple_xs(
415 $runtime_handle,
416 $native_program,
417 );
418 }
419 9 return GraphQL::Houtou::XS::VM::execute_native_program_auto_xs(
420 $runtime_handle,
421 $native_program,
422 $root_value,
423 $context_value,
424 $variables,
425 );
426 }
427  
428 3 ▶sub execute_compact_program {
Subroutine execute_compact_program: called CC=1 SCAR=0.0
Pod undocumented
429 3 my ($self, $program, %opts) = @_;
430 3 my $native_program = _require_native_program($program);
431 return GraphQL::Houtou::XS::VM::execute_native_program_handle_xs(
432 $self->_native_runtime_handle,
433 $native_program,
434 $opts{root_value},
435 $opts{context},
436 $opts{variables},
437 3 );
438 }
439  
440 # Drive a possibly-pending async result to completion using the caller's
441 # on_stall callback. This is the core batching contract: execution runs
442 # until every field either completed or is waiting on a promise ("stall"),
443 # then on_stall is invoked and must make progress (return a true dispatch
444 # count) by resolving promises - typically by flushing data loaders. Each
445 # resolution runs its continuations synchronously, advancing the scheduler
446 # to the next stall. No progress while promises remain pending is reported
447 # as a deadlock.
448 1493 ▶sub _settle_result {
Subroutine _settle_result: called CC=10 SCAR=27.7
449 1493 my ($self, $result, $on_stall) = @_;
450 1493 ▶ return $result
Branch: 1 branch
BranchTrueFalseTotal
unless GraphQL::Houtou::XS::VM::runtime_value_is_async_xs($self->_native_runtime_handle, $result) 1487 6 1493
451 if !GraphQL::Houtou::XS::VM::runtime_value_is_async_xs(
452 $self->_native_runtime_handle, $result,
453 );
454  
455 6 my ($settled, $value) = (0, undef);
456 # Keep the derived chain alive until settlement; Future-style adapters may
457 # otherwise discard it before its callbacks run.
458 6 my $chain;
459 eval {
460 $chain = GraphQL::Houtou::XS::VM::runtime_then_async_xs(
461 $self->_native_runtime_handle,
462 $result,
463 5 ▶ sub { ($settled, $value) = (1, $_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
464 0 ▶ sub { ($settled, $value) = (-1, $_[0]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
465 6 );
466 6 1;
467 6 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $chain = GraphQL::Houtou::XS::VM::runtime_then_async_xs($self->_native_runtime_handle, $result, sub { ($settled, $value) = (1, $_[0]); } , sub { ($settled, $value) = (-1, $_[0]); } ); 1 } } or do { my $error = $@; GraphQL::Houtou::XS::VM::cancel_pending_response_xs($result); die $error } 6 0 6
468 0 my $error = $@;
469 0 GraphQL::Houtou::XS::VM::cancel_pending_response_xs($result);
470 0 die $error;
471 };
472 6 ▶ while (!$settled) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($settled) 6 5 11
473 6 my $progressed = $on_stall->();
474 6 ▶ if (!$settled && !$progressed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($settled or $progressed) 1 5 6
Condition66%2/3
$settled or $progressed
l!l&&r!l&&!r
501
MC/DC50%1/2
$settled or $progressed
$settled $progressed
Truth table66%2/3
A or B
A= $settledB= $progressed
ABresult
1X1
011
000
475 # The request is being abandoned while promises are pending; cancel
476 # it so the pending machinery (a reference cycle while armed) is
477 # torn down instead of leaking with the abandoned frames.
478 1 GraphQL::Houtou::XS::VM::cancel_pending_response_xs($result);
479 1 die "GraphQL execution stalled: promises are pending but on_stall made no progress"
480 . " (a resolver returned a promise that no registered loader will resolve)\n";
481 }
482 }
483 5 ▶ if ($settled < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settled < 0) 0 5 5
484 0 ▶ die $value if ref $value || ($value // '') ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value or ($value // "") ne "" 0 0 0
Condition0%0/5
ref $value or ($value // "") ne ""
l!l&&r!l&&!r
000
$value // ""
l!l
00
MC/DC0%0/2
ref $value or ($value // "") ne ""
ref $value $value
Truth table0%0/3
A or B
A= ref $valueB= $value
ABresult
1X1
011
000
485 0 die "GraphQL execution failed with an unknown async rejection\n";
486 }
487 5 return $value;
488 }
489  
490 3 ▶sub execute_bundle_descriptor {
Subroutine execute_bundle_descriptor: called CC=1 SCAR=0.0
Pod documented
491 3 my ($self, $descriptor, %opts) = @_;
492 3 my $bundle = $self->load_bundle_descriptor($descriptor);
493 2 return $self->execute_bundle($bundle, %opts);
494 }
495  
496 # Request-stage checks shared by execute_document and its JSON sibling:
497 # depth limit and full query validation. The depth check is skipped for
498 # documents already in the program cache; validation is skipped only for
499 # documents this runtime has actually validated before (a cache entry
500 # stored under validate => 0 proves nothing). Returns an arrayref of
501 # request errors, or undef when execution may proceed. Request errors
502 # produce an errors-only envelope (no "data" key), per the spec's
503 # request-error contract.
504 461 ▶sub _document_request_errors {
Subroutine _document_request_errors: called CC=42 SCAR=39.4
505 461 my ($self, $document, $max_depth, $max_nodes, $max_cost,
506 $default_list_size, $validate, $operation_name, $allow_introspection) = @_;
507 461 ▶ return undef if !defined $max_depth && !defined $max_nodes
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_depth || defined $max_nodes || defined $max_cost || $validate and $allow_introspection 0 461 461
Condition41%5/12
not defined $max_depth || defined $max_nodes || defined $max_cost || $validate and $allow_introspection
!ll&&!rl&&r
46100
defined $max_depth || defined $max_nodes || defined $max_cost || $validate
l!l&&r!l&&!r
46100
defined $max_depth or defined $max_nodes or defined $max_cost
l!l&&r!l&&!r
46100
defined $max_depth or defined $max_nodes
l!l&&r!l&&!r
46010
MC/DC0%0/5
not defined $max_depth || defined $max_nodes || defined $max_cost || $validate and $allow_introspection
defined $max_depth defined $max_nodes defined $max_cost $validate $allow_introspection
Truth table33%2/6
not(A or B or C || D) and E
A= defined $max_depthB= defined $max_nodesC= defined $max_costD= $validateE= $allow_introspection
ABCDEresult
1XXXX0
01XXX0
001XX0
0001X0
000000
000011
508 && !defined $max_cost && !$validate && $allow_introspection;
509  
510 461 my $is_string = !ref($document);
511 461 ▶ my $cache_key = $is_string
Branch: 1 branch
BranchTrueFalseTotal
$is_string ? : 460 1 461
512 ? _document_cache_key($document, $operation_name)
513 : undef;
514 461 ▶ my $already_validated = $is_string && $self->{_validated_documents}{$cache_key};
Condition100%3/3
$is_string && $self->{'_validated_documents'}{$cache_key}
!ll&&!rl&&r
14564
MC/DC100%2/2
$is_string && $self->{'_validated_documents'}{$cache_key}
$is_string $self->{'_validated_documents'}{$cache_key}
Truth table100%3/3
A && B
A= $is_stringB= $self->{'_validated_documents'}{$cache_key}
ABresult
0X0
100
111
515 my $already_limited = $is_string && $self->{_limit_signatures}{$cache_key}
516 461 ▶ && $self->{_limit_signatures}{$cache_key} eq _limit_signature(
Condition100%6/6
$is_string && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq _limit_signature($max_depth, $max_nodes, $max_cost, $default_list_size, $allow_introspection)
!ll&&!rl&&r
45731
$is_string and $self->{"_limit_signatures"}{$cache_key}
!ll&&!rl&&r
14564
MC/DC100%3/3
$is_string && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq _limit_signature($max_depth, $max_nodes, $max_cost, $default_list_size, $allow_introspection)
$is_string $self->{"_limit_signatures"}{$cache_key} $self->{'_limit_signatures'}{$cache_key} eq _limit_signature($max_depth, $max_nodes, $max_cost, $default_list_size, $allow_introspection)
Truth table100%4/4
A and B && C
A= $is_stringB= $self->{"_limit_signatures"}{$cache_key}C= $self->{'_limit_signatures'}{$cache_key} eq _limit_signature($max_depth, $max_nodes, $max_cost, $default_list_size, $allow_introspection)
ABCresult
0XX0
10X0
1100
1111
517 $max_depth, $max_nodes, $max_cost, $default_list_size,
518 $allow_introspection,
519 );
520 # Depth and node caps bound the untrusted document; skip them once the
521 # program is cached (a cached document already passed them once).
522 461 ▶ my $need_limits = (defined $max_depth || defined $max_nodes || defined $max_cost)
Condition55%5/9
(defined $max_depth || defined $max_nodes || defined $max_cost) && !$already_limited
!ll&&!rl&&r
01460
defined $max_depth or defined $max_nodes or defined $max_cost
l!l&&r!l&&!r
46100
defined $max_depth or defined $max_nodes
l!l&&r!l&&!r
46010
MC/DC25%1/4
(defined $max_depth || defined $max_nodes || defined $max_cost) && !$already_limited
defined $max_depth defined $max_nodes defined $max_cost !$already_limited
Truth table42%3/7
A or B or C && not(D)
A= defined $max_depthB= defined $max_nodesC= defined $max_costD= !$already_limited
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
523 && !$already_limited;
524 461 ▶ my $need_validate = $validate && !$already_validated;
Condition100%3/3
$validate && !$already_validated
!ll&&!rl&&r
164441
MC/DC100%2/2
$validate && !$already_validated
$validate !$already_validated
Truth table100%3/3
A && not(B)
A= $validateB= !$already_validated
ABresult
0X0
100
111
525 461 ▶ my $need_introspection_check = !$allow_introspection && !$already_limited;
Condition66%2/3
$allow_introspection || $already_limited
l!l&&r!l&&!r
45308
MC/DC50%1/2
$allow_introspection || $already_limited
$allow_introspection $already_limited
Truth table66%2/3
A || B
A= $allow_introspectionB= $already_limited
ABresult
1X1
011
000
526 461 ▶ return undef if !$need_limits && !$need_validate && !$need_introspection_check;
Branch: 1 branch
BranchTrueFalseTotal
unless $need_limits or $need_validate or $need_introspection_check 0 461 461
Condition50%3/6
$need_limits or $need_validate or $need_introspection_check
l!l&&r!l&&!r
46100
$need_limits or $need_validate
l!l&&r!l&&!r
46010
MC/DC0%0/3
$need_limits or $need_validate or $need_introspection_check
$need_limits $need_validate $need_introspection_check
Truth table50%2/4
A or B or C
A= $need_limitsB= $need_validateC= $need_introspection_check
ABCresult
1XX1
01X1
0011
0000
527  
528 461 ▶ my $ast = $is_string ? GraphQL::Houtou::parse($document) : $document;
Branch: 1 branch
BranchTrueFalseTotal
$is_string ? : 460 1 461
529 457 ▶ $ast = _select_operation_ast($ast, $operation_name) if defined $operation_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $operation_name 9 448 457
530 454 ▶ if ($need_introspection_check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_introspection_check) 8 446 454
531 8 my $errors = _introspection_errors($ast);
532 8 ▶ return $errors if @$errors;
Branch: 1 branch
BranchTrueFalseTotal
if @$errors 7 1 8
533 }
534 447 ▶ if ($need_limits && defined $max_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_limits and defined $max_depth) 445 2 447
Condition100%3/3
$need_limits and defined $max_depth
!ll&&!rl&&r
11445
MC/DC100%2/2
$need_limits and defined $max_depth
$need_limits defined $max_depth
Truth table100%3/3
A and B
A= $need_limitsB= defined $max_depth
ABresult
0X0
100
111
535 445 my @errors = GraphQL::Houtou::Validation::DepthLimit::check_query_depth(
536 $ast, max_depth => $max_depth,
537 );
538 445 ▶ return \@errors if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 3 442 445
539 }
540 444 ▶ if ($need_limits && defined $max_nodes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_limits and defined $max_nodes) 442 2 444
Condition100%3/3
$need_limits and defined $max_nodes
!ll&&!rl&&r
11442
MC/DC100%2/2
$need_limits and defined $max_nodes
$need_limits defined $max_nodes
Truth table100%3/3
A and B
A= $need_limitsB= defined $max_nodes
ABresult
0X0
100
111
541 442 my @errors = GraphQL::Houtou::Validation::NodeLimit::check_query_nodes(
542 $ast, max_nodes => $max_nodes,
543 );
544 442 ▶ return \@errors if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 1 441 442
545 }
546 443 ▶ if ($need_limits && defined $max_cost) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_limits and defined $max_cost) 442 1 443
Condition66%2/3
$need_limits and defined $max_cost
!ll&&!rl&&r
10442
MC/DC50%1/2
$need_limits and defined $max_cost
$need_limits defined $max_cost
Truth table66%2/3
A and B
A= $need_limitsB= defined $max_cost
ABresult
0X0
100
111
547 442 ▶ my $schema = $self->runtime_schema->can('schema')
Branch: 1 branch
BranchTrueFalseTotal
$self->runtime_schema->can('schema') ? : 442 0 442
548 ? $self->runtime_schema->schema : undef;
549 442 ▶ if ($schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema) 442 0 442
550 442 require GraphQL::Houtou::Validation;
551 442 ▶ my $errors = GraphQL::Houtou::Validation::check_query_cost(
Branch: 1 branch
BranchTrueFalseTotal
defined $operation_name ? : 6 436 442
552 $schema, $ast,
553 max_cost => $max_cost,
554 default_list_size => $default_list_size,
555 (defined $operation_name ? (operation_name => $operation_name) : ()),
556 );
557 442 ▶ return $errors if $errors && @$errors;
Branch: 1 branch
BranchTrueFalseTotal
if $errors and @$errors 2 440 442
Condition66%2/3
$errors and @$errors
!ll&&!rl&&r
04402
MC/DC50%1/2
$errors and @$errors
$errors @$errors
Truth table66%2/3
A and B
A= $errorsB= @$errors
ABresult
0X0
100
111
558 }
559 }
560 441 ▶ if ($need_validate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_validate) 427 14 441
561 # Validation needs the schema's type objects; a runtime inflated from
562 # a descriptor (persisted deployments) has none, and its documents
563 # were validated when the descriptor was built.
564 427 ▶ my $schema = $self->runtime_schema->can('schema') ? $self->runtime_schema->schema : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->runtime_schema->can('schema') ? : 427 0 427
565 427 ▶ if ($schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema) 427 0 427
566 427 require GraphQL::Houtou::Validation;
567 427 my $errors = GraphQL::Houtou::Validation::validate($schema, $ast);
568 427 ▶ return $errors if $errors && @$errors;
Branch: 1 branch
BranchTrueFalseTotal
if $errors and @$errors 66 361 427
Condition66%2/3
$errors and @$errors
!ll&&!rl&&r
036166
MC/DC50%1/2
$errors and @$errors
$errors @$errors
Truth table66%2/3
A and B
A= $errorsB= @$errors
ABresult
0X0
100
111
569 # Only remember validated documents that the program cache can also
570 # hold, so the set stays bounded by the cache's eviction.
571 $self->{_validated_documents}{$cache_key} = 1
572 361 ▶ if $is_string && $self->{_program_cache_max};
Branch: 1 branch
BranchTrueFalseTotal
if $is_string and $self->{"_program_cache_max"} 359 2 361
Condition100%3/3
$is_string and $self->{"_program_cache_max"}
!ll&&!rl&&r
11359
MC/DC100%2/2
$is_string and $self->{"_program_cache_max"}
$is_string $self->{"_program_cache_max"}
Truth table100%3/3
A and B
A= $is_stringB= $self->{"_program_cache_max"}
ABresult
0X0
100
111
573 }
574 }
575 375 return undef;
576 }
577  
578 # Convert a caught exception into GraphQL error entries for an errors-only
579 # envelope. Houtou error objects keep their locations/extensions; the
580 # parser's graphql-perl-style message is reduced to a spec-style syntax
581 # error line (the parse() API keeps raising the full legacy format).
582 36 ▶sub _request_error_entries {
Subroutine _request_error_entries: called CC=5 SCAR=16.2
583 36 my ($error) = @_;
584 36 ▶ if (blessed($error) && $error->isa('GraphQL::Houtou::Error')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($error) and $error->isa("GraphQL::Houtou::Error")) 33 3 36
Condition66%2/3
builtin::blessed($error) and $error->isa("GraphQL::Houtou::Error")
!ll&&!rl&&r
3033
MC/DC50%1/2
builtin::blessed($error) and $error->isa("GraphQL::Houtou::Error")
builtin::blessed($error) $error->isa("GraphQL::Houtou::Error")
Truth table66%2/3
A and B
A= builtin::blessed($error)B= $error->isa("GraphQL::Houtou::Error")
ABresult
0X0
100
111
585 33 my $entry = $error->to_json;
586 33 ▶ if (($entry->{message} // '') =~ /\AError parsing Pegex document:\s*\n\s*msg:\s*(.+?)\s*\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if (($entry->{"message"} // "") =~ /\AError parsing Pegex document:\s*\n\s*msg:\s*(.+?)\s*\n/u) 4 29 33
Condition50%1/2
$entry->{"message"} // ""
l!l
330
MC/DC0%0/1
$entry->{"message"} // ""
$entry->{"message"}
Truth table50%1/2
A
A= $entry->{"message"}
Aresult
11
00
587 4 $entry->{message} = "Syntax Error: $1";
588 }
589 33 return [ $entry ];
590 }
591 3 my $message = "$error";
592 3 $message =~ s/\s+\z//;
593 3 return [ { message => $message } ];
594 }
595  
596 # True for exceptions that represent GraphQL request errors (client-caused:
597 # syntax, validation, input coercion). Anything else - configuration or
598 # internal errors - must keep propagating as an exception.
599 56 ▶sub _is_request_error {
Subroutine _is_request_error: called CC=2 SCAR=7.1
600 56 my ($error) = @_;
601 56 ▶ return blessed($error) && $error->isa('GraphQL::Houtou::Error');
Condition66%2/3
builtin::blessed($error) && $error->isa('GraphQL::Houtou::Error')
!ll&&!rl&&r
32024
MC/DC50%1/2
builtin::blessed($error) && $error->isa('GraphQL::Houtou::Error')
builtin::blessed($error) $error->isa('GraphQL::Houtou::Error')
Truth table66%2/3
A && B
A= builtin::blessed($error)B= $error->isa('GraphQL::Houtou::Error')
ABresult
0X0
100
111
602 }
603  
604 2126 ▶sub execute_document {
Subroutine execute_document: called CC=27 SCAR=33.0
Pod documented
605 2126 my ($self, $document, %opts) = @_;
606 2126 ▶ my $max_depth = exists $opts{max_depth} ? delete $opts{max_depth} : $self->{_max_depth};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_depth'} ? : 4 2122 2126
607 2126 ▶ my $max_nodes = exists $opts{max_nodes} ? delete $opts{max_nodes} : $self->{_max_nodes};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_nodes'} ? : 1 2125 2126
608 2126 ▶ my $max_cost = exists $opts{max_cost} ? delete $opts{max_cost} : $self->{_max_cost};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_cost'} ? : 2 2124 2126
609 my $default_list_size = exists $opts{default_list_size}
610 2126 ▶ ? delete $opts{default_list_size} : $self->{_default_list_size};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'default_list_size'} ? : 0 2126 2126
611 2126 ▶ my $validate = exists $opts{validate} ? delete $opts{validate} : $self->{_validate};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'validate'} ? : 4 2122 2126
612 my $allow_introspection = exists $opts{allow_introspection}
613 ? (delete $opts{allow_introspection} ? 1 : 0)
614 2126 ▶ : $self->{_allow_introspection};
Branch: 2 branches
BranchTrueFalseTotal
exists $opts{'allow_introspection'} ? : 3 2123 2126
delete $opts{'allow_introspection'} ? : 1 2 3
615 2126 my $operation_name = delete $opts{operation_name};
616  
617 # Hot path: a cached program whose document this runtime already
618 # validated skips the request stage entirely (depth was checked before
619 # it entered the cache, validation is recorded per document). Requests
620 # naming an operationName cache under a (document, operationName) key.
621 2126 ▶ my $cache_key = !ref($document)
Branch: 1 branch
BranchTrueFalseTotal
!ref($document) ? : 2125 1 2126
622 ? _document_cache_key($document, $operation_name)
623 : undef;
624 my $cached = defined $cache_key && $self->{_program_cache_max}
625 2126 ▶ ? $self->{_program_cache}{$cache_key}
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_key && $self->{'_program_cache_max'} ? : 2122 4 2126
Condition100%3/3
defined $cache_key and $self->{"_program_cache_max"}
!ll&&!rl&&r
132122
MC/DC100%2/2
defined $cache_key and $self->{"_program_cache_max"}
defined $cache_key $self->{"_program_cache_max"}
Truth table100%3/3
A and B
A= defined $cache_keyB= $self->{"_program_cache_max"}
ABresult
0X0
100
111
626 : undef;
627 2126 my $limit_signature = _limit_signature(
628 $max_depth, $max_nodes, $max_cost, $default_list_size,
629 $allow_introspection,
630 );
631 my $limits_ok = $cached && $self->{_limit_signatures}{$cache_key}
632 2126 ▶ && $self->{_limit_signatures}{$cache_key} eq $limit_signature;
Condition100%6/6
$cached && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
!ll&&!rl&&r
40331720
$cached and $self->{"_limit_signatures"}{$cache_key}
!ll&&!rl&&r
390131723
MC/DC100%3/3
$cached && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
$cached $self->{"_limit_signatures"}{$cache_key} $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
Truth table100%4/4
A and B && C
A= $cachedB= $self->{"_limit_signatures"}{$cache_key}C= $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
ABCresult
0XX0
10X0
1100
1111
633 2126 ▶ if ($cached && $limits_ok
Branch: 1 branch
BranchTrueFalseTotal
if ($cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}) 1719 407 2126
Condition100%9/9
$cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}
!ll&&!rl&&r
40611719
$cached and $limits_ok
!ll&&!rl&&r
390161720
not $validate or $self->{"_validated_documents"}{$cache_key}
l!l&&r!l&&!r
517141
MC/DC100%4/4
$cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}
$cached $limits_ok not $validate $self->{"_validated_documents"}{$cache_key}
Truth table100%5/5
A and B and not(C) or D
A= $cachedB= $limits_okC= not $validateD= $self->{"_validated_documents"}{$cache_key}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
634 && (!$validate || $self->{_validated_documents}{$cache_key})) {
635 1719 my $result = eval { $self->execute_program($cached, %opts) };
636 1719 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 19 1700 1719
637 19 ▶ die $error if !_is_request_error($error);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_request_error($error) 5 14 19
638 14 return { errors => _request_error_entries($error) };
639 }
640 1700 return $result;
641 }
642  
643 # Cold path. The taxonomy: parse/validation/compile failures are
644 # document-caused and always envelope; execution failures envelope only
645 # when they are GraphQL request errors (variable coercion raises
646 # GraphQL::Houtou::Error) - async misconfiguration, scheduler deadlock,
647 # and internal bugs keep propagating.
648 407 my $executing = 0;
649 407 my ($result, $request_errors);
650 407 my $ok = eval {
651 407 $request_errors = $self->_document_request_errors(
652 $document, $max_depth, $max_nodes, $max_cost,
653 $default_list_size, $validate, $operation_name, $allow_introspection);
654 404 ▶ if (!$request_errors) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request_errors) 328 76 404
655 328 ▶ my $program = $self->compile_program($document, %opts,
Branch: 1 branch
BranchTrueFalseTotal
defined $operation_name ? : 4 324 328
656 (defined $operation_name ? (operation_name => $operation_name) : ()));
657 $self->{_limit_signatures}{$cache_key} = $limit_signature
658 325 ▶ if defined $cache_key && $self->{_program_cache}{$cache_key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache_key and $self->{"_program_cache"}{$cache_key} 322 3 325
Condition100%3/3
defined $cache_key and $self->{"_program_cache"}{$cache_key}
!ll&&!rl&&r
12322
MC/DC100%2/2
defined $cache_key and $self->{"_program_cache"}{$cache_key}
defined $cache_key $self->{"_program_cache"}{$cache_key}
Truth table100%3/3
A and B
A= defined $cache_keyB= $self->{"_program_cache"}{$cache_key}
ABresult
0X0
100
111
659 325 $executing = 1;
660 325 $result = $self->execute_program($program, %opts);
661 }
662 378 1;
663 };
664 407 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 29 378 407
665 29 my $error = $@;
666 29 ▶ die $error if $executing && !_is_request_error($error);
Branch: 1 branch
BranchTrueFalseTotal
if $executing and not _is_request_error($error) 15 14 29
Condition100%3/3
$executing and not _is_request_error($error)
!ll&&!rl&&r
6815
MC/DC100%2/2
$executing and not _is_request_error($error)
$executing not _is_request_error($error)
Truth table100%3/3
A and not(B)
A= $executingB= not _is_request_error($error)
ABresult
0X0
100
111
667 14 return { errors => _request_error_entries($error) };
668 }
669 378 ▶ return { errors => $request_errors } if $request_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $request_errors 76 302 378
670 302 return $result;
671 }
672  
673 27 ▶sub execute_bundle {
Subroutine execute_bundle: called CC=1 SCAR=0.0
Pod documented
674 27 my ($self, $bundle, %opts) = @_;
675 return GraphQL::Houtou::XS::VM::execute_native_bundle_xs(
676 $self->_native_runtime_handle,
677 $bundle,
678 $opts{root_value},
679 $opts{context},
680 $opts{variables},
681 27 );
682 }
683  
684 # Direct-JSON siblings of the sync native lane: the response is rendered as
685 # UTF-8 JSON bytes in XS without materializing the Perl envelope. Without
686 # on_stall the lane is sync-only and resolvers returning supported promises
687 # croak; with on_stall the request runs on the async lane and the
688 # response frame serializes its native value tree straight to JSON when it
689 # resolves (see execute_program_to_json).
690  
691 18 ▶sub execute_bundle_to_json {
Subroutine execute_bundle_to_json: called CC=1 SCAR=0.0
Pod documented
692 18 my ($self, $bundle, %opts) = @_;
693 return GraphQL::Houtou::XS::VM::execute_native_bundle_to_json_xs(
694 $self->_native_runtime_handle,
695 $bundle,
696 $opts{root_value},
697 $opts{context},
698 $opts{variables},
699 18 );
700 }
701  
702 88 ▶sub execute_program_to_json {
Subroutine execute_program_to_json: called CC=10 SCAR=24.2
Pod documented
703 88 my ($self, $program, %opts) = @_;
704 88 my $native_program = _require_native_program($program);
705 88 my $on_stall = delete $opts{on_stall};
706 88 ▶ my $strict_sync = delete $opts{strict_sync} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $opts{'strict_sync'} ? : 1 87 88
707 88 ▶ if ($on_stall && !$strict_sync) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_stall and not $strict_sync) 14 74 88
Condition66%2/3
$on_stall and not $strict_sync
!ll&&!rl&&r
74014
MC/DC50%1/2
$on_stall and not $strict_sync
$on_stall not $strict_sync
Truth table66%2/3
A and not(B)
A= $on_stallB= not $strict_sync
ABresult
0X0
100
111
708 # Batching resolvers return promises, so run on the async lane; the
709 # response frame renders JSON directly from its native value tree at
710 # resolve time (query field order preserved). The auto lane prepares
711 # program variables itself.
712 14 ▶ require GraphQL::Houtou::Promise::PromiseXS if $self->_uses_promise_xs;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_uses_promise_xs 14 0 14
713 my $result = GraphQL::Houtou::XS::VM::execute_native_program_auto_to_json_xs(
714 $self->_native_runtime_handle,
715 $native_program,
716 $opts{root_value},
717 $opts{context},
718 $opts{variables},
719 14 );
720 14 return $self->_settle_result($result, $on_stall);
721 }
722 74 ▶ if ($self->{_async} && !$strict_sync) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_async"} and not $strict_sync) 11 63 74
Condition100%3/3
$self->{"_async"} and not $strict_sync
!ll&&!rl&&r
62111
MC/DC100%2/2
$self->{"_async"} and not $strict_sync
$self->{"_async"} not $strict_sync
Truth table100%3/3
A and not(B)
A= $self->{"_async"}B= not $strict_sync
ABresult
0X0
100
111
723 11 return $self->_auto_json_or_die($native_program, %opts);
724 }
725 63 ▶ if (!GraphQL::Houtou::XS::VM::native_program_needs_variable_specialization_xs($native_program)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (GraphQL::Houtou::XS::VM::native_program_needs_variable_specialization_xs($native_program)) 63 0 63
726 return GraphQL::Houtou::XS::VM::execute_native_program_prepared_fast_to_json_xs(
727 $self->_native_runtime_handle,
728 $native_program,
729 $opts{root_value},
730 $opts{context},
731 $opts{variables} || {},
732 63 ▶ );
Condition100%2/2
$opts{'variables'} || {}
l!l
2439
MC/DC100%1/1
$opts{'variables'} || {}
$opts{'variables'}
Truth table100%2/2
A
A= $opts{'variables'}
Aresult
11
00
733 }
734 my $prepared_variables = GraphQL::Houtou::Runtime::InputCoercion::prepare_variables(
735 $self->runtime_schema,
736 $native_program,
737 $opts{variables} || {},
738 0 ▶ );
Condition0%0/2
$opts{'variables'} || {}
l!l
00
MC/DC0%0/1
$opts{'variables'} || {}
$opts{'variables'}
Truth table0%0/2
A
A= $opts{'variables'}
Aresult
11
00
739 0 my $effective_program = $self->_cached_specialized_program(
740 $native_program,
741 $prepared_variables,
742 );
743 return GraphQL::Houtou::XS::VM::execute_native_program_to_json_xs(
744 $self->_native_runtime_handle,
745 $effective_program,
746 $opts{root_value},
747 $opts{context},
748 0 $prepared_variables,
749 );
750 }
751  
752 # Async JSON lane without an on_stall hook: promises that resolve during
753 # execution (pre-resolved chains) complete synchronously and yield JSON; a
754 # genuine stall has nothing to flush it, so fail with a pointer to on_stall
755 # rather than handing a promise to a caller that expected bytes.
756 11 ▶sub _auto_json_or_die {
Subroutine _auto_json_or_die: called CC=8 SCAR=22.6
757 11 my ($self, $native_program, %opts) = @_;
758 11 ▶ require GraphQL::Houtou::Promise::PromiseXS if $self->_uses_promise_xs;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_uses_promise_xs 11 0 11
759 my $result = GraphQL::Houtou::XS::VM::execute_native_program_auto_to_json_xs(
760 $self->_native_runtime_handle,
761 $native_program,
762 $opts{root_value},
763 $opts{context},
764 $opts{variables},
765 11 );
766 11 ▶ if ($self->_uses_promise_xs
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_uses_promise_xs and builtin::blessed($result) and $result->isa("Promise::XS::Promise")) 3 8 11
Condition66%4/6
$self->_uses_promise_xs and builtin::blessed($result) and $result->isa("Promise::XS::Promise")
!ll&&!rl&&r
803
$self->_uses_promise_xs and builtin::blessed($result)
!ll&&!rl&&r
083
MC/DC33%1/3
$self->_uses_promise_xs and builtin::blessed($result) and $result->isa("Promise::XS::Promise")
$self->_uses_promise_xs builtin::blessed($result) $result->isa("Promise::XS::Promise")
Truth table50%2/4
A and B and C
A= $self->_uses_promise_xsB= builtin::blessed($result)C= $result->isa("Promise::XS::Promise")
ABCresult
0XX0
10X0
1100
1111
767 && blessed($result) && $result->isa('Promise::XS::Promise')) {
768 # Pre-resolved promise chains settle during execution, so the response
769 # promise may already hold the JSON; only a genuine stall is an error.
770 3 my $settled = eval {
771 3 GraphQL::Houtou::Promise::PromiseXS::maybe_get_promise_xs($result);
772 };
773 3 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 3 0 3
774 # A rejected response promise carries a real request error; only the
775 # still-pending case earns the on_stall hint. The pending request is
776 # abandoned here, so cancel it (see _settle_result).
777 3 ▶ die $err if $err !~ /did not resolve synchronously/;
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /did not resolve synchronously/u 0 3 3
778 3 GraphQL::Houtou::XS::VM::cancel_pending_response_xs($result);
779 3 die "resolvers returned pending promises; pass on_stall (see GraphQL::Houtou::DataLoader)"
780 . " so execute_document_to_json can drive them to completion\n";
781 }
782 0 return $settled;
783 }
784 8 ▶ if (GraphQL::Houtou::XS::VM::runtime_value_is_async_xs(
Branch: 1 branch
BranchTrueFalseTotal
if (GraphQL::Houtou::XS::VM::runtime_value_is_async_xs($self->_native_runtime_handle, $result)) 0 8 8
785 $self->_native_runtime_handle, $result,
786 )) {
787 0 GraphQL::Houtou::XS::VM::cancel_pending_response_xs($result);
788 0 die "resolvers returned pending promises; pass on_stall (see GraphQL::Houtou::DataLoader)"
789 . " so execute_document_to_json can drive them to completion\n";
790 }
791 8 return $result;
792 }
793  
794 11 ▶sub _request_errors_json {
Subroutine _request_errors_json: called CC=1 SCAR=0.0
795 11 my ($errors) = @_;
796 11 require JSON::MaybeXS;
797 11 return JSON::MaybeXS->new->utf8->canonical->encode({ errors => $errors });
798 }
799  
800 97 ▶sub execute_document_to_json {
Subroutine execute_document_to_json: called CC=27 SCAR=34.9
Pod documented
801 97 my ($self, $document, %opts) = @_;
802 97 ▶ my $max_depth = exists $opts{max_depth} ? delete $opts{max_depth} : $self->{_max_depth};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_depth'} ? : 0 97 97
803 97 ▶ my $max_nodes = exists $opts{max_nodes} ? delete $opts{max_nodes} : $self->{_max_nodes};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_nodes'} ? : 0 97 97
804 97 ▶ my $max_cost = exists $opts{max_cost} ? delete $opts{max_cost} : $self->{_max_cost};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'max_cost'} ? : 0 97 97
805 my $default_list_size = exists $opts{default_list_size}
806 97 ▶ ? delete $opts{default_list_size} : $self->{_default_list_size};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'default_list_size'} ? : 0 97 97
807 97 ▶ my $validate = exists $opts{validate} ? delete $opts{validate} : $self->{_validate};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'validate'} ? : 0 97 97
808 my $allow_introspection = exists $opts{allow_introspection}
809 ? (delete $opts{allow_introspection} ? 1 : 0)
810 97 ▶ : $self->{_allow_introspection};
Branch: 2 branches
BranchTrueFalseTotal
exists $opts{'allow_introspection'} ? : 1 96 97
delete $opts{'allow_introspection'} ? : 0 1 1
811 97 my $operation_name = delete $opts{operation_name};
812  
813 # Same hot/cold structure and error taxonomy as execute_document.
814 97 ▶ my $cache_key = !ref($document)
Branch: 1 branch
BranchTrueFalseTotal
!ref($document) ? : 97 0 97
815 ? _document_cache_key($document, $operation_name)
816 : undef;
817 my $cached = defined $cache_key && $self->{_program_cache_max}
818 97 ▶ ? $self->{_program_cache}{$cache_key}
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_key && $self->{'_program_cache_max'} ? : 97 0 97
Condition33%1/3
defined $cache_key and $self->{"_program_cache_max"}
!ll&&!rl&&r
0097
MC/DC0%0/2
defined $cache_key and $self->{"_program_cache_max"}
defined $cache_key $self->{"_program_cache_max"}
Truth table33%1/3
A and B
A= defined $cache_keyB= $self->{"_program_cache_max"}
ABresult
0X0
100
111
819 : undef;
820 97 my $limit_signature = _limit_signature(
821 $max_depth, $max_nodes, $max_cost, $default_list_size,
822 $allow_introspection,
823 );
824 my $limits_ok = $cached && $self->{_limit_signatures}{$cache_key}
825 97 ▶ && $self->{_limit_signatures}{$cache_key} eq $limit_signature;
Condition66%4/6
$cached && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
!ll&&!rl&&r
54043
$cached and $self->{"_limit_signatures"}{$cache_key}
!ll&&!rl&&r
54043
MC/DC33%1/3
$cached && $self->{'_limit_signatures'}{$cache_key} && $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
$cached $self->{"_limit_signatures"}{$cache_key} $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
Truth table50%2/4
A and B && C
A= $cachedB= $self->{"_limit_signatures"}{$cache_key}C= $self->{'_limit_signatures'}{$cache_key} eq $limit_signature
ABCresult
0XX0
10X0
1100
1111
826 97 ▶ if ($cached && $limits_ok
Branch: 1 branch
BranchTrueFalseTotal
if ($cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}) 43 54 97
Condition55%5/9
$cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}
!ll&&!rl&&r
54043
$cached and $limits_ok
!ll&&!rl&&r
54043
not $validate or $self->{"_validated_documents"}{$cache_key}
l!l&&r!l&&!r
0430
MC/DC25%1/4
$cached and $limits_ok and !$validate || $self->{"_validated_documents"}{$cache_key}
$cached $limits_ok not $validate $self->{"_validated_documents"}{$cache_key}
Truth table40%2/5
A and B and not(C) or D
A= $cachedB= $limits_okC= not $validateD= $self->{"_validated_documents"}{$cache_key}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
827 && (!$validate || $self->{_validated_documents}{$cache_key})) {
828 43 my $result = eval { $self->execute_program_to_json($cached, %opts) };
829 43 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 6 37 43
830 6 ▶ die $error if !_is_request_error($error);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_request_error($error) 5 1 6
831 1 return _request_errors_json(_request_error_entries($error));
832 }
833 37 return $result;
834 }
835  
836 54 my $executing = 0;
837 54 my ($result, $request_errors);
838 54 my $ok = eval {
839 54 $request_errors = $self->_document_request_errors(
840 $document, $max_depth, $max_nodes, $max_cost,
841 $default_list_size, $validate, $operation_name, $allow_introspection);
842 50 ▶ if (!$request_errors) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request_errors) 47 3 50
843 47 ▶ my $program = $self->compile_program($document, %opts,
Branch: 1 branch
BranchTrueFalseTotal
defined $operation_name ? : 2 45 47
844 (defined $operation_name ? (operation_name => $operation_name) : ()));
845 $self->{_limit_signatures}{$cache_key} = $limit_signature
846 45 ▶ if defined $cache_key && $self->{_program_cache}{$cache_key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache_key and $self->{"_program_cache"}{$cache_key} 45 0 45
Condition33%1/3
defined $cache_key and $self->{"_program_cache"}{$cache_key}
!ll&&!rl&&r
0045
MC/DC0%0/2
defined $cache_key and $self->{"_program_cache"}{$cache_key}
defined $cache_key $self->{"_program_cache"}{$cache_key}
Truth table33%1/3
A and B
A= defined $cache_keyB= $self->{"_program_cache"}{$cache_key}
ABresult
0X0
100
111
847 45 $executing = 1;
848 45 $result = $self->execute_program_to_json($program, %opts);
849 }
850 40 1;
851 };
852 54 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 14 40 54
853 14 my $error = $@;
854 14 ▶ die $error if $executing && !_is_request_error($error);
Branch: 1 branch
BranchTrueFalseTotal
if $executing and not _is_request_error($error) 7 7 14
Condition100%3/3
$executing and not _is_request_error($error)
!ll&&!rl&&r
617
MC/DC100%2/2
$executing and not _is_request_error($error)
$executing not _is_request_error($error)
Truth table100%3/3
A and not(B)
A= $executingB= not _is_request_error($error)
ABresult
0X0
100
111
855 7 return _request_errors_json(_request_error_entries($error));
856 }
857 40 ▶ return _request_errors_json($request_errors) if $request_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $request_errors 3 37 40
858 37 return $result;
859 }
860  
861 3 ▶sub _cached_specialized_program {
Subroutine _cached_specialized_program: called CC=6 SCAR=20.3
862 3 my ($self, $native_program, $variables) = @_;
863 3 ▶ return $native_program if !$variables || !keys %$variables;
Branch: 1 branch
BranchTrueFalseTotal
unless $variables and keys %$variables 0 3 3
Condition33%1/3
$variables and keys %$variables
!ll&&!rl&&r
003
MC/DC0%0/2
$variables and keys %$variables
$variables keys %$variables
Truth table33%1/3
A and B
A= $variablesB= keys %$variables
ABresult
0X0
100
111
864  
865 3 my $variables_key = _specialized_variables_cache_key($variables);
866 3 ▶ if (length($variables_key) > 2048) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $variables_key > 2048) 0 3 3
867 # Unbounded variable payloads would otherwise become unbounded cache
868 # keys; specialize without caching instead.
869 0 return $self->_specialize_program_descriptor($native_program, $variables);
870 }
871 3 my $key = join q(|), refaddr($native_program), $variables_key;
872  
873 3 ▶ if (my $cached = $self->{_specialized_program_cache}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cached = $self->{"_specialized_program_cache"}{$key}) 0 3 3
874 0 return $cached;
875 }
876  
877 3 my $specialized = $self->_specialize_program_descriptor($native_program, $variables);
878 3 my $cache = $self->{_specialized_program_cache};
879 3 my $order = $self->{_specialized_program_cache_order};
880 3 ▶ if (scalar(@$order) >= $self->{_specialized_program_cache_max}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$order >= $self->{"_specialized_program_cache_max"}) 0 3 3
881 0 my $evicted = shift @$order;
882 0 delete $cache->{$evicted};
883 }
884 3 $cache->{$key} = $specialized;
885 3 push @$order, $key;
886 3 return $specialized;
887 }
888  
889 6 ▶sub _specialized_variables_cache_key {
Subroutine _specialized_variables_cache_key: called CC=7 SCAR=22.3
890 6 my ($value) = @_;
891 6 my $ref = ref($value);
892 6 ▶ return 'u' if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 6 6
893 6 ▶ return $value ? 'b1' : 'b0' if is_bool($value);
Branch: 2 branches
BranchTrueFalseTotal
if is_bool($value) 0 6 6
$value ? : 0 0 0
894 6 ▶ return 's:' . $value if !$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 3 3 6
895 3 ▶ if ($ref eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "ARRAY") 0 3 3
896 0 return 'a:[' . join(',', map { _specialized_variables_cache_key($_) } @$value) . ']';
897 }
898 3 ▶ if ($ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "HASH") 3 0 3
899 return 'h:{' . join(',', map {
900 3 my $k = $_;
901 3 $k . '=>' . _specialized_variables_cache_key($value->{$k})
902 } sort keys %$value) . '}';
903 }
904 0 return $ref . ':' . "$value";
905 }
906  
907 41 ▶sub _specialize_runtime_directives_payloads {
Subroutine _specialize_runtime_directives_payloads: called CC=10 SCAR=27.3
908 41 my ($descriptor, $variables) = @_;
909 41 ▶ return $descriptor if !$descriptor;
Branch: 1 branch
BranchTrueFalseTotal
unless $descriptor 0 41 41
910  
911 41 ▶ if (ref($descriptor) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $descriptor eq "HASH") 41 0 41
912 41 ▶ my $blocks = $descriptor->{blocks_compact} || $descriptor->{blocks} || [];
Condition40%2/5
$descriptor->{'blocks_compact'} || $descriptor->{'blocks'} || []
l!l
410
$descriptor->{"blocks_compact"} or $descriptor->{"blocks"}
l!l&&r!l&&!r
4100
MC/DC0%0/2
$descriptor->{'blocks_compact'} || $descriptor->{'blocks'} || []
$descriptor->{"blocks_compact"} $descriptor->{"blocks"}
Truth table33%1/3
A or B
A= $descriptor->{"blocks_compact"}B= $descriptor->{"blocks"}
ABresult
1X1
011
000
913 41 for my $block (@$blocks) {
914 75 ▶ my $ops = ref($block) eq 'ARRAY' ? ($block->[4] || []) : ($block->{ops} || []);
Branch: 1 branch
BranchTrueFalseTotal
ref $block eq 'ARRAY' ? : 75 0 75
Condition25%1/4
$block->[4] or []
l!l
750
$block->{"ops"} or []
l!l
00
MC/DC0%0/1
$block->[4] or []
$block->[4]
MC/DC0%0/1
$block->{"ops"} or []
$block->{"ops"}
Truth table50%1/2
A
A= $block->[4]
Aresult
11
00
Truth table0%0/2
A
A= $block->{"ops"}
Aresult
11
00
915 75 for my $op (@$ops) {
916 114 _specialize_runtime_directives_op($op, $variables);
917 }
918 }
919 }
920  
921 41 return $descriptor;
922 }
923  
924 114 ▶sub _specialize_runtime_directives_op {
Subroutine _specialize_runtime_directives_op: called CC=12 SCAR=35.3
925 114 my ($op, $variables) = @_;
926 114 ▶ return if !$op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 114 114
927  
928 114 ▶ if (ref($op) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $op eq "ARRAY") 114 0 114
929 114 ▶ my $mode_code = $op->[18] || 0;
Condition100%2/2
$op->[18] || 0
l!l
4110
MC/DC100%1/1
$op->[18] || 0
$op->[18]
Truth table100%2/2
A
A= $op->[18]
Aresult
11
00
930 114 ▶ return if !$mode_code || !$op->[20];
Branch: 1 branch
BranchTrueFalseTotal
unless $mode_code and $op->[20] 110 4 114
Condition66%2/3
$mode_code and $op->[20]
!ll&&!rl&&r
11004
MC/DC50%1/2
$mode_code and $op->[20]
$mode_code $op->[20]
Truth table66%2/3
A and B
A= $mode_codeB= $op->[20]
ABresult
0X0
100
111
931 4 my $payload = GraphQL::Houtou::Runtime::DirectiveRuntime::materialize_runtime_directives(
932 $op->[19],
933 $variables,
934 );
935 4 $op->[18] = 1;
936 4 $op->[19] = $payload;
937 4 ▶ $op->[20] = @$payload ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$payload ? : 4 0 4
938 4 return;
939 }
940  
941 0 ▶ return if ref($op) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $op ne "HASH" 0 0 0
942 0 ▶ my $mode_code = $op->{runtime_directives_mode_code} || 0;
Condition0%0/2
$op->{'runtime_directives_mode_code'} || 0
l!l
00
MC/DC0%0/1
$op->{'runtime_directives_mode_code'} || 0
$op->{'runtime_directives_mode_code'}
Truth table0%0/2
A
A= $op->{'runtime_directives_mode_code'}
Aresult
11
00
943 0 ▶ return if !$mode_code || !$op->{has_runtime_directives};
Branch: 1 branch
BranchTrueFalseTotal
unless $mode_code and $op->{"has_runtime_directives"} 0 0 0
Condition0%0/3
$mode_code and $op->{"has_runtime_directives"}
!ll&&!rl&&r
000
MC/DC0%0/2
$mode_code and $op->{"has_runtime_directives"}
$mode_code $op->{"has_runtime_directives"}
Truth table0%0/3
A and B
A= $mode_codeB= $op->{"has_runtime_directives"}
ABresult
0X0
100
111
944  
945 my $payload = GraphQL::Houtou::Runtime::DirectiveRuntime::materialize_runtime_directives(
946 $op->{runtime_directives_payload},
947 0 $variables,
948 );
949 0 $op->{runtime_directives_mode_code} = 1;
950 0 $op->{runtime_directives_payload} = $payload;
951 0 ▶ $op->{has_runtime_directives} = @$payload ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$payload ? : 0 0 0
952 }
953  
954 45 1;
955  
956 __END__
« blib/lib/GraphQL/Houtou/Runtime/VMBlock.pm ↑ Summary blib/lib/GraphQL/Houtou/Runtime/SchemaGraph.pm »