line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Type::Enum; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
1815
|
use 5.014; |
|
17
|
|
|
|
|
102
|
|
4
|
17
|
|
|
17
|
|
98
|
use strict; |
|
31
|
|
|
|
|
258
|
|
|
31
|
|
|
|
|
405
|
|
5
|
31
|
|
|
17
|
|
119
|
use warnings; |
|
30
|
|
|
|
|
79
|
|
|
30
|
|
|
|
|
710
|
|
6
|
18
|
|
|
17
|
|
124
|
use Moo; |
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
127
|
|
7
|
17
|
|
|
17
|
|
6512
|
use Types::Standard -all; |
|
17
|
|
|
|
|
57
|
|
|
17
|
|
|
|
|
137
|
|
8
|
17
|
|
|
17
|
|
806989
|
use GraphQL::Type::Library -all; |
|
17
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
146
|
|
9
|
17
|
|
|
17
|
|
238011
|
use GraphQL::Debug qw(_debug); |
|
17
|
|
|
|
|
47
|
|
|
17
|
|
|
|
|
1071
|
|
10
|
17
|
|
|
17
|
|
118
|
use GraphQL::MaybeTypeCheck; |
|
17
|
|
|
|
|
42
|
|
|
17
|
|
|
|
|
140
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends qw(GraphQL::Type); |
13
|
|
|
|
|
|
|
with qw( |
14
|
|
|
|
|
|
|
GraphQL::Role::Input |
15
|
|
|
|
|
|
|
GraphQL::Role::Output |
16
|
|
|
|
|
|
|
GraphQL::Role::Leaf |
17
|
|
|
|
|
|
|
GraphQL::Role::Nullable |
18
|
|
|
|
|
|
|
GraphQL::Role::Named |
19
|
|
|
|
|
|
|
GraphQL::Role::FieldDeprecation |
20
|
|
|
|
|
|
|
GraphQL::Role::FieldsEither |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
24
|
|
|
|
|
|
|
|
25
|
17
|
|
|
17
|
|
112
|
use constant DEBUG => $ENV{GRAPHQL_DEBUG}; |
|
17
|
|
|
|
|
42
|
|
|
17
|
|
|
|
|
5244
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
GraphQL::Type::Enum - GraphQL enum type |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use GraphQL::Type::Enum; |
34
|
|
|
|
|
|
|
my %text2value; |
35
|
|
|
|
|
|
|
my $type = GraphQL::Type::Enum->new( |
36
|
|
|
|
|
|
|
name => 'Enum', |
37
|
|
|
|
|
|
|
values => { value1 => {}, value2 => { value => 'yo' } }, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Has C<name>, C<description> from L<GraphQL::Role::Named>. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 values |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Hash-ref mapping value labels to a hash-ref description. Description keys, |
47
|
|
|
|
|
|
|
all optional: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item value |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Perl value of that item. If not specified, will be the string name of |
54
|
|
|
|
|
|
|
the value. Integers are often useful. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item deprecation_reason |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Reason if deprecated. If supplied, the hash for that value will also |
59
|
|
|
|
|
|
|
have a key C<is_deprecated> with a true value. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item description |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Description. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has values => ( |
70
|
|
|
|
|
|
|
is => 'ro', |
71
|
|
|
|
|
|
|
isa => Map[ |
72
|
|
|
|
|
|
|
StrNameValid, |
73
|
|
|
|
|
|
|
Dict[ |
74
|
|
|
|
|
|
|
value => Optional[Any], |
75
|
|
|
|
|
|
|
deprecation_reason => Optional[Str], |
76
|
|
|
|
|
|
|
description => Optional[Str], |
77
|
|
|
|
|
|
|
] |
78
|
|
|
|
|
|
|
], |
79
|
|
|
|
|
|
|
required => 1, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 is_valid |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
True if given Perl entity is valid value for this type. Relies on unique |
87
|
|
|
|
|
|
|
stringification of the value. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
has _name2value => (is => 'lazy', isa => Map[StrNameValid, Any]); |
92
|
|
|
|
|
|
|
sub _build__name2value { |
93
|
11
|
|
|
11
|
|
152
|
my ($self) = @_; |
94
|
11
|
|
|
|
|
43
|
my $v = $self->values; |
95
|
11
|
|
|
|
|
58
|
+{ map { ($_ => $v->{$_}{value}) } keys %$v }; |
|
74
|
|
|
|
|
398
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has _value2name => (is => 'lazy', isa => Map[Str, StrNameValid]); |
99
|
|
|
|
|
|
|
sub _build__value2name { |
100
|
8
|
|
|
8
|
|
132
|
my ($self) = @_; |
101
|
8
|
|
|
|
|
148
|
my $n2v = $self->_name2value; |
102
|
8
|
|
|
|
|
724
|
DEBUG and _debug('_build__value2name', $self, $n2v); |
103
|
8
|
|
|
|
|
191
|
+{ reverse %$n2v }; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
1
|
50
|
|
1
|
1
|
524
|
method is_valid(Any $item) :ReturnType(Bool) { |
|
1
|
50
|
|
|
|
5
|
|
|
1
|
50
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
56
|
|
107
|
1
|
|
|
|
|
3
|
DEBUG and _debug('is_valid', $item, $item.'', $self->_value2name); |
108
|
1
|
100
|
|
|
|
3
|
return 1 if !defined $item; |
109
|
1
|
|
|
|
|
22
|
!!$self->_value2name->{$item}; |
110
|
17
|
|
|
17
|
|
3459
|
} |
|
17
|
|
|
|
|
47
|
|
|
17
|
|
|
|
|
135
|
|
111
|
|
|
|
|
|
|
|
112
|
14
|
50
|
|
14
|
1
|
43
|
method graphql_to_perl(Maybe[Str | ScalarRef] $item) { |
|
14
|
50
|
|
|
|
44
|
|
|
14
|
50
|
|
|
|
25
|
|
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
37
|
|
|
247
|
|
|
|
|
543
|
|
113
|
247
|
|
|
|
|
540
|
DEBUG and _debug('graphql_to_perl', $item, $self->_name2value); |
114
|
247
|
50
|
|
|
|
361
|
return undef if !defined $item; |
115
|
247
|
50
|
|
|
|
464
|
$item = $$$item if ref($item) eq 'REF'; # Handle unquoted enum values |
116
|
247
|
|
66
|
|
|
509
|
$self->_name2value->{$item} // die "Expected type '@{[$self->to_string]}', found $item.\n"; |
|
247
|
|
|
|
|
1468
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
247
|
50
|
|
247
|
1
|
312
|
method perl_to_graphql(Any $item) { |
|
247
|
100
|
|
|
|
457
|
|
|
247
|
50
|
|
|
|
5377
|
|
|
2
|
|
|
|
|
76
|
|
|
2
|
|
|
|
|
71
|
|
|
52
|
|
|
|
|
164487
|
|
120
|
52
|
|
|
|
|
275
|
DEBUG and _debug('perl_to_graphql', $item, $self->_value2name); |
121
|
52
|
|
|
|
|
199
|
return undef if !defined $item; |
122
|
52
|
|
66
|
|
|
182
|
$self->_value2name->{$item} // die "Expected a value of type '@{[$self->to_string]}' but received: @{[ref($item)||qq{'$item'}]}.\n"; |
|
479
|
|
|
|
|
1222
|
|
|
6
|
|
|
|
|
537
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 BUILD |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Internal method. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub BUILD { |
132
|
6
|
|
|
52
|
1
|
20
|
my ($self, $args) = @_; |
133
|
6
|
|
|
|
|
22
|
$self->_fields_deprecation_apply('values'); |
134
|
11
|
|
|
|
|
43
|
my $v = $self->values; |
135
|
6
|
|
|
|
|
26
|
for my $name (keys %$v) { |
136
|
6
|
|
|
|
|
182
|
$v->{$name}{value} = $name if !exists $v->{$name}{value}; # undef valid |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
method from_ast( |
141
|
|
|
|
|
|
|
HashRef $name2type, |
142
|
|
|
|
|
|
|
HashRef $ast_node, |
143
|
10
|
100
|
|
10
|
1
|
42
|
) :ReturnType(InstanceOf[__PACKAGE__]) { |
|
10
|
50
|
|
|
|
31
|
|
|
10
|
50
|
|
|
|
18
|
|
|
10
|
50
|
|
|
|
24
|
|
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
107
|
|
|
10
|
|
|
|
|
69
|
|
144
|
10
|
|
|
|
|
21
|
my $values = +{ %{$ast_node->{values}} }; |
|
10
|
|
|
|
|
49
|
|
145
|
10
|
|
|
|
|
65
|
$values = $self->_from_ast_field_deprecate($_, $values) for keys %$values; |
146
|
10
|
|
|
|
|
55
|
$self->new( |
147
|
|
|
|
|
|
|
$self->_from_ast_named($ast_node), |
148
|
|
|
|
|
|
|
values => $values, |
149
|
|
|
|
|
|
|
); |
150
|
17
|
|
|
17
|
|
56689
|
} |
|
17
|
|
|
|
|
46
|
|
|
17
|
|
|
|
|
102
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
has to_doc => (is => 'lazy', isa => Str); |
153
|
|
|
|
|
|
|
sub _build_to_doc { |
154
|
|
|
|
6
|
|
|
my ($self) = @_; |
155
|
|
|
|
|
|
|
my $v = $self->values; |
156
|
|
|
|
|
|
|
my @valuelines = map { |
157
|
|
|
|
|
|
|
( |
158
|
|
|
|
|
|
|
$self->_description_doc_lines($v->{$_}{description}), |
159
|
|
|
|
|
|
|
$self->_to_doc_field_deprecate($_, $v->{$_}), |
160
|
|
|
|
|
|
|
) |
161
|
|
|
|
|
|
|
} sort keys %$v; |
162
|
|
|
|
|
|
|
join '', map "$_\n", |
163
|
|
|
|
|
|
|
$self->_description_doc_lines($self->description), |
164
|
|
|
|
|
|
|
"enum @{[$self->name]} {", |
165
|
|
|
|
|
|
|
(map length() ? " $_" : "", @valuelines), |
166
|
|
|
|
|
|
|
"}"; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |