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

filter: Statementstmt 75.9% 139 / 183 Branchbran 44.9% 53 / 118 Conditioncond 31.5% 36 / 114 MC/DCmcdc 7.8% 5 / 64 Subroutinesub 89.2% 25 / 28 Podpod 0.0% 0 / 6 totaltotal 50.2% 258 / 513 CC 107 SCAR 37.0
CC
107
Cov
55%
materialize_program_runtime_directives
210.0
has_runtime_directives
72.0
_default_field_resolver
62.5
CRAP 40.5
« blib/lib/GraphQL/Houtou/Runtime/OperationCompiler.pm ↑ Summary blib/lib/GraphQL/Houtou/Type/Interface.pm »
1 package GraphQL::Houtou::Runtime::DirectiveRuntime;
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 Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 62 ▶use JSON::MaybeXS qw(is_bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 62 ▶use Scalar::Util qw(blessed refaddr reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 62 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 62 our @EXPORT_OK = qw(
13 has_runtime_directives
14 apply_runtime_directives
15 slot_needs_runtime_wrapper
16 wrap_field_resolver
17 materialize_runtime_directives
18 materialize_program_runtime_directives
19 );
20  
21 62 my %RUNTIME_DIRECTIVE_ENTRIES_CACHE;
22 62 our $CURRENT_DIRECTIVE_FRAME;
23 62 our $NEXT_DIRECTIVE_VALUE;
24 62 our $CURRENT_SINGLE_DIRECTIVE_VALUE;
25 2 ▶our $NEXT_SINGLE_DIRECTIVE_VALUE = sub { return $CURRENT_SINGLE_DIRECTIVE_VALUE };
Subroutine __ANON__: called CC=1 SCAR=0.0
26 3 ▶$NEXT_DIRECTIVE_VALUE = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
27 3 ▶ my $frame = $CURRENT_DIRECTIVE_FRAME || return undef;
Condition50%1/2
$GraphQL::Houtou::Runtime::DirectiveRuntime::CURRENT_DIRECTIVE_FRAME || (return undef)
l!l
30
MC/DC0%0/1
$GraphQL::Houtou::Runtime::DirectiveRuntime::CURRENT_DIRECTIVE_FRAME || (return undef)
$GraphQL::Houtou::Runtime::DirectiveRuntime::CURRENT_DIRECTIVE_FRAME
Truth table50%1/2
A
A= $GraphQL::Houtou::Runtime::DirectiveRuntime::CURRENT_DIRECTIVE_FRAME
Aresult
11
00
28 3 my $index = $frame->{index}++;
29 3 ▶ return $frame->{final_cb}->() if $index >= @{ $frame->{entries} };
Branch: 1 branch
BranchTrueFalseTotal
if $index >= @{$frame->{"entries"};} 1 2 3
30  
31 2 my ($mode, $code, $directive_args, $directive) = @{ $frame->{entries}[$index] };
32 2 ▶ if ($mode eq 'transform') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "transform") 2 0 2
33 return $code->(
34 scalar($NEXT_DIRECTIVE_VALUE->()),
35 $frame->{source},
36 $frame->{field_args},
37 $frame->{context},
38 $frame->{info},
39 $frame->{return_type},
40 2 $directive_args,
41 $directive,
42 );
43 }
44 return $code->(
45 $NEXT_DIRECTIVE_VALUE,
46 $frame->{source},
47 $frame->{field_args},
48 $frame->{context},
49 $frame->{info},
50 $frame->{return_type},
51 0 $directive_args,
52 $directive,
53 );
54 62 };
55  
56 0 ▶sub has_runtime_directives {
Subroutine has_runtime_directives: not called CC=8 SCAR=42.8
Pod undocumented
57 0 my ($schema) = @_;
58 0 ▶ return 0 if !$schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 0 0
59 0 ▶ for my $directive (@{ $schema->directives || [] }) {
Condition0%0/2
$schema->directives || []
l!l
00
MC/DC0%0/1
$schema->directives || []
$schema->directives
Truth table0%0/2
A
A= $schema->directives
Aresult
11
00
60 0 ▶ next if !$directive;
Branch: 1 branch
BranchTrueFalseTotal
unless $directive 0 0 0
61 0 ▶ next if !$directive->can('has_runtime_hook') || !$directive->has_runtime_hook;
Branch: 1 branch
BranchTrueFalseTotal
unless $directive->can("has_runtime_hook") and $directive->has_runtime_hook 0 0 0
Condition0%0/3
$directive->can("has_runtime_hook") and $directive->has_runtime_hook
!ll&&!rl&&r
000
MC/DC0%0/2
$directive->can("has_runtime_hook") and $directive->has_runtime_hook
$directive->can("has_runtime_hook") $directive->has_runtime_hook
Truth table0%0/3
A and B
A= $directive->can("has_runtime_hook")B= $directive->has_runtime_hook
ABresult
0X0
100
111
62 0 ▶ return 1 if $directive->has_executable_location;
Branch: 1 branch
BranchTrueFalseTotal
if $directive->has_executable_location 0 0 0
63 }
64 0 return 0;
65 }
66  
67 16947 ▶sub slot_needs_runtime_wrapper {
Subroutine slot_needs_runtime_wrapper: called CC=5 SCAR=16.3
Pod undocumented
68 16947 my (%args) = @_;
69 16947 ▶ my $field = $args{field} || {};
Condition50%1/2
$args{'field'} || {}
l!l
169470
MC/DC0%0/1
$args{'field'} || {}
$args{'field'}
Truth table50%1/2
A
A= $args{'field'}
Aresult
11
00
70 16947 ▶ return 0 if ref($field) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $field ne "HASH" 0 16947 16947
71 16947 ▶ return @{ $field->{directives} || [] } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$field->{'directives'} or [];} ? : 5 16942 16947
Condition100%2/2
$field->{'directives'} || []
l!l
816939
MC/DC100%1/1
$field->{'directives'} || []
$field->{'directives'}
Truth table100%2/2
A
A= $field->{'directives'}
Aresult
11
00
72 }
73  
74 488 ▶sub wrap_field_resolver {
Subroutine wrap_field_resolver: called CC=7 SCAR=19.8
Pod undocumented
75 488 my (%args) = @_;
76 488 my $schema = $args{schema};
77 488 my $field_name = $args{field_name};
78 488 ▶ my $field = $args{field} || {};
Condition50%1/2
$args{'field'} || {}
l!l
4880
MC/DC0%0/1
$args{'field'} || {}
$args{'field'}
Truth table50%1/2
A
A= $args{'field'}
Aresult
11
00
79 488 my $base_resolver = $args{resolver};
80 488 ▶ my $is_typename = ($field_name || q()) eq '__typename' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($field_name || '') eq '__typename' ? : 0 488 488
Condition50%1/2
$field_name || ''
l!l
4880
MC/DC0%0/1
$field_name || ''
$field_name
Truth table50%1/2
A
A= $field_name
Aresult
11
00
81  
82 488 ▶ my $directive_defs = $schema ? ($schema->name2directive || {}) : {};
Branch: 1 branch
BranchTrueFalseTotal
$schema ? : 488 0 488
Condition50%1/2
$schema->name2directive or {}
l!l
4880
MC/DC0%0/1
$schema->name2directive or {}
$schema->name2directive
Truth table50%1/2
A
A= $schema->name2directive
Aresult
11
00
83 488 ▶ my $schema_directives = $field->{directives} || [];
Condition100%2/2
$field->{'directives'} || []
l!l
2486
MC/DC100%1/1
$field->{'directives'} || []
$field->{'directives'}
Truth table100%2/2
A
A= $field->{'directives'}
Aresult
11
00
84 488 my $compiled_schema_directives = _compile_directive_entries($directive_defs, $schema_directives);
85  
86 36 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
87 36 my ($source, $field_args, $context, $info, $return_type) = @_;
88 36 ▶ my $final_cb = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
89 36 ▶ return _default_field_resolver(
Branch: 1 branch
BranchTrueFalseTotal
unless $base_resolver 2 34 36
90 $source, $field_name, $field_args, $context, $info,
91 )
92 if !$base_resolver;
93 34 return $base_resolver->($source, $field_args, $context, $info, $return_type);
94 36 };
95  
96 36 ▶ return $final_cb->() if !@$compiled_schema_directives && !$is_typename;
Branch: 1 branch
BranchTrueFalseTotal
unless @$compiled_schema_directives or $is_typename 34 2 36
Condition66%2/3
@$compiled_schema_directives or $is_typename
l!l&&r!l&&!r
2034
MC/DC50%1/2
@$compiled_schema_directives or $is_typename
@$compiled_schema_directives $is_typename
Truth table66%2/3
A or B
A= @$compiled_schema_directivesB= $is_typename
ABresult
1X1
011
000
97  
98 2 return _apply_compiled_directive_entries(
99 $compiled_schema_directives,
100 $source,
101 $field_args,
102 $context,
103 $info,
104 $return_type,
105 $final_cb,
106 );
107 488 };
108 }
109  
110 5 ▶sub apply_runtime_directives {
Subroutine apply_runtime_directives: called CC=4 SCAR=14.2
Pod undocumented
111 5 my ($runtime_schema, $source, $field_args, $context, $info, $return_type, $resolved_value) = @_;
112 5 my $schema = _resolve_schema($runtime_schema);
113 5 ▶ return $resolved_value if !$schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema 0 5 5
114  
115 5 my $runtime_directives = _runtime_directives_from_info($info);
116 5 ▶ return $resolved_value if !@$runtime_directives;
Branch: 1 branch
BranchTrueFalseTotal
unless @$runtime_directives 0 5 5
117 5 my $compiled_runtime_directives = _compiled_runtime_directive_entries($schema, $runtime_directives);
118 5 ▶ return $resolved_value if !@$compiled_runtime_directives;
Branch: 1 branch
BranchTrueFalseTotal
unless @$compiled_runtime_directives 0 5 5
119  
120 return _apply_compiled_directive_entries(
121 $compiled_runtime_directives,
122 $source,
123 $field_args,
124 $context,
125 $info,
126 $return_type,
127 5 ▶ sub { $resolved_value },
Subroutine __ANON__: called CC=1 SCAR=0.0
128 5 );
129 }
130  
131 5 ▶sub _runtime_directives_from_info {
Subroutine _runtime_directives_from_info: called CC=7 SCAR=31.1
132 5 my ($info) = @_;
133 5 ▶ return [] if !$info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 5 5
134  
135 5 ▶ my $runtime_directives = $info->{directives} || [];
Condition50%1/2
$info->{'directives'} || []
l!l
50
MC/DC0%0/1
$info->{'directives'} || []
$info->{'directives'}
Truth table50%1/2
A
A= $info->{'directives'}
Aresult
11
00
136 5 ▶ return $runtime_directives if @$runtime_directives;
Branch: 1 branch
BranchTrueFalseTotal
if @$runtime_directives 5 0 5
137  
138 0 my $program = $info->{operation};
139 0 my $block_index = $info->{block_index};
140 0 my $op_index = $info->{op_index};
141 0 ▶ return [] if !defined $block_index || !defined $op_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block_index and defined $op_index 0 0 0
Condition0%0/3
defined $block_index and defined $op_index
!ll&&!rl&&r
000
MC/DC0%0/2
defined $block_index and defined $op_index
defined $block_index defined $op_index
Truth table0%0/3
A and B
A= defined $block_indexB= defined $op_index
ABresult
0X0
100
111
142  
143 return materialize_program_runtime_directives(
144 $program,
145 $block_index,
146 $op_index,
147 $info->{variable_values} || {},
148 0 ▶ );
Condition0%0/2
$info->{'variable_values'} || {}
l!l
00
MC/DC0%0/1
$info->{'variable_values'} || {}
$info->{'variable_values'}
Truth table0%0/2
A
A= $info->{'variable_values'}
Aresult
11
00
149 }
150  
151 4 ▶sub materialize_runtime_directives {
Subroutine materialize_runtime_directives: called CC=3 SCAR=11.7
Pod undocumented
152 4 my ($payload, $variables) = @_;
153 4 ▶ return [] if !$payload;
Branch: 1 branch
BranchTrueFalseTotal
unless $payload 0 4 4
154 4 ▶ return _materialize_value($payload, $variables || {});
Condition50%1/2
$variables || {}
l!l
40
MC/DC0%0/1
$variables || {}
$variables
Truth table50%1/2
A
A= $variables
Aresult
11
00
155 }
156  
157 0 ▶sub materialize_program_runtime_directives {
Subroutine materialize_program_runtime_directives: not called CC=14 SCAR=53.5
Pod undocumented
158 0 my ($program, $block_index, $op_index, $variables) = @_;
159 0 ▶ return [] if !defined $block_index || !defined $op_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block_index and defined $op_index 0 0 0
Condition0%0/3
defined $block_index and defined $op_index
!ll&&!rl&&r
000
MC/DC0%0/2
defined $block_index and defined $op_index
defined $block_index defined $op_index
Truth table0%0/3
A and B
A= defined $block_indexB= defined $op_index
ABresult
0X0
100
111
160 0 my $descriptor = _program_descriptor($program);
161 0 ▶ return [] if !$descriptor;
Branch: 1 branch
BranchTrueFalseTotal
unless $descriptor 0 0 0
162 0 ▶ my $blocks = $descriptor->{blocks_compact} || $descriptor->{blocks} || [];
Condition0%0/5
$descriptor->{'blocks_compact'} || $descriptor->{'blocks'} || []
l!l
00
$descriptor->{"blocks_compact"} or $descriptor->{"blocks"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$descriptor->{'blocks_compact'} || $descriptor->{'blocks'} || []
$descriptor->{"blocks_compact"} $descriptor->{"blocks"}
Truth table0%0/3
A or B
A= $descriptor->{"blocks_compact"}B= $descriptor->{"blocks"}
ABresult
1X1
011
000
163 0 ▶ my $block = $blocks->[$block_index] || return [];
Condition0%0/2
$blocks->[$block_index] || (return [])
l!l
00
MC/DC0%0/1
$blocks->[$block_index] || (return [])
$blocks->[$block_index]
Truth table0%0/2
A
A= $blocks->[$block_index]
Aresult
11
00
164 0 ▶ my $ops = ref($block) eq 'ARRAY' ? ($block->[4] || []) : ($block->{ops} || []);
Branch: 1 branch
BranchTrueFalseTotal
ref $block eq 'ARRAY' ? : 0 0 0
Condition0%0/4
$block->[4] or []
l!l
00
$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 table0%0/2
A
A= $block->[4]
Aresult
11
00
Truth table0%0/2
A
A= $block->{"ops"}
Aresult
11
00
165 0 ▶ my $op = $ops->[$op_index] || return [];
Condition0%0/2
$ops->[$op_index] || (return [])
l!l
00
MC/DC0%0/1
$ops->[$op_index] || (return [])
$ops->[$op_index]
Truth table0%0/2
A
A= $ops->[$op_index]
Aresult
11
00
166  
167 0 ▶ if (ref($op) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $op eq "ARRAY") 0 0 0
168 0 ▶ return [] if !$op->[20];
Branch: 1 branch
BranchTrueFalseTotal
unless $op->[20] 0 0 0
169 0 return materialize_runtime_directives($op->[19], $variables);
170 }
171  
172 0 ▶ return [] if !$op->{has_runtime_directives};
Branch: 1 branch
BranchTrueFalseTotal
unless $op->{"has_runtime_directives"} 0 0 0
173 0 return materialize_runtime_directives($op->{runtime_directives_payload}, $variables);
174 }
175  
176 2 ▶sub _default_field_resolver {
Subroutine _default_field_resolver: called CC=14 SCAR=41.4
177 2 my ($source, $field_name, $args, $context, $info) = @_;
178 2 ▶ return undef if !defined $field_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field_name 0 2 2
179  
180 2 ▶ if ($field_name eq '__typename') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field_name eq "__typename") 0 2 2
181 0 ▶ my $parent_type = $info ? $info->{parent_type} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$info ? : 0 0 0
182 0 ▶ return $parent_type && $parent_type->can('name') ? $parent_type->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$parent_type && $parent_type->can('name') ? : 0 0 0
Condition0%0/3
$parent_type and $parent_type->can("name")
!ll&&!rl&&r
000
MC/DC0%0/2
$parent_type and $parent_type->can("name")
$parent_type $parent_type->can("name")
Truth table0%0/3
A and B
A= $parent_typeB= $parent_type->can("name")
ABresult
0X0
100
111
183 }
184  
185 2 ▶ if (blessed($source) && $source->can($field_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($source) and $source->can($field_name)) 0 2 2
Condition33%1/3
builtin::blessed($source) and $source->can($field_name)
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($source) and $source->can($field_name)
builtin::blessed($source) $source->can($field_name)
Truth table33%1/3
A and B
A= builtin::blessed($source)B= $source->can($field_name)
ABresult
0X0
100
111
186 0 return $source->$field_name($args, $context, $info);
187 }
188  
189 2 ▶ if ($source && (reftype($source) || '') eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source and (builtin::reftype($source) || "") eq "HASH") 2 0 2
Condition40%2/5
$source and (builtin::reftype($source) || "") eq "HASH"
!ll&&!rl&&r
002
builtin::reftype($source) || ''
l!l
20
MC/DC0%0/2
$source and (builtin::reftype($source) || "") eq "HASH"
$source builtin::reftype($source)
Truth table33%1/3
A and B
A= $sourceB= builtin::reftype($source)
ABresult
0X0
100
111
190 2 my $value = $source->{$field_name};
191 2 ▶ return $value->($args, $context, $info)
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "CODE" or builtin::blessed($value) and overload::Method($value, "&{}") 2 0 2
Condition16%1/6
ref $value eq "CODE" or builtin::blessed($value) and overload::Method($value, "&{}")
l!l&&r!l&&!r
200
builtin::blessed($value) and overload::Method($value, "&{}")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $value eq "CODE" or builtin::blessed($value) and overload::Method($value, "&{}")
ref $value eq "CODE" builtin::blessed($value) overload::Method($value, "&{}")
Truth table25%1/4
A or B and C
A= ref $value eq "CODE"B= builtin::blessed($value)C= overload::Method($value, "&{}")
ABCresult
1XX1
0111
00X0
0100
192 if ref($value) eq 'CODE'
193 || (blessed($value) && overload::Method($value, '&{}'));
194 0 return $value;
195 }
196 0 return undef;
197 }
198  
199 1 ▶sub _resolve_default_property_value {
Subroutine _resolve_default_property_value: called CC=3 SCAR=14.2
200 1 my ($value, $args, $context, $info) = @_;
201 1 ▶ return $value->($args, $context, $info)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and overload::Method($value, "&{}") 1 0 1
Condition33%1/3
builtin::blessed($value) and overload::Method($value, "&{}")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($value) and overload::Method($value, "&{}")
builtin::blessed($value) overload::Method($value, "&{}")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= overload::Method($value, "&{}")
ABresult
0X0
100
111
202 if blessed($value) && overload::Method($value, '&{}');
203 0 return $value;
204 }
205  
206 0 ▶sub _program_descriptor {
Subroutine _program_descriptor: not called CC=5 SCAR=34.0
207 0 my ($program) = @_;
208 0 ▶ return if !$program;
Branch: 1 branch
BranchTrueFalseTotal
unless $program 0 0 0
209 0 ▶ 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") } }) 0 0 0
Condition0%0/3
ref $program and eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
!ll&&!rl&&r
000
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 table0%0/3
A and B
A= ref $programB= eval { do { $program->isa("GraphQL::Houtou::Runtime::NativeProgram") } }
ABresult
0X0
100
111
210 0 GraphQL::Houtou::_bootstrap_xs();
211 0 return GraphQL::Houtou::XS::VM::native_program_descriptor_xs($program);
212 }
213 0 ▶ return $program if ref($program) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $program eq "HASH" 0 0 0
214 0 return;
215 }
216  
217 5 ▶sub _resolve_schema {
Subroutine _resolve_schema: called CC=7 SCAR=24.5
218 5 my ($runtime_schema) = @_;
219 5 ▶ return if !$runtime_schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $runtime_schema 0 5 5
220 5 ▶ return $runtime_schema if ref($runtime_schema) && eval { $runtime_schema->can('name2directive') };
Branch: 1 branch
BranchTrueFalseTotal
if ref $runtime_schema and eval { do { $runtime_schema->can("name2directive") } } 0 5 5
Condition33%1/3
ref $runtime_schema and eval { do { $runtime_schema->can("name2directive") } }
!ll&&!rl&&r
050
MC/DC0%0/2
ref $runtime_schema and eval { do { $runtime_schema->can("name2directive") } }
ref $runtime_schema eval { do { $runtime_schema->can("name2directive") } }
Truth table33%1/3
A and B
A= ref $runtime_schemaB= eval { do { $runtime_schema->can("name2directive") } }
ABresult
0X0
100
111
221 return $runtime_schema->{schema}
222 if ref($runtime_schema) eq 'HASH'
223 && ref($runtime_schema->{schema})
224 5 ▶ && eval { $runtime_schema->{schema}->can('name2directive') };
Branch: 1 branch
BranchTrueFalseTotal
if ref $runtime_schema eq "HASH" and ref $runtime_schema->{"schema"} and eval { do { $runtime_schema->{"schema"}->can("name2directive") } } 5 0 5
Condition33%2/6
ref $runtime_schema eq "HASH" and ref $runtime_schema->{"schema"} and eval { do { $runtime_schema->{"schema"}->can("name2directive") } }
!ll&&!rl&&r
005
ref $runtime_schema eq "HASH" and ref $runtime_schema->{"schema"}
!ll&&!rl&&r
005
MC/DC0%0/3
ref $runtime_schema eq "HASH" and ref $runtime_schema->{"schema"} and eval { do { $runtime_schema->{"schema"}->can("name2directive") } }
ref $runtime_schema eq "HASH" ref $runtime_schema->{"schema"} eval { do { $runtime_schema->{"schema"}->can("name2directive") } }
Truth table25%1/4
A and B and C
A= ref $runtime_schema eq "HASH"B= ref $runtime_schema->{"schema"}C= eval { do { $runtime_schema->{"schema"}->can("name2directive") } }
ABCresult
0XX0
10X0
1100
1111
225 0 return;
226 }
227  
228 5 ▶sub _compiled_runtime_directive_entries {
Subroutine _compiled_runtime_directive_entries: called CC=10 SCAR=27.8
229 5 my ($schema, $runtime_directives) = @_;
230 5 ▶ return [] if !$schema || !$runtime_directives || !@$runtime_directives;
Branch: 1 branch
BranchTrueFalseTotal
unless $schema and $runtime_directives and @$runtime_directives 0 5 5
Condition33%2/6
$schema and $runtime_directives and @$runtime_directives
!ll&&!rl&&r
005
$schema and $runtime_directives
!ll&&!rl&&r
005
MC/DC0%0/3
$schema and $runtime_directives and @$runtime_directives
$schema $runtime_directives @$runtime_directives
Truth table25%1/4
A and B and C
A= $schemaB= $runtime_directivesC= @$runtime_directives
ABCresult
0XX0
10X0
1100
1111
231  
232 5 my $schema_key = refaddr($schema);
233 5 my $directives_key = refaddr($runtime_directives);
234 5 ▶ if ($schema_key && $directives_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_key and $directives_key) 5 0 5
Condition33%1/3
$schema_key and $directives_key
!ll&&!rl&&r
005
MC/DC0%0/2
$schema_key and $directives_key
$schema_key $directives_key
Truth table33%1/3
A and B
A= $schema_keyB= $directives_key
ABresult
0X0
100
111
235 5 my $cached = $RUNTIME_DIRECTIVE_ENTRIES_CACHE{$schema_key}{$directives_key};
236 5 ▶ return $cached if $cached;
Branch: 1 branch
BranchTrueFalseTotal
if $cached 0 5 5
237 }
238  
239 5 ▶ my $compiled = _compile_directive_entries($schema->name2directive || {}, $runtime_directives);
Condition50%1/2
$schema->name2directive || {}
l!l
50
MC/DC0%0/1
$schema->name2directive || {}
$schema->name2directive
Truth table50%1/2
A
A= $schema->name2directive
Aresult
11
00
240 5 ▶ if ($schema_key && $directives_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_key and $directives_key) 5 0 5
Condition33%1/3
$schema_key and $directives_key
!ll&&!rl&&r
005
MC/DC0%0/2
$schema_key and $directives_key
$schema_key $directives_key
Truth table33%1/3
A and B
A= $schema_keyB= $directives_key
ABresult
0X0
100
111
241 5 $RUNTIME_DIRECTIVE_ENTRIES_CACHE{$schema_key}{$directives_key} = $compiled;
242 }
243 5 return $compiled;
244 }
245  
246 493 ▶sub _compile_directive_entries {
Subroutine _compile_directive_entries: called CC=13 SCAR=28.3
247 493 my ($directive_defs, $instances) = @_;
248 493 ▶ return [] if !$instances || !@$instances;
Branch: 1 branch
BranchTrueFalseTotal
unless $instances and @$instances 486 7 493
Condition66%2/3
$instances and @$instances
!ll&&!rl&&r
04867
MC/DC50%1/2
$instances and @$instances
$instances @$instances
Truth table66%2/3
A and B
A= $instancesB= @$instances
ABresult
0X0
100
111
249  
250 7 my @entries;
251 7 for my $instance (@$instances) {
252 8 ▶ next if !$instance || ref($instance) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $instance or ref $instance ne "HASH" 0 8 8
Condition33%1/3
not $instance or ref $instance ne "HASH"
l!l&&r!l&&!r
008
MC/DC0%0/2
not $instance or ref $instance ne "HASH"
not $instance ref $instance ne "HASH"
Truth table33%1/3
not(A) or B
A= not $instanceB= ref $instance ne "HASH"
ABresult
1X1
011
000
253 8 ▶ my $name = $instance->{name} || next;
Condition50%1/2
$instance->{'name'} || (next)
l!l
80
MC/DC0%0/1
$instance->{'name'} || (next)
$instance->{'name'}
Truth table50%1/2
A
A= $instance->{'name'}
Aresult
11
00
254 8 ▶ my $directive = $directive_defs->{$name} || next;
Condition50%1/2
$directive_defs->{$name} || (next)
l!l
80
MC/DC0%0/1
$directive_defs->{$name} || (next)
$directive_defs->{$name}
Truth table50%1/2
A
A= $directive_defs->{$name}
Aresult
11
00
255 8 my ($mode, $code);
256 8 ▶ if ($directive->can('apply_field_result') && $directive->apply_field_result) {
Branch: 2 branches
BranchTrueFalseTotal
if ($directive->can('apply_field_result') and $directive->apply_field_result) { } 5 3 8
elsif ($directive->can('resolve_field') and $directive->resolve_field) { } 3 0 3
Condition66%2/3
$directive->can("apply_field_result") and $directive->apply_field_result
!ll&&!rl&&r
035
MC/DC50%1/2
$directive->can("apply_field_result") and $directive->apply_field_result
$directive->can("apply_field_result") $directive->apply_field_result
Truth table66%2/3
A and B
A= $directive->can("apply_field_result")B= $directive->apply_field_result
ABresult
0X0
100
111
257 5 $mode = 'transform';
258 5 $code = $directive->apply_field_result;
259 ▶ } elsif ($directive->can('resolve_field') && $directive->resolve_field) {
Condition33%1/3
$directive->can("resolve_field") and $directive->resolve_field
!ll&&!rl&&r
003
MC/DC0%0/2
$directive->can("resolve_field") and $directive->resolve_field
$directive->can("resolve_field") $directive->resolve_field
Truth table33%1/3
A and B
A= $directive->can("resolve_field")B= $directive->resolve_field
ABresult
0X0
100
111
260 3 $mode = 'middleware';
261 3 $code = $directive->resolve_field;
262 } else {
263 0 next;
264 }
265 push @entries, [
266 $mode,
267 $code,
268 8 ▶ ($instance->{arguments} || {}),
Condition50%1/2
$instance->{'arguments'} || {}
l!l
80
MC/DC0%0/1
$instance->{'arguments'} || {}
$instance->{'arguments'}
Truth table50%1/2
A
A= $instance->{'arguments'}
Aresult
11
00
269 $directive,
270 ];
271 }
272 7 return \@entries;
273 }
274  
275 7 ▶sub _apply_compiled_directive_entries {
Subroutine _apply_compiled_directive_entries: called CC=5 SCAR=16.3
276 7 my ($entries, $source, $field_args, $context, $info, $return_type, $final_cb) = @_;
277 7 ▶ return $final_cb->() if !$entries || !@$entries;
Branch: 1 branch
BranchTrueFalseTotal
unless $entries and @$entries 0 7 7
Condition33%1/3
$entries and @$entries
!ll&&!rl&&r
007
MC/DC0%0/2
$entries and @$entries
$entries @$entries
Truth table33%1/3
A and B
A= $entriesB= @$entries
ABresult
0X0
100
111
278 7 ▶ if (@$entries == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$entries == 1) 6 1 7
279 6 my ($mode, $code, $directive_args, $directive) = @{ $entries->[0] };
280 6 ▶ if ($mode eq 'transform') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "transform") 3 3 6
281 3 return $code->(
282 scalar($final_cb->()),
283 $source,
284 $field_args,
285 $context,
286 $info,
287 $return_type,
288 $directive_args,
289 $directive,
290 );
291 }
292 3 local $CURRENT_SINGLE_DIRECTIVE_VALUE = $final_cb->();
293 3 return $code->(
294 $NEXT_SINGLE_DIRECTIVE_VALUE,
295 $source,
296 $field_args,
297 $context,
298 $info,
299 $return_type,
300 $directive_args,
301 $directive,
302 );
303 }
304  
305 1 local $CURRENT_DIRECTIVE_FRAME = {
306 entries => $entries,
307 index => 0,
308 source => $source,
309 field_args => $field_args,
310 context => $context,
311 info => $info,
312 return_type => $return_type,
313 final_cb => $final_cb,
314 };
315 1 return $NEXT_DIRECTIVE_VALUE->();
316 }
317  
318 20 ▶sub _materialize_value {
Subroutine _materialize_value: called CC=8 SCAR=21.8
319 20 my ($value, $variables) = @_;
320 20 my $ref = ref($value);
321 20 ▶ return $value if !$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 4 16 20
322 16 ▶ return $value ? 1 : 0 if is_bool($value);
Branch: 2 branches
BranchTrueFalseTotal
if is_bool($value) 0 16 16
$value ? : 0 0 0
323 16 ▶ return _materialize_variable($$value, $variables) if $ref eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "SCALAR" 4 12 16
324 12 ▶ return _materialize_value($$value, $variables) if $ref eq 'REF';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "REF" 0 12 12
325 12 ▶ return [ map { _materialize_value($_, $variables) } @$value ] if $ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "ARRAY" 4 8 12
326 return {
327 8 ▶ map { $_ => _materialize_value($value->{$_}, $variables) }
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "HASH" 8 0 8
328 keys %$value
329 } if $ref eq 'HASH';
330 0 return $value;
331 }
332  
333 4 ▶sub _materialize_variable {
Subroutine _materialize_variable: called CC=3 SCAR=11.7
334 4 my ($name, $variables) = @_;
335 4 ▶ return undef if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 4 4
336 4 ▶ return exists $variables->{$name} ? $variables->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $variables->{$name} ? : 4 0 4
337 }
338  
339 62 1;
« blib/lib/GraphQL/Houtou/Runtime/OperationCompiler.pm ↑ Summary blib/lib/GraphQL/Houtou/Type/Interface.pm »