| 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])
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])
| |||||||||||||||||||||||||||||
| 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])
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])
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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'} || ''
$ast_node->{'directives'} || []
MC/DC0%0/1
$_->{'name'} || ''
$_->{'name'}
MC/DC100%1/1
$ast_node->{'directives'} || []
$ast_node->{'directives'}
Truth table50%1/2
A
A= $_->{'name'}
Truth table100%2/2
A
A= $ast_node->{'directives'}
| |||||||||||||||||||||||||||||
| 47 | 16 | ▶ | return $class->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 73 | 20 | $fields = $fields->(); | |||||||||||||||||||||||||||
| 74 | 20 | $self->{fields} = $fields; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 596 | ▶ | if (!$self->{_fields_deprecation_applied}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return if grep { !$fields->{$_}{type}->is_valid($item->{$_} // $fields->{$_}{default_value}) } keys %$fields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->{$_} // $fields->{$_}{"default_value"}
MC/DC0%0/2
$item->{$_} // $fields->{$_}{"default_value"}
$item->{$_}
$fields->{$_}{"default_value"}
Truth table0%0/3
A // B
A= $item->{$_}B= $fields->{$_}{"default_value"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 97 | 24 | ▶ | die "found not an object" if ref($item) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
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"}
| |||||||||||||||||||||||||||||
| 102 | 22 | ▶ | my $value = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 111 | 9 | my @keys = keys %$item; | |||||||||||||||||||||||||||
| 112 | 9 | ▶ | die "OneOf Input Object '@{[$self->name]}' must specify exactly one key.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 124 | 30 | ▶ | die "found not an object" if ref($item) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
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"}
| |||||||||||||||||||||||||||||
| 130 | 22 | ▶ | my $raw = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | die "found not an object" if ref($item) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $item->{$key} or exists $fields->{$key}{"default_value"}
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"}
| |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $raw = exists $item->{$key} ? $item->{$key} : $fields->{$key}{default_value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 || {}
MC/DC0%0/1
$item || {}
$item
Truth table50%1/2
A
A= $item
| |||||||||||||||||||||||||||||
| 155 | 24 | ▶ | die join '', map qq{In field "$_": Unknown field.\n}, @unknown if @unknown; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 16 | return; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 14 | 1; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||