line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Type::Enum; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
1729
|
use 5.014; |
|
17
|
|
|
|
|
64
|
|
4
|
17
|
|
|
17
|
|
94
|
use strict; |
|
31
|
|
|
|
|
235
|
|
|
31
|
|
|
|
|
420
|
|
5
|
31
|
|
|
17
|
|
119
|
use warnings; |
|
30
|
|
|
|
|
68
|
|
|
30
|
|
|
|
|
699
|
|
6
|
18
|
|
|
17
|
|
105
|
use Moo; |
|
17
|
|
|
|
|
37
|
|
|
17
|
|
|
|
|
111
|
|
7
|
17
|
|
|
17
|
|
6636
|
use Types::Standard -all; |
|
17
|
|
|
|
|
52
|
|
|
17
|
|
|
|
|
168
|
|
8
|
17
|
|
|
17
|
|
752331
|
use GraphQL::Type::Library -all; |
|
17
|
|
|
|
|
55
|
|
|
17
|
|
|
|
|
187
|
|
9
|
17
|
|
|
17
|
|
224072
|
use GraphQL::Debug qw(_debug); |
|
17
|
|
|
|
|
46
|
|
|
17
|
|
|
|
|
1128
|
|
10
|
17
|
|
|
17
|
|
126
|
use GraphQL::MaybeTypeCheck; |
|
17
|
|
|
|
|
38
|
|
|
17
|
|
|
|
|
163
|
|
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
|
|
110
|
use constant DEBUG => $ENV{GRAPHQL_DEBUG}; |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
5069
|
|
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
|
|
149
|
my ($self) = @_; |
94
|
11
|
|
|
|
|
44
|
my $v = $self->values; |
95
|
11
|
|
|
|
|
57
|
+{ map { ($_ => $v->{$_}{value}) } keys %$v }; |
|
74
|
|
|
|
|
376
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has _value2name => (is => 'lazy', isa => Map[Str, StrNameValid]); |
99
|
|
|
|
|
|
|
sub _build__value2name { |
100
|
8
|
|
|
8
|
|
105
|
my ($self) = @_; |
101
|
8
|
|
|
|
|
127
|
my $n2v = $self->_name2value; |
102
|
8
|
|
|
|
|
576
|
DEBUG and _debug('_build__value2name', $self, $n2v); |
103
|
8
|
|
|
|
|
155
|
+{ reverse %$n2v }; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
1
|
50
|
|
1
|
1
|
900
|
method is_valid(Any $item) :ReturnType(Bool) { |
|
1
|
50
|
|
|
|
4
|
|
|
1
|
50
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
71
|
|
107
|
1
|
|
|
|
|
2
|
DEBUG and _debug('is_valid', $item, $item.'', $self->_value2name); |
108
|
1
|
100
|
|
|
|
3
|
return 1 if !defined $item; |
109
|
1
|
|
|
|
|
21
|
!!$self->_value2name->{$item}; |
110
|
17
|
|
|
17
|
|
3438
|
} |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
182
|
|
111
|
|
|
|
|
|
|
|
112
|
14
|
50
|
|
14
|
1
|
38
|
method graphql_to_perl(Maybe[Str | ScalarRef] $item) { |
|
14
|
50
|
|
|
|
70
|
|
|
14
|
50
|
|
|
|
36
|
|
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
55
|
|
|
247
|
|
|
|
|
607
|
|
113
|
247
|
|
|
|
|
494
|
DEBUG and _debug('graphql_to_perl', $item, $self->_name2value); |
114
|
247
|
50
|
|
|
|
355
|
return undef if !defined $item; |
115
|
247
|
50
|
|
|
|
565
|
$item = $$$item if ref($item) eq 'REF'; # Handle unquoted enum values |
116
|
247
|
|
66
|
|
|
595
|
$self->_name2value->{$item} // die "Expected type '@{[$self->to_string]}', found $item.\n"; |
|
247
|
|
|
|
|
1386
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
247
|
50
|
|
247
|
1
|
328
|
method perl_to_graphql(Any $item) { |
|
247
|
100
|
|
|
|
507
|
|
|
247
|
50
|
|
|
|
5338
|
|
|
2
|
|
|
|
|
48
|
|
|
2
|
|
|
|
|
97
|
|
|
52
|
|
|
|
|
153964
|
|
120
|
52
|
|
|
|
|
295
|
DEBUG and _debug('perl_to_graphql', $item, $self->_value2name); |
121
|
52
|
|
|
|
|
202
|
return undef if !defined $item; |
122
|
52
|
|
66
|
|
|
161
|
$self->_value2name->{$item} // die "Expected a value of type '@{[$self->to_string]}' but received: @{[ref($item)||qq{'$item'}]}.\n"; |
|
479
|
|
|
|
|
1452
|
|
|
6
|
|
|
|
|
631
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 BUILD |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Internal method. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub BUILD { |
132
|
6
|
|
|
52
|
1
|
28
|
my ($self, $args) = @_; |
133
|
6
|
|
|
|
|
31
|
$self->_fields_deprecation_apply('values'); |
134
|
11
|
|
|
|
|
82
|
my $v = $self->values; |
135
|
6
|
|
|
|
|
34
|
for my $name (keys %$v) { |
136
|
6
|
|
|
|
|
215
|
$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
|
|
|
|
38
|
|
|
10
|
50
|
|
|
|
23
|
|
|
10
|
50
|
|
|
|
27
|
|
|
10
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
101
|
|
|
10
|
|
|
|
|
66
|
|
144
|
10
|
|
|
|
|
19
|
my $values = +{ %{$ast_node->{values}} }; |
|
10
|
|
|
|
|
51
|
|
145
|
10
|
|
|
|
|
78
|
$values = $self->_from_ast_field_deprecate($_, $values) for keys %$values; |
146
|
10
|
|
|
|
|
66
|
$self->new( |
147
|
|
|
|
|
|
|
$self->_from_ast_named($ast_node), |
148
|
|
|
|
|
|
|
values => $values, |
149
|
|
|
|
|
|
|
); |
150
|
17
|
|
|
17
|
|
56287
|
} |
|
17
|
|
|
|
|
94
|
|
|
17
|
|
|
|
|
106
|
|
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; |