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

filter: Statementstmt 95.4% 83 / 87 Branchbran 64.2% 18 / 28 Conditioncond 47.6% 10 / 21 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 91.6% 22 / 24 Podpod 0.0% 0 / 13 totaltotal 72.0% 134 / 186 CC 23 SCAR 14.9
CC
23
Cov
82%
get_types
10.6
_validate_member_types
7.1
non_null
6.0
CRAP 4.4
« blib/lib/GraphQL/Houtou/Type/Enum.pm ↑ Summary blib/lib/GraphQL/Houtou/Internal/TypeSupport.pm »
1 package GraphQL::Houtou::Type::Union;
2  
3 13 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use parent 'GraphQL::Houtou::Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use GraphQL::Houtou::Type::List ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use GraphQL::Houtou::Type::NonNull ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 with qw(
13 GraphQL::Houtou::Role::Output
14 GraphQL::Houtou::Role::Composite
15 GraphQL::Houtou::Role::Abstract
16 GraphQL::Houtou::Role::Named
17 );
18  
19 9 ▶sub list {
Subroutine list: called CC=2 SCAR=9.2
Pod undocumented
20 9 ▶ $_[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
090
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 0 ▶sub non_null {
Subroutine non_null: not called CC=2 SCAR=17.9
Pod undocumented
24 0 ▶ $_[0]->{_houtou_non_null} ||= GraphQL::Houtou::Type::NonNull->new(of => $_[0]);
Condition0%0/3
$_[0]{"_houtou_non_null"} ||= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
l!l&&r!l&&!r
000
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 table0%0/3
A ||= B
A= $_[0]{"_houtou_non_null"}B= "GraphQL::Houtou::Type::NonNull"->new("of", $_[0])
ABresult
1X1
011
000
25 }
26  
27 13 ▶use constant DEBUG => $ENV{GRAPHQL_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 24 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
30 24 my ($class, %args) = @_;
31 24 ▶ die "GraphQL::Houtou::Type::Union requires name" if !defined $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"name"} 0 24 24
32 24 ▶ die "GraphQL::Houtou::Type::Union requires types" if !exists $args{types};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"types"} 0 24 24
33 24 my $types = $args{types};
34 24 ▶ _validate_member_types($types) if ref($types) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $types ne "CODE" 12 12 24
35 24 my $self = $class->SUPER::new(%args);
36 24 $self->{name} = $args{name};
37 24 $self->{description} = $args{description};
38 24 $self->{types} = $types;
39 24 $self->{resolve_type} = $args{resolve_type};
40 24 $self->{tag_resolver} = $args{tag_resolver};
41 24 $self->{tag_map} = $args{tag_map};
42 24 $self->{_types_validated} = 0;
43 24 return $self;
44 }
45  
46 363 ▶sub name { return $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
47 94 ▶sub description { return $_[0]->{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod undocumented
48 185 ▶sub to_string { return $_[0]->{to_string} ||= $_[0]->name }
Subroutine to_string: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0]{"to_string"} ||= $_[0]->name
l!l&&r!l&&!r
169160
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
49 24 ▶sub _validate_member_types {
Subroutine _validate_member_types: called CC=6 SCAR=19.6
50 24 my ($types) = @_;
51 24 ▶ die "GraphQL::Houtou::Type::Union requires a non-empty types array"
Branch: 1 branch
BranchTrueFalseTotal
if ref $types ne "ARRAY" or not @$types 0 24 24
Condition33%1/3
ref $types ne "ARRAY" or not @$types
l!l&&r!l&&!r
0024
MC/DC0%0/2
ref $types ne "ARRAY" or not @$types
ref $types ne "ARRAY" not @$types
Truth table33%1/3
A or not(B)
A= ref $types ne "ARRAY"B= not @$types
ABresult
1X1
011
000
52 if ref($types) ne 'ARRAY' || !@$types;
53 24 my %seen;
54 24 for my $type (@$types) {
55 30 ▶ die "GraphQL::Houtou::Type::Union requires object types" if !ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 0 30 30
56 30 ▶ die "Duplicate union member " . $type->name if $seen{$type->name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$type->name}++ 0 30 30
57 }
58 24 return;
59 }
60  
61 244 ▶sub types {
Subroutine types: called CC=2 SCAR=6.9
Pod undocumented
62 244 my ($self) = @_;
63 244 ▶ if (ref($self->{types}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"types"} eq "CODE") 12 232 244
64 12 my $types = $self->{types}->();
65 12 _validate_member_types($types);
66 12 $self->{types} = $types;
67 }
68 244 return $self->{types};
69 }
70  
71 12 ▶sub from_ast {
Subroutine from_ast: called CC=1 SCAR=0.2
Pod undocumented
72 12 my ($class, $name2type, $ast_node) = @_;
73 12 require GraphQL::Houtou::Internal::TypeSupport;
74 return $class->new(
75 GraphQL::Houtou::Internal::TypeSupport::named_from_ast($ast_node),
76 GraphQL::Houtou::Internal::TypeSupport::from_ast_maptype($name2type, $ast_node, 'types'),
77 # SDL carries no dispatch logic; replace via the resolvers option of
78 # Schema->from_doc (resolve_type / tag_resolver) before executing
79 # queries that hit this union.
80 0 ▶ resolve_type => sub { return },
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 12 );
82 }
83 131 ▶sub resolve_type { return $_[0]->{resolve_type} }
Subroutine resolve_type: called CC=1 SCAR=0.0
Pod undocumented
84 28 ▶sub tag_resolver { return $_[0]->{tag_resolver} }
Subroutine tag_resolver: called CC=1 SCAR=0.0
Pod undocumented
85 18 ▶sub tag_map { return $_[0]->{tag_map} }
Subroutine tag_map: called CC=1 SCAR=0.0
Pod undocumented
86 229 ▶sub _types_validated {
Subroutine _types_validated: called CC=2 SCAR=6.9
87 229 my ($self, @set) = @_;
88 229 ▶ $self->{_types_validated} = $set[0] if @set;
Branch: 1 branch
BranchTrueFalseTotal
if @set 24 205 229
89 229 return $self->{_types_validated};
90 }
91  
92 205 ▶sub get_types {
Subroutine get_types: called CC=9 SCAR=23.6
Pod undocumented
93 205 my ($self) = @_;
94 205 my @types = @{ $self->types };
95 205 ▶ return \@types if $self->_types_validated;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_types_validated 181 24 205
96  
97 24 $self->_types_validated(1);
98 my @non_object = grep {
99 24 ▶ !ref($_)
Condition66%4/6
ref $_ && ($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object'))
!ll&&!rl&&r
0129
$_->isa("GraphQL::Houtou::Type::Object") or $_->isa("GraphQL::Type::Object")
l!l&&r!l&&!r
2901
MC/DC33%1/3
ref $_ && ($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object'))
ref $_ $_->isa("GraphQL::Houtou::Type::Object") $_->isa("GraphQL::Type::Object")
Truth table50%2/4
A && B or C
A= ref $_B= $_->isa("GraphQL::Houtou::Type::Object")C= $_->isa("GraphQL::Type::Object")
ABCresult
0XX0
1000
11X1
1011
100 || !($_->isa('GraphQL::Houtou::Type::Object') || $_->isa('GraphQL::Type::Object'))
101 } @types;
102 1 die "Union type @{[$self->name]} can only include Object types, found "
103 24 ▶ . join(', ', map { ref($_) ? $_->to_string : "'$_'" } @non_object) . ".\n"
Branch: 2 branches
BranchTrueFalseTotal
if @non_object 1 23 24
ref $_ ? : 1 0 1
104 if @non_object;
105 23 ▶ if (!$self->resolve_type && !$self->tag_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->resolve_type or $self->tag_resolver) 0 23 23
Condition66%2/3
$self->resolve_type or $self->tag_resolver
l!l&&r!l&&!r
13100
MC/DC0%0/2
$self->resolve_type or $self->tag_resolver
$self->resolve_type $self->tag_resolver
Truth table66%2/3
A or B
A= $self->resolve_typeB= $self->tag_resolver
ABresult
1X1
011
000
106 0 my @bad = map $_->name, grep !$_->is_type_of, @types;
107 0 ▶ die $self->name . " no resolve_type and no is_type_of for @bad" if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 0 0 0
108 }
109 23 return \@types;
110 }
111  
112 3 ▶sub to_doc {
Subroutine to_doc: called CC=2 SCAR=7.0
Pod undocumented
113 3 my ($self) = @_;
114 3 ▶ return $self->{to_doc} if exists $self->{to_doc};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"to_doc"} 0 3 3
115 3 require GraphQL::Houtou::Internal::TypeSupport;
116 return $self->{to_doc} = join '', map "$_\n",
117 GraphQL::Houtou::Internal::TypeSupport::description_doc_lines($self->description),
118 3 "union @{[$self->name]} = " . join(' | ', map $_->name, @{ $self->types });
119 }
120  
121 13 1;
122  
123 __END__
« blib/lib/GraphQL/Houtou/Type/Enum.pm ↑ Summary blib/lib/GraphQL/Houtou/Internal/TypeSupport.pm »