The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Object::Type

ABSTRACT

Data-Object Type Constraint Builder

SYNOPSIS

  package App::Type::Id;

  use parent 'Data::Object::Type';

  sub name {
    return 'Id';
  }

  sub parent {
    return 'Str';
  }

  sub namespace {
    return 'App::Type::Library';
  }

  sub validation {
    my ($self, $data) = @_;

    return 0 if !$data;

    return 0 if $data !~ /^\d+$/;

    return 1;
  }

DESCRIPTION

Data::Object::Type is an abstract base class for type constraint builder classes.

METHODS

This package implements the following methods.

aliases

  aliases() : ArrayRef

The aliases method returns aliases to register in the type library.

aliases example
  my $aliases = $data->aliases();

coercion_generator

  coercion_generator(Object $arg1, Object $arg2, Object $arg3) : Object

coercion_generator

coercion_generator example
  my $coercion_generator = $self->coercion_generator();

coercions

  coercions() : ArrayRef

The coercions method returns coercions to configure on the type constraint.

coercions example
  my $coercions = $data->coercions();

constraint_generator

  const(Str $arg1, Any $arg2) : Any

constraint_generator

constraint_generator example
  my $constraint_generator = $self->constraint_generator();

explaination_generator

  explaination(Object $arg1, Object $arg2, Str $arg3) : Any

The explaination_generator method returns the explaination for the type check failure.

explaination_generator example
  my $explaination_generator = $self->explaination_generator();

library

  library() : Any

The library method returns an instance of the type library instance.

library example
  my $library = $data->library();

name

  name() : StrObject

The name method returns the name of the data type.

name example
  my $name = $data->name();

namespace

  name() : StrObject

The namespace method returns the name of the data type.

namespace example
  my $namespace = $data->namespace();

new

  new() : Object

Construct a new object.

new example
  my $data = Data::Object::Type->new();

options

  options(Any $arg1) : (Str, Any)

The options method is used internally to create the options for building the Type::Tiny type constraint.

options example
  my $options = $data->options();

parent

  parent() : Str

The parent method represents the type expression (or parent type) that its type should derive from.

parent example
  my $parent = $data->parent();

register

  register() : DoType

The register method registers the built type constraint in the specified type library.

register example
  my $register = $data->register();

validation

  validation(Object $arg1) : NumObject

The validation method returns truthy if type check is valid.

validation example
  my $validation = $self->validation();

validator

  validator() : Object

The validator method returns the built type constraint object.

validator example
  my $validator = $data->validator();