# perldoc > Type::Library

---
type: CommandReference
command: Type::Library
mode: perldoc
section: ''
source: perldoc
---

## Quick Reference

- `use Type::Library -base;` — base class for creating type libraries
- `__PACKAGE__->meta->add_type($type)` — add a type to the library
- `__PACKAGE__->meta->make_immutable` — freeze all coercions
- `use Types::Mine qw(Number);` — import type as constant
- `use Types::Mine qw(:types);` — import all types
- `use Types::Mine qw(:is);` — import check functions
- `use Types::Mine qw(:assert);` — import assert functions
- `use Types::Mine qw(:all);` — import everything

## Name

Type::Library - tiny, yet Moo(se)-compatible type libraries

## Synopsis

perl
package Types::Mine {
   use Scalar::Util qw(looks_like_number);
   use Type::Library -base;
   use Type::Tiny;

   my $NUM = Type::Tiny->new(
      name       => "Number",
      constraint => sub { looks_like_number($_) },
      message    => sub { "$_ ain't a number" },
   );

   __PACKAGE__->meta->add_type($NUM);
   __PACKAGE__->meta->make_immutable;
}

package Ermintrude {
   use Moo;
   use Types::Mine qw(Number);
   has favourite_number => (is => "ro", isa => Number);
}
## Methods

- `meta` — get the blessed singleton object on which other methods are called
- `add_type($type)` or `add_type(%opts)` — add a type to the library; if `%opts` given, calls `Type::Tiny->new(%opts)` first. Automatically defines `Foo`, `is_Foo`, `assert_Foo`, `to_Foo` functions in the library's namespace
- `get_type($name)` — get the `Type::Tiny` object for a given name
- `has_type($name)` — boolean; true if the type exists in the library
- `type_names` — list all types defined by the library
- `add_coercion($c)` or `add_coercion(%opts)` — add a standalone coercion; if `%opts` given, calls `Type::Coercion->new(%opts)` first. Defines a `FooFromBar` function
- `get_coercion($name)` — get the `Type::Coercion` object for a given name
- `has_coercion($name)` — boolean; true if the coercion exists
- `coercion_names` — list all standalone coercions
- `import(@args)` — exporter (inherits from `Exporter::Tiny`)
- `make_immutable` — shortcut for calling `$type->coercion->freeze` on every type constraint

## Constants

- `NICE_PROTOTYPES` — if true, gives parameterizable type constraints the prototype `(;$)`, allowing `ArrayRef[Int] | HashRef[Int]` to work

## Examples

### SYNOPSIS (full)

perl
package Types::Mine {
   use Scalar::Util qw(looks_like_number);
   use Type::Library -base;
   use Type::Tiny;
   my $NUM = Type::Tiny->new(
      name       => "Number",
      constraint => sub { looks_like_number($_) },
      message    => sub { "$_ ain't a number" },
   );
   __PACKAGE__->meta->add_type($NUM);
   __PACKAGE__->meta->make_immutable;
}

package Ermintrude {
   use Moo;
   use Types::Mine qw(Number);
   has favourite_number => (is => "ro", isa => Number);
}

package Bullwinkle {
   use Moose;
   use Types::Mine qw(Number);
   has favourite_number => (is => "ro", isa => Number);
}

package Maisy {
   use Mouse;
   use Types::Mine qw(Number);
   has favourite_number => (is => "ro", isa => Number);
}
### Export variants

perl
# Exports nothing
use Types::Mine;

# Export a type constant
use Types::Mine qw( String );

# Export multiple types
use Types::Mine qw( String Number );

# Export all types
use Types::Mine qw( :types );

# Export coercions
use Types::Mine qw( :coercions );

# Export check functions (is_*)
use Types::Mine qw( is_String );

# Export all check functions
use Types::Mine qw( :is );

# Export assert functions (assert_*)
use Types::Mine qw( assert_String );
use Types::Mine qw( :assert );

# Export coercion functions (to_*)
use Types::Mine qw( to_String );
use Types::Mine qw( :to );

# Export a type plus its helpers
use Types::Mine qw( +String );

# Export everything
use Types::Mine qw( :all );
## See Also

- [Type::Tiny::Manual](https://metacpan.org/pod/Type::Tiny::Manual)
- [Type::Tiny](https://metacpan.org/pod/Type::Tiny)
- [Type::Utils](https://metacpan.org/pod/Type::Utils)
- [Types::Standard](https://metacpan.org/pod/Types::Standard)
- [Type::Coercion](https://metacpan.org/pod/Type::Coercion)
- [Moose::Util::TypeConstraints](https://metacpan.org/pod/Moose::Util::TypeConstraints)
- [Mouse::Util::TypeConstraints](https://metacpan.org/pod/Mouse::Util::TypeConstraints)
- [Exporter::Tiny](https://metacpan.org/pod/Exporter::Tiny)