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

filter: Statementstmt 85.4% 100 / 117 Branchbran 60.0% 30 / 50 Conditioncond 51.8% 14 / 27 MC/DCmcdc 23.5% 4 / 17 Subroutinesub 92.0% 23 / 25 Podpod 0.0% 0 / 14 totaltotal 68.4% 171 / 250 CC 39 SCAR 23.6
CC
39
Cov
74%
perl_to_graphql
56.0
is_valid
20.0
graphql_to_perl
7.3
CRAP 10.6
« blib/lib/GraphQL/Houtou/Runtime/VMProgram.pm ↑ Summary blib/lib/GraphQL/Houtou/Async/Adapter.pm »
1 package GraphQL::Houtou::Type::InputObject;
2  
3 14 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use parent 'GraphQL::Houtou::Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use GraphQL::Houtou::Internal::TypeSupport qw(description_doc_lines named_from_ast apply_fields_deprecation from_ast_fields make_fieldtuples);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use GraphQL::Houtou::Type::List ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use GraphQL::Houtou::Type::NonNull ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 14 with qw(
14 GraphQL::Houtou::Role::Input
15 GraphQL::Houtou::Role::FieldsInput
16 GraphQL::Houtou::Role::HashMappable
17 );
18  
19 1 ▶sub list {
Subroutine list: called CC=2 SCAR=9.2
Pod undocumented
20 1 ▶ $_[0]->{_houtou_list} ||= GraphQL::Houtou::Type::List->new(of => $_[0]);
Condition33%1/3
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
l!l&&r!l&&!r
010
MC/DC0%0/2
$_[0]{"_houtou_list"} ||= "GraphQL::Houtou::Type::List"->new("of", $_[0])
$_[0]{"_houtou_list"} "GraphQL::Houtou::Type::List"->new("of", $_[0])
Truth table33%1/3
A ||= B
A= $_[0]{"_houtou_list"}B= "GraphQL::Houtou::Type::List"->new("of", $_[0])
ABresult
1X1
011
000
21 }
22  
23 16 ▶sub non_null {
Subroutine non_null: called CC=2 SCAR=7.2
Pod undocumented
24 16 ▶ $_[0]->{_houtou_non_null} ||= GraphQL::Houtou::Type::NonNull->new(of => $_[0]);
Condition66%2/3
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
l!l&&r!l&&!r
1060
MC/DC0%0/2
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
$_[0]{"_houtou_non_null"} "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
Truth table66%2/3
A ||= B
A= $_[0]{"_houtou_non_null"}B= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
ABresult
1X1
011
000
25 }
26  
27 14 ▶use constant DEBUG => $ENV{GRAPHQL_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 35 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
30 35 my ($class, %args) = @_;
31 35 my $self = $class->SUPER::new(%args);
32 35 $self->{name} = $args{name};
33 35 $self->{description} = $args{description};
34 35 $self->{fields} = $args{fields};
35 35 ▶ $self->{is_one_of} = $args{is_one_of} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args{'is_one_of'} ? : 13 22 35
36 35 return bless $self, $class;
37 }
38  
39 956 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
40 347 ▶sub description { $_[0]->{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
41 382 ▶sub is_one_of { $_[0]->{is_one_of} }
Subroutine is_one_of: called CC=1 SCAR=0.0
Pod undocumented
42 689 ▶sub to_string { $_[0]->{to_string} ||= $_[0]->name }
Subroutine to_string: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0]{"to_string"} ||= $_[0]->name
l!l&&r!l&&!r
666230
MC/DC0%0/2
$_[0]{"to_string"} ||= $_[0]->name
$_[0]{"to_string"} $_[0]->name
Truth table66%2/3
A ||= B
A= $_[0]{"to_string"}B= $_[0]->name
ABresult
1X1
011
000
43  
44 16 ▶sub from_ast {
Subroutine from_ast: called CC=4 SCAR=13.9
Pod undocumented
45 16 my ($class, $name2type, $ast_node) = @_;
46 16 ▶ my $one_of = grep { ($_->{name} || q()) eq 'oneOf' } @{ $ast_node->{directives} || [] };
Condition75%3/4
$_->{'name'} || ''
l!l
110
$ast_node->{'directives'} || []
l!l
115
MC/DC0%0/1
$_->{'name'} || ''
$_->{'name'}
MC/DC100%1/1
$ast_node->{'directives'} || []
$ast_node->{'directives'}
Truth table50%1/2
A
A= $_->{'name'}
Aresult
11
00
Truth table100%2/2
A
A= $ast_node->{'directives'}
Aresult
11
00
47 16 ▶ return $class->new(
Branch: 1 branch
BranchTrueFalseTotal
$one_of ? : 11 5 16
48 named_from_ast($ast_node),
49 from_ast_fields($name2type, $ast_node, 'fields'),
50 ($one_of ? (is_one_of => 1) : ()),
51 );
52 }
53  
54 4 ▶sub to_doc {
Subroutine to_doc: called CC=4 SCAR=14.2
Pod undocumented
55 4 my ($self) = @_;
56 4 ▶ return $self->{to_doc} if exists $self->{to_doc};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"to_doc"} 0 4 4
57 my @fieldlines = map {
58 4 my ($main, @description) = @$_;
59 11 (@description, $main);
60 } make_fieldtuples($self->fields);
61 4 ▶ my $one_of = $self->is_one_of ? ' @oneOf' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_one_of ? : 4 0 4
62 4 return $self->{to_doc} = join '', map "$_\n",
63 description_doc_lines($self->description),
64 4 ▶ "input @{[$self->name]}$one_of {",
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 11 0 11
65 (map length() ? " $_" : "", @fieldlines),
66 "}";
67 }
68  
69 596 ▶sub fields {
Subroutine fields: called CC=3 SCAR=11.0
Pod undocumented
70 596 my ($self) = @_;
71 596 my $fields = $self->{fields};
72 596 ▶ if (ref($fields) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fields eq "CODE") 20 576 596
73 20 $fields = $fields->();
74 20 $self->{fields} = $fields;
75 }
76 596 ▶ if (!$self->{_fields_deprecation_applied}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_fields_deprecation_applied"}) 35 561 596
77 35 $self->{fields} = apply_fields_deprecation($self->{fields});
78 35 $self->{_fields_deprecation_applied} = 1;
79 }
80 596 return $self->{fields};
81 }
82  
83 0 ▶sub is_valid {
Subroutine is_valid: not called CC=4 SCAR=30.0
Pod undocumented
84 0 my ($self, $item) = @_;
85 0 my $fields = $self->fields;
86  
87 0 ▶ return 1 if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 0 0
88 0 ▶ return if grep { !$fields->{$_}{type}->is_valid($item->{$_} // $fields->{$_}{default_value}) } keys %$fields;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $fields->{$_}{"type"}->is_valid($item->{$_} // $fields->{$_}{"default_value"});} keys %$fields 0 0 0
Condition0%0/3
$item->{$_} // $fields->{$_}{"default_value"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$item->{$_} // $fields->{$_}{"default_value"}
$item->{$_} $fields->{$_}{"default_value"}
Truth table0%0/3
A // B
A= $item->{$_}B= $fields->{$_}{"default_value"}
ABresult
1X1
011
000
89 0 return 1;
90 }
91  
92 24 ▶sub uplift {
Subroutine uplift: called CC=7 SCAR=19.5
Pod undocumented
93 24 my ($self, $item) = @_;
94 24 my $fields = $self->fields;
95  
96 24 ▶ return $item if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 24 24
97 24 ▶ die "found not an object" if ref($item) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $item ne "HASH" 0 24 24
98 24 _assert_known_fields($item, $fields);
99 16 my %uplifted;
100 16 for my $key (sort keys %$fields) {
101 27 ▶ next if !exists $item->{$key} && !exists $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $item->{$key} or exists $fields->{$key}{"default_value"} 5 22 27
Condition100%3/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
l!l&&r!l&&!r
1755
MC/DC100%2/2
exists $item->{$key} or exists $fields->{$key}{"default_value"}
exists $item->{$key} exists $fields->{$key}{"default_value"}
Truth table100%3/3
A or B
A= exists $item->{$key}B= exists $fields->{$key}{"default_value"}
ABresult
1X1
011
000
102 22 ▶ my $value = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
exists $item->{$key} ? : 17 5 22
103 22 $uplifted{$key} = $fields->{$key}{type}->uplift($value);
104 }
105 16 return \%uplifted;
106 }
107  
108 30 ▶sub _assert_one_of {
Subroutine _assert_one_of: called CC=4 SCAR=13.9
109 30 my ($self, $item) = @_;
110 30 ▶ return if !$self->{is_one_of};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"is_one_of"} 21 9 30
111 9 my @keys = keys %$item;
112 9 ▶ die "OneOf Input Object '@{[$self->name]}' must specify exactly one key.\n"
Branch: 1 branch
BranchTrueFalseTotal
if @keys != 1 3 6 9
113 if @keys != 1;
114 3 die "OneOf Input Object '@{[$self->name]}' field '$keys[0]' must be non-null.\n"
115 6 ▶ if !defined $item->{ $keys[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$item{$keys[0]} 3 3 6
116 3 return;
117 }
118  
119 30 ▶sub graphql_to_perl {
Subroutine graphql_to_perl: called CC=7 SCAR=19.8
Pod undocumented
120 30 my ($self, $item) = @_;
121 30 my $fields = $self->fields;
122  
123 30 ▶ return $item if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 30 30
124 30 ▶ die "found not an object" if ref($item) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $item ne "HASH" 0 30 30
125 30 $self->_assert_one_of($item);
126 24 $item = $self->uplift($item);
127 16 my %value;
128 16 for my $key (sort keys %$fields) {
129 27 ▶ next if !exists $item->{$key} && !exists $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $item->{$key} or exists $fields->{$key}{"default_value"} 5 22 27
Condition66%2/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
l!l&&r!l&&!r
2205
MC/DC50%1/2
exists $item->{$key} or exists $fields->{$key}{"default_value"}
exists $item->{$key} exists $fields->{$key}{"default_value"}
Truth table66%2/3
A or B
A= exists $item->{$key}B= exists $fields->{$key}{"default_value"}
ABresult
1X1
011
000
130 22 ▶ my $raw = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
exists $item->{$key} ? : 22 0 22
131 22 $value{$key} = $fields->{$key}{type}->graphql_to_perl($raw);
132 }
133 16 return \%value;
134 }
135  
136 0 ▶sub perl_to_graphql {
Subroutine perl_to_graphql: not called CC=7 SCAR=40.3
Pod undocumented
137 0 my ($self, $item) = @_;
138 0 my $fields = $self->fields;
139  
140 0 ▶ return $item if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 0 0
141 0 ▶ die "found not an object" if ref($item) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $item ne "HASH" 0 0 0
142 0 $item = $self->uplift($item);
143 0 my %value;
144 0 for my $key (sort keys %$fields) {
145 0 ▶ next if !exists $item->{$key} && !exists $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $item->{$key} or exists $fields->{$key}{"default_value"} 0 0 0
Condition0%0/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $item->{$key} or exists $fields->{$key}{"default_value"}
exists $item->{$key} exists $fields->{$key}{"default_value"}
Truth table0%0/3
A or B
A= exists $item->{$key}B= exists $fields->{$key}{"default_value"}
ABresult
1X1
011
000
146 0 ▶ my $raw = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value};
Branch: 1 branch
BranchTrueFalseTotal
exists $item->{$key} ? : 0 0 0
147 0 $value{$key} = $fields->{$key}{type}->perl_to_graphql($raw);
148 }
149 0 return \%value;
150 }
151  
152 24 ▶sub _assert_known_fields {
Subroutine _assert_known_fields: called CC=3 SCAR=11.0
153 24 my ($item, $fields) = @_;
154 24 ▶ my @unknown = grep { !exists $fields->{$_} } sort keys %{$item || {}};
Condition50%1/2
$item || {}
l!l
240
MC/DC0%0/1
$item || {}
$item
Truth table50%1/2
A
A= $item
Aresult
11
00
155 24 ▶ die join '', map qq{In field "$_": Unknown field.\n}, @unknown if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 8 16 24
156 16 return;
157 }
158  
159 14 1;
160  
161 __END__
« blib/lib/GraphQL/Houtou/Runtime/VMProgram.pm ↑ Summary blib/lib/GraphQL/Houtou/Async/Adapter.pm »