perldoc > Type::Library

📖 NAME

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

🚀 Quick Reference

Use CaseCommandDescription
🆕 Create a type libraryuse Type::Library -base;Declare a new type library package
➕ Add a type$lib->meta->add_type($type)Register a Type::Tiny constraint in the library
📦 Import typesuse Types::Mine qw(Number String)Export type constants into your namespace
✅ Check a valueis_String($value)Returns true if $value passes the type constraint
🚨 Assert a typeassert_String($value)Returns $value or dies on failure
🔄 Coerce a valueto_String($value)Coerces $value to the target type
🔍 Look up a typeTypes::Mine->meta->get_type('Number')Retrieve the Type::Tiny object by name
📋 List typesTypes::Mine->meta->type_namesGet all type names defined in the library
🔒 Immutable__PACKAGE__->meta->make_immutableFreeze all coercions in the library

📝 SYNOPSIS

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);
}

🔮 STATUS

This module is covered by the Type-Tiny stability policy.

📖 DESCRIPTION

Type::Library is a tiny class for creating MooseX::Types-like type libraries which are compatible with Moo, Moose and Mouse.

If you're reading this because you want to create a type library, then you're probably better off reading Type::Tiny::Manual::Libraries.

🔧 Methods

A type library is a singleton class. Use the meta method to get a blessed object which other methods can get called on. For example:

Types::Mine->meta->add_type($foo);

📌 Constants

📤 Export

Type libraries are exporters. For the purposes of the following examples, assume that the Types::Mine library defines types Number and String.

# Exports nothing.
#
use Types::Mine;

# Exports a function "String" which is a constant returning
# the String type constraint.
#
use Types::Mine qw( String );

# Exports both String and Number as above.
#
use Types::Mine qw( String Number );

# Same.
#
use Types::Mine qw( :types );

# Exports "coerce_String" and "coerce_Number", as well as any other
# coercions
#
use Types::Mine qw( :coercions );

# Exports a sub "is_String" so that "is_String($foo)" is equivalent
# to "String->check($foo)".
#
use Types::Mine qw( is_String );

# Exports "is_String" and "is_Number".
#
use Types::Mine qw( :is );

# Exports a sub "assert_String" so that "assert_String($foo)" is
# equivalent to "String->assert_return($foo)".
#
use Types::Mine qw( assert_String );

# Exports "assert_String" and "assert_Number".
#
use Types::Mine qw( :assert );

# Exports a sub "to_String" so that "to_String($foo)" is equivalent
# to "String->coerce($foo)".
#
use Types::Mine qw( to_String );

# Exports "to_String" and "to_Number".
#
use Types::Mine qw( :to );

# Exports "String", "is_String", "assert_String" and "coerce_String".
#
use Types::Mine qw( +String );

# Exports everything.
#
use Types::Mine qw( :all );

Type libraries automatically inherit from Exporter::Tiny; see the documentation of that module for tips and tricks importing from libraries.

🐛 BUGS

Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.

📚 SEE ALSO

👤 AUTHOR

Toby Inkster <tobyink AT cpan.org>.

📄 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014, 2017-2021 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

⚠️ DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Type::Library
📖 NAME 🚀 Quick Reference 📝 SYNOPSIS 🔮 STATUS 📖 DESCRIPTION
🔧 Methods 📌 Constants 📤 Export
🐛 BUGS 📚 SEE ALSO 👤 AUTHOR 📄 COPYRIGHT AND LICENCE ⚠️ DISCLAIMER OF WARRANTIES

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-16 11:18 @216.73.216.208
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^