GraphQL/Type/Scalar.pm

filter: Statementstmt 96.9% 128 / 132 Branchbran 59.5% 25 / 42 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 94.2% 33 / 35 Podpod 100% 4 / 4 totaltotal 86.5% 193 / 223 CC 24 SCAR 9.5
CC
24
Cov
87%
__ANON__
6.0
from_ast
5.2
__ANON__
4.2
CRAP 2.6
« GraphQL/Type/NonNull.pm ↑ Summary GraphQL/Type/Interface.pm »
1 package GraphQL::Type::Scalar;
2  
3 18 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use GraphQL::Type::Library -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use GraphQL::Debug qw(_debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Types::Standard -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use JSON::MaybeXS qw(JSON is_bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 extends qw(GraphQL::Type);
13 18 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::FieldsEither
20 );
21 18 ▶use GraphQL::MaybeTypeCheck;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶use GraphQL::Plugin::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 18 our $VERSION = '0.02';
25 18 our @EXPORT_OK = qw($Int $Float $String $Boolean $ID);
26  
27 18 ▶use constant DEBUG => $ENV{GRAPHQL_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 my $JSON = JSON::MaybeXS->new->allow_nonref->canonical;
29  
30 =head1 NAME
31  
32 GraphQL::Type::Scalar - GraphQL scalar type
33  
34 =head1 SYNOPSIS
35  
36 use GraphQL::Type::Scalar;
37 my $int_type = GraphQL::Type::Scalar->new(
38 name => 'Int',
39 description =>
40 'The `Int` scalar type represents non-fractional signed whole numeric ' .
41 'values. Int can represent values between -(2^31) and 2^31 - 1. ',
42 serialize => \&coerce_int,
43 parse_value => \&coerce_int,
44 );
45  
46 =head1 ATTRIBUTES
47  
48 Has C<name>, C<description> from L<GraphQL::Role::Named>.
49  
50 =head2 serialize
51  
52 Code-ref. Required.
53  
54 Coerces
55 B<from> a Perl entity of the required type,
56 B<to> a GraphQL entity,
57 or throws an exception.
58  
59 Must throw an exception if passed a defined (i.e. non-null) but invalid
60 Perl object of the relevant type. C<undef> must always be valid.
61  
62 =cut
63  
64 18 has serialize => (is => 'ro', isa => CodeRef, required => 1);
65  
66 =head2 parse_value
67  
68 Code-ref. Required if is for an input type.
69  
70 Coerces
71 B<from> a GraphQL entity,
72 B<to> a Perl entity of the required type,
73 or throws an exception.
74  
75 =cut
76  
77 18 has parse_value => (is => 'ro', isa => CodeRef);
78  
79 =head1 METHODS
80  
81 =head2 is_valid
82  
83 True if given Perl entity is valid value for this type. Uses L</serialize>
84 attribute.
85  
86 =cut
87  
88 31 ▶method is_valid(Any $item) :ReturnType(Bool) {
Subroutine is_valid: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method is_valid (expected 2, got ' . @_ . ')') 0 31 31
@_ > 2 and Function::Parameters::_croak('Too many arguments for method is_valid (expected 2, got ' . @_ . ')') 0 31 31
89 31 ▶ return 1 if !defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 31 31
90 31 eval { $self->serialize->($item); 1 };
91 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 222 ▶method graphql_to_perl(Any $item) :ReturnType(Any) {
Subroutine graphql_to_perl: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method graphql_to_perl (expected 2, got ' . @_ . ')') 0 222 222
@_ > 2 and Function::Parameters::_croak('Too many arguments for method graphql_to_perl (expected 2, got ' . @_ . ')') 0 222 222
94 222 $self->parse_value->($item);
95 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 875 ▶method perl_to_graphql(Any $item) :ReturnType(Any) {
Subroutine perl_to_graphql: called CC=3 SCAR=11.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method perl_to_graphql (expected 2, got ' . @_ . ')') 0 875 875
@_ > 2 and Function::Parameters::_croak('Too many arguments for method perl_to_graphql (expected 2, got ' . @_ . ')') 0 875 875
98 875 $self->serialize->($item);
99 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 2 ▶method from_ast(
Subroutine from_ast: called CC=5 SCAR=16.4
Pod documented
102 HashRef $name2type,
103 HashRef $ast_node,
104 2 ▶) :ReturnType(InstanceOf[__PACKAGE__]) {
Branch: 4 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method from_ast (expected 3, got ' . @_ . ')') 0 2 2
@_ > 3 and Function::Parameters::_croak('Too many arguments for method from_ast (expected 3, got ' . @_ . ')') 0 2 2
Ref::Util::XS::is_plain_hashref($name2type) or Function::Parameters::_croak('In method from_ast: parameter 1 ($name2type): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_HashRef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"coercion_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; my($parent, $child, $param) = @_; return unless $param->has_coercion; my $coercable_item = $param->coercion->_source_type_union; my $C = 'Type::Coercion'->new('type_constraint', $child); if ($param->coercion->can_be_inlined and $coercable_item->can_be_inlined) { $C->add_type_coercions($parent, &Types::Standard::Stringable(sub { my @code; push @code, 'do { my ($orig, $return_orig, %new) = ($_, 0);'; push @code, 'for (keys %$orig) {'; push @code, sprintf('$return_orig++ && last unless (%s);', $coercable_item->inline_check('$orig->{$_}')); push @code, sprintf('$new{$_} = (%s);', $param->coercion->inline_coercion('$orig->{$_}')); push @code, '}'; push @code, '$return_orig ? $orig : \\%new'; push @code, '}'; join $", @code; } )); } else { $C->add_type_coercions($parent, sub { my $value = @_ ? $_[0] : $_; my %new; foreach my $k (keys %$value) { return $value unless $coercable_item->check($value->{$k}); $new{$k} = $param->coerce($value->{$k}); } return \%new; } ); } return $C;},"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_ eq 'HASH';},"constraint_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; return &Types::Standard::HashRef() unless @_; require Error::TypeTiny::WrongNumberOfParameters; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'HashRef', \@_, 1); my $param = shift(); Types::TypeTiny::is_TypeTiny($param) or _croak "Parameter to HashRef[`a] expected to be a type constraint; got $param"; my $param_compiled_check = $param->compiled_check; my $xsub; do { my $paramname = Type::Tiny::XS::is_known($param_compiled_check); $xsub = Type::Tiny::XS::get_coderef_for("HashRef[$paramname]") if $paramname }; return sub { my $hash = shift(); ($param->check($_) or return) foreach (values %$hash); return !0; } , $xsub;},"deep_explanation" => sub { package Types::Standard::HashRef; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; foreach my $k (sort keys %$value) { my $item = $value->{$k}; next if $param->check($item); return [sprintf('"%s" constrains each value in the hash with "%s"', $type, $param), @{$param->validate_explain($item, sprintf('%s->{%s}', $varname, B::perlstring($k)));}]; } return;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 544,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "HashRef","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; my $param = shift(); my $compiled = $param->compiled_check; my $xsubname; unless ($Type::Tiny::AvoidCallbacks) { my $paramname = Type::Tiny::XS::is_known($compiled); $xsubname = Type::Tiny::XS::get_subname_for("HashRef[$paramname]"); } return unless $param->can_be_inlined; return sub { my $v = $_[1]; return "$xsubname($v)" if $xsubname and not $Type::Tiny::AvoidCallbacks; my $p = &Types::Standard::HashRef()->inline_check($v); my $param_check = $param->inline_check('$i'); "$p and do { " . 'my $ok = 1; ' . "for my \$i (values %{$v}) { " . "(\$ok = 0, last) unless $param_check " . '}; ' . '$ok ' . '}'; } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_plain_hashref($_[1])" : "ref($_[1]) eq 'HASH'";},"library" => "Types::Standard","my_methods" => {"hashref_allows_key" => sub { package Types::Standard::HashRef; no warnings; use strict; my $self = shift(); Types::Standard::is_Str($_[0]);},"hashref_allows_value" => sub { package Types::Standard::HashRef; no warnings; use strict; my $self = shift(); my($key, $value) = @_; return !1 unless $self->my_hashref_allows_key($key); return !0 if $self == &Types::Standard::HashRef(); my $href = $self->find_parent(sub { $_->has_parent and $_->parent == &Types::Standard::HashRef(); } ); my $param = $href->type_parameter; Types::Standard::is_Str($key) and $param->check($value);}},"name" => "HashRef","name_generator" => sub { package Type::Tiny; use warnings; use strict; defined $_ and s/[\x00-\x1F]//gms foreach (my($s, @a) = @_); sprintf '%s[%s]', $s, join(',', map((!defined($_) ? 'undef' : (!ref($_) && /\W/ ? B::perlstring($_) : $_)), @a));},"parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; not ref $_[0] and _failed_check(16, 'Ref', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Ref","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_;},"constraint_generator" => sub { package Types::Standard; no warnings; use strict; return $meta->get_type('Ref') unless @_; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'Ref', \@_, 1); my $reftype = shift(); $reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or _croak "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype"; $reftype = "$reftype"; return sub { ref $_[0] and builtin::reftype($_[0]) eq $reftype; } ;},"deep_explanation" => sub { package Types::Standard; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; return if $type->check($value); my $reftype = builtin::reftype($value); return [sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)), sprintf('reftype(%s) is %s', $varname, defined $reftype ? B::perlstring($reftype) : 'undef')];},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 438,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Ref","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard; no warnings; use strict; my $reftype = shift(); return sub { my $v = $_[1]; &$maybe_load_modules('Scalar::Util', "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"); } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; "!!ref($_[1])";},"library" => "Types::Standard","name" => "Ref","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 16}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return {};},"type_default_generator" => sub { package Types::Standard; no warnings; use strict; return $Type::Tiny::parameterize_type->type_default if @_ < 2; return undef;},"uniq" => 22}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($name2type)) 2 0 2
Ref::Util::XS::is_plain_hashref($ast_node) or Function::Parameters::_croak('In method from_ast: parameter 2 ($ast_node): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_HashRef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"coercion_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; my($parent, $child, $param) = @_; return unless $param->has_coercion; my $coercable_item = $param->coercion->_source_type_union; my $C = 'Type::Coercion'->new('type_constraint', $child); if ($param->coercion->can_be_inlined and $coercable_item->can_be_inlined) { $C->add_type_coercions($parent, &Types::Standard::Stringable(sub { my @code; push @code, 'do { my ($orig, $return_orig, %new) = ($_, 0);'; push @code, 'for (keys %$orig) {'; push @code, sprintf('$return_orig++ && last unless (%s);', $coercable_item->inline_check('$orig->{$_}')); push @code, sprintf('$new{$_} = (%s);', $param->coercion->inline_coercion('$orig->{$_}')); push @code, '}'; push @code, '$return_orig ? $orig : \\%new'; push @code, '}'; join $", @code; } )); } else { $C->add_type_coercions($parent, sub { my $value = @_ ? $_[0] : $_; my %new; foreach my $k (keys %$value) { return $value unless $coercable_item->check($value->{$k}); $new{$k} = $param->coerce($value->{$k}); } return \%new; } ); } return $C;},"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_ eq 'HASH';},"constraint_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; return &Types::Standard::HashRef() unless @_; require Error::TypeTiny::WrongNumberOfParameters; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'HashRef', \@_, 1); my $param = shift(); Types::TypeTiny::is_TypeTiny($param) or _croak "Parameter to HashRef[`a] expected to be a type constraint; got $param"; my $param_compiled_check = $param->compiled_check; my $xsub; do { my $paramname = Type::Tiny::XS::is_known($param_compiled_check); $xsub = Type::Tiny::XS::get_coderef_for("HashRef[$paramname]") if $paramname }; return sub { my $hash = shift(); ($param->check($_) or return) foreach (values %$hash); return !0; } , $xsub;},"deep_explanation" => sub { package Types::Standard::HashRef; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; foreach my $k (sort keys %$value) { my $item = $value->{$k}; next if $param->check($item); return [sprintf('"%s" constrains each value in the hash with "%s"', $type, $param), @{$param->validate_explain($item, sprintf('%s->{%s}', $varname, B::perlstring($k)));}]; } return;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 544,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "HashRef","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard::HashRef; no warnings; use strict; my $param = shift(); my $compiled = $param->compiled_check; my $xsubname; unless ($Type::Tiny::AvoidCallbacks) { my $paramname = Type::Tiny::XS::is_known($compiled); $xsubname = Type::Tiny::XS::get_subname_for("HashRef[$paramname]"); } return unless $param->can_be_inlined; return sub { my $v = $_[1]; return "$xsubname($v)" if $xsubname and not $Type::Tiny::AvoidCallbacks; my $p = &Types::Standard::HashRef()->inline_check($v); my $param_check = $param->inline_check('$i'); "$p and do { " . 'my $ok = 1; ' . "for my \$i (values %{$v}) { " . "(\$ok = 0, last) unless $param_check " . '}; ' . '$ok ' . '}'; } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_plain_hashref($_[1])" : "ref($_[1]) eq 'HASH'";},"library" => "Types::Standard","my_methods" => {"hashref_allows_key" => sub { package Types::Standard::HashRef; no warnings; use strict; my $self = shift(); Types::Standard::is_Str($_[0]);},"hashref_allows_value" => sub { package Types::Standard::HashRef; no warnings; use strict; my $self = shift(); my($key, $value) = @_; return !1 unless $self->my_hashref_allows_key($key); return !0 if $self == &Types::Standard::HashRef(); my $href = $self->find_parent(sub { $_->has_parent and $_->parent == &Types::Standard::HashRef(); } ); my $param = $href->type_parameter; Types::Standard::is_Str($key) and $param->check($value);}},"name" => "HashRef","name_generator" => sub { package Type::Tiny; use warnings; use strict; defined $_ and s/[\x00-\x1F]//gms foreach (my($s, @a) = @_); sprintf '%s[%s]', $s, join(',', map((!defined($_) ? 'undef' : (!ref($_) && /\W/ ? B::perlstring($_) : $_)), @a));},"parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; not ref $_[0] and _failed_check(16, 'Ref', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Ref","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_;},"constraint_generator" => sub { package Types::Standard; no warnings; use strict; return $meta->get_type('Ref') unless @_; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'Ref', \@_, 1); my $reftype = shift(); $reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or _croak "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype"; $reftype = "$reftype"; return sub { ref $_[0] and builtin::reftype($_[0]) eq $reftype; } ;},"deep_explanation" => sub { package Types::Standard; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; return if $type->check($value); my $reftype = builtin::reftype($value); return [sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)), sprintf('reftype(%s) is %s', $varname, defined $reftype ? B::perlstring($reftype) : 'undef')];},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 438,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Ref","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard; no warnings; use strict; my $reftype = shift(); return sub { my $v = $_[1]; &$maybe_load_modules('Scalar::Util', "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"); } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; "!!ref($_[1])";},"library" => "Types::Standard","name" => "Ref","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 16}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return {};},"type_default_generator" => sub { package Types::Standard; no warnings; use strict; return $Type::Tiny::parameterize_type->type_default if @_ < 2; return undef;},"uniq" => 22}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($ast_node)) 2 0 2
105 2 DEBUG and _debug('Scalar.from_ast', $ast_node);
106 $self->new(
107 $self->_from_ast_named($ast_node),
108 1 ▶ serialize => sub { require Carp; Carp::croak "Fake serialize called" },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 1 ▶ parse_value => sub { require Carp; Carp::croak "Fake parse_value called" },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 2 );
111 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 18 has to_doc => (is => 'lazy', isa => Str);
114 2 ▶sub _build_to_doc {
Subroutine _build_to_doc: called CC=1 SCAR=0.0
115 2 my ($self) = @_;
116 2 DEBUG and _debug('Scalar.to_doc', $self);
117 2 join '', map "$_\n",
118 $self->_description_doc_lines($self->description),
119 2 "scalar @{[$self->name]}";
120 }
121  
122 =head1 EXPORTED VARIABLES
123  
124 =head2 $Int
125  
126 =cut
127  
128 180 ▶sub _leave_undef {
Subroutine _leave_undef: called CC=1 SCAR=0.0
129 180 my ($closure) = @_;
130 180 ▶ sub { return undef if !defined $_[0]; goto &$closure; };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 27 1100 1127
131 }
132  
133 our $Int = GraphQL::Type::Scalar->new(
134 name => 'Int',
135 description =>
136 'The `Int` scalar type represents non-fractional signed whole numeric ' .
137 'values. Int can represent values between -(2^31) and 2^31 - 1.',
138 77 ▶ serialize => _leave_undef(sub { !is_Int32Signed($_[0]) and die "Not an Int.\n"; $_[0]+0 }),
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&is_Int32Signed($_[0]) or die "Not an Int.\n" 72 5 77
139 22 ▶ parse_value => _leave_undef(sub { !is_Int32Signed($_[0]) and die "Not an Int.\n"; $_[0]+0 }),
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&is_Int32Signed($_[0]) or die "Not an Int.\n" 21 1 22
140 );
141  
142 =head2 $Float
143  
144 =cut
145  
146 our $Float = GraphQL::Type::Scalar->new(
147 name => 'Float',
148 description =>
149 'The `Float` scalar type represents signed double-precision fractional ' .
150 'values as specified by ' .
151 '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).',
152 0 ▶ serialize => _leave_undef(sub { !is_Num($_[0]) and die "Not a Float.\n"; $_[0]+0 }),
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
&is_Num($_[0]) or die "Not a Float.\n" 0 0 0
153 0 ▶ parse_value => _leave_undef(sub { !is_Num($_[0]) and die "Not a Float.\n"; $_[0]+0 }),
Subroutine __ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
&is_Num($_[0]) or die "Not a Float.\n" 0 0 0
154 );
155  
156 =head2 $String
157  
158 =cut
159  
160 our $String = GraphQL::Type::Scalar->new(
161 name => 'String',
162 description =>
163 'The `String` scalar type represents textual data, represented as UTF-8 ' .
164 'character sequences. The String type is most often used by GraphQL to ' .
165 'represent free-form human-readable text.',
166 680 ▶ serialize => _leave_undef(sub { !is_Str($_[0]) and die "Not a String.\n"; $_[0].'' }),
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
is_Str($_[0]) or die "Not a String.\n" 677 3 680
167 71 ▶ parse_value => _leave_undef(sub { !is_Str($_[0]) and die "Not a String.\n"; $_[0] }),
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
is_Str($_[0]) or die "Not a String.\n" 70 1 71
168 );
169  
170 =head2 $Boolean
171  
172 =cut
173  
174 our $Boolean = GraphQL::Type::Scalar->new(
175 name => 'Boolean',
176 description =>
177 'The `Boolean` scalar type represents `true` or `false`.',
178 150 ▶ serialize => _leave_undef(sub { !is_Bool($_[0]) and !is_bool($_[0]) and die "Not a Boolean.\n"; $_[0] ? JSON->true : JSON->false }),
Subroutine __ANON__: called CC=4 SCAR=14.3
Branch: 2 branches
BranchTrueFalseTotal
is_Bool($_[0]) or is_bool($_[0]) or die "Not a Boolean.\n" 150 0 150
$_[0] ? : 11 139 150
Condition66%2/3
is_Bool($_[0]) or is_bool($_[0])
l!l&&r!l&&!r
14910
MC/DC0%0/2
is_Bool($_[0]) or is_bool($_[0])
is_Bool($_[0]) is_bool($_[0])
Truth table66%2/3
A or B
A= is_Bool($_[0])B= is_bool($_[0])
ABresult
1X1
011
000
179 98 ▶ parse_value => _leave_undef(sub { !is_Bool($_[0]) and !is_bool($_[0]) and die "Not a Boolean.\n"; $_[0]+0 }),
Subroutine __ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
is_Bool($_[0]) or is_bool($_[0]) or die "Not a Boolean.\n" 98 0 98
Condition33%1/3
is_Bool($_[0]) or is_bool($_[0])
l!l&&r!l&&!r
0980
MC/DC0%0/2
is_Bool($_[0]) or is_bool($_[0])
is_Bool($_[0]) is_bool($_[0])
Truth table33%1/3
A or B
A= is_Bool($_[0])B= is_bool($_[0])
ABresult
1X1
011
000
180 );
181  
182 =head2 $ID
183  
184 =cut
185  
186 our $ID = GraphQL::Type::Scalar->new(
187 name => 'ID',
188 description =>
189 'The `ID` scalar type represents a unique identifier, often used to ' .
190 'refetch an object or as key for a cache. The ID type appears in a JSON ' .
191 'response as a String; however, it is not intended to be human-readable. ' .
192 'When expected as an input type, any string (such as `"4"`) or integer ' .
193 '(such as `4`) input value will be accepted as an ID.',
194 1 ▶ serialize => _leave_undef(sub { Str->(@_); $_[0].'' }),
Subroutine __ANON__: called CC=1 SCAR=0.0
195 1 ▶ parse_value => _leave_undef(sub { Str->(@_); $_[0] }),
Subroutine __ANON__: called CC=1 SCAR=0.0
196 );
197  
198 18 GraphQL::Plugin::Type->register($_) for ($Int, $Float, $String, $Boolean, $ID);
199  
200 18 __PACKAGE__->meta->make_immutable();
201  
202 18 1;
« GraphQL/Type/NonNull.pm ↑ Summary GraphQL/Type/Interface.pm »