GraphQL/Type/NonNull.pm

filter: Statementstmt 100% 55 / 55 Branchbran 50.0% 5 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 89.8% 80 / 89 CC 8 SCAR 10.2
CC
8
Cov
90%
is_valid
5.6
graphql_to_perl
4.0
BEGIN
1.0
CRAP 2.8
« GraphQL/Plugin/Type.pm ↑ Summary GraphQL/Type/Scalar.pm »
1 package GraphQL::Type::NonNull;
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 Types::Standard -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use GraphQL::MaybeTypeCheck;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 extends qw(GraphQL::Type);
10  
11 18 our $VERSION = '0.02';
12  
13 # A-ha
14 18 my @TAKE_ON_ME = qw(
15 GraphQL::Role::Input
16 GraphQL::Role::Output
17 );
18  
19 =head1 NAME
20  
21 GraphQL::Type::NonNull - GraphQL type that is a non-null version of another type
22  
23 =head1 SYNOPSIS
24  
25 use GraphQL::Type::NonNull;
26 my $type = GraphQL::Type::NonNull->new(of => $other_type);
27  
28 =head1 DESCRIPTION
29  
30 Type that is a wrapper for another type. Means data cannot be a null value.
31  
32 =head1 ATTRIBUTES
33  
34 =head2 of
35  
36 GraphQL type object of which this is a non-null version.
37  
38 =cut
39  
40 18 has of => (
41 is => 'ro',
42 isa => InstanceOf['GraphQL::Type'],
43 required => 1,
44 handles => [ qw(name) ],
45 );
46  
47 =head1 METHODS
48  
49 =head2 BUILD
50  
51 L<Moo> method that applies the relevant roles.
52  
53 =cut
54  
55 242 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
56 242 my ($self, $args) = @_;
57 242 my $of = $self->of;
58 242 Role::Tiny->apply_roles_to_object($self, grep $of->DOES($_), @TAKE_ON_ME);
59 }
60  
61 =head2 to_string
62  
63 Part of serialisation.
64  
65 =cut
66  
67 9 ▶has to_string => (is => 'lazy', isa => Str, init_arg => undef, builder => sub {
Subroutine _build_to_string: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
68 9 my ($self) = @_;
69 9 $self->of->to_string . '!';
70 18 });
71  
72 =head2 is_valid
73  
74 True if given Perl value is a valid value for this type.
75  
76 =cut
77  
78 1 ▶method is_valid(Any $item) :ReturnType(Bool) {
Subroutine is_valid: called CC=5 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method is_valid (expected 2, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for method is_valid (expected 2, got ' . @_ . ')') 0 1 1
79 1 ▶ return if !defined $item or !$self->of->is_valid($item);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item and $self->of->is_valid($item) 0 1 1
Condition33%1/3
defined $item and $self->of->is_valid($item)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $item and $self->of->is_valid($item)
defined $item $self->of->is_valid($item)
Truth table33%1/3
A and B
A= defined $itemB= $self->of->is_valid($item)
ABresult
0X0
100
111
80 1 1;
81 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 75 ▶method graphql_to_perl(Any $item) :ReturnType(Any) {
Subroutine graphql_to_perl: called CC=4 SCAR=14.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method graphql_to_perl (expected 2, got ' . @_ . ')') 0 75 75
@_ > 2 and Function::Parameters::_croak('Too many arguments for method graphql_to_perl (expected 2, got ' . @_ . ')') 0 75 75
84 75 my $of = $self->of;
85 75 ▶ $of->graphql_to_perl($item) // die $self->to_string . " given null value.\n";
Condition100%2/2
$of->graphql_to_perl($item) // die($self->to_string . " given null value.\n")
l!l
6110
MC/DC100%1/1
$of->graphql_to_perl($item) // die($self->to_string . " given null value.\n")
$of->graphql_to_perl($item)
Truth table100%2/2
A
A= $of->graphql_to_perl($item)
Aresult
11
00
86 18 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 =head2 name
89  
90 The C<name> of the type this object is a non-null version of.
91  
92 =cut
93  
94 18 __PACKAGE__->meta->make_immutable();
95  
96 18 1;
« GraphQL/Plugin/Type.pm ↑ Summary GraphQL/Type/Scalar.pm »