— — — — — |
use 5.014;
our $VERSION = '0.02' ;
my @TAKE_ON_ME = qw(
GraphQL::Role::Input
GraphQL::Role::Output
) ;
has of => (
is => 'ro' ,
isa => InstanceOf[ 'GraphQL::Type' ],
required => 1,
handles => [ qw(name) ],
);
sub BUILD {
my ( $self , $args ) = @_ ;
my $of = $self ->of;
Role::Tiny->apply_roles_to_object( $self , grep $of ->DOES( $_ ), @TAKE_ON_ME );
}
has to_string => ( is => 'lazy' , isa => Str, init_arg => undef , builder => sub {
my ( $self ) = @_ ;
$self ->of->to_string . '!' ;
});
method is_valid(Any $item ) :ReturnType(Bool) {
return if ! defined $item or ! $self ->of->is_valid( $item );
1;
}
method graphql_to_perl(Any $item ) :ReturnType(Any) {
my $of = $self ->of;
$of ->graphql_to_perl( $item ) // die $self ->to_string . " given null value.\n" ;
}
__PACKAGE__->meta->make_immutable();
1;
|