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