Type::Registry(3) User Contributed Perl Documentation Type::Registry(3)

# [NAME](#NAME)

Type::Registry - a glorified hashref for looking up type constraints

# [SYNOPSIS](#SYNOPSIS)

```
   package Foo::Bar;
   
   use Type::Registry;
   
   my $reg = "Type::Registry"->for_me;  # a registry for Foo::Bar
   
   # Register all types from Types::Standard
   $reg->add_types(-Standard);
   
   # Register just one type from Types::XSD
   $reg->add_types(-XSD => ["NonNegativeInteger"]);
   
   # Register all types from MyApp::Types
   $reg->add_types("MyApp::Types");
   
   # Create a type alias
   $reg->alias_type("NonNegativeInteger" => "Count");
   
   # Look up a type constraint
   my $type = $reg->lookup("ArrayRef[Count]");
   
   $type->check([1, 2, 3.14159]);  # croaks
```

Alternatively:

```
   package Foo::Bar;
   
   use Type::Registry qw( t );
   
   # Register all types from Types::Standard
   t->add_types(-Standard);
   
   # Register just one type from Types::XSD
   t->add_types(-XSD => ["NonNegativeInteger"]);
   
   # Register all types from MyApp::Types
   t->add_types("MyApp::Types");
   
   # Create a type alias
   t->alias_type("NonNegativeInteger" => "Count");
   
   # Look up a type constraint
   my $type = t("ArrayRef[Count]");
   
   $type->check([1, 2, 3.14159]);  # croaks
```

# [STATUS](#STATUS)

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

# [DESCRIPTION](#DESCRIPTION)

A type registry is basically just a hashref mapping type names to type constraint objects.

## [Constructors](#Constructors)

"new"

Create a new glorified hashref.

[for\_class($class)](#for_class%28$class%29)

Create or return the existing glorified hashref associated with the given class.

Note that any type constraint you have imported from Type::Library-based type libraries will be automatically available in your class' registry.

"for\_me"

Create or return the existing glorified hashref associated with the caller.

## [Methods](#Methods)

[add\_types(@libraries)](#add_types%28@libraries%29)

The libraries list is treated as an "optlist" (a la Data::OptList).

Strings are the names of type libraries; if the first character is a hyphen, it is expanded to the "Types::" prefix. If followed by an arrayref, this is the list of types to import from that library. Otherwise, imports all types from the library.

```
   use Type::Registry qw(t);
   
   t->add_types(-Standard);  # OR: t->add_types("Types::Standard");
   
   t->add_types(
      -TypeTiny => ['HashLike'],
      -Standard => ['HashRef' => { -as => 'RealHash' }],
   );
    
```

MooseX::Types (and experimentally, MouseX::Types) libraries can also be added this way, but *cannot be followed by an arrayref of* *types to import*.

"add\_type($type, $name)"

The long-awaited singular form of "add\_types". Given a type constraint object, adds it to the registry with a given name. The name may be omitted, in which case "$type-&gt;name" is called, and Type::Registry will throw an error if $type is anonymous. If a name is explicitly given, Type::Registry cares not one wit whether the type constraint is anonymous.

This method can even add MooseX::Types and MouseX::Types type constraints; indeed anything that can be handled by Types::TypeTiny's "to\_TypeTiny" function. (Bear in mind that to\_TypeTiny *always* results in an anonymous type constraint, so $name will be required.)

"alias\_type($oldname, $newname)"

Create an alias for an existing type.

[simple\_lookup($name)](#simple_lookup%28$name%29)

Look up a type in the registry by name.

Returns undef if not found.

[foreign\_lookup($name)](#foreign_lookup%28$name%29)

Like "simple\_lookup", but if the type name contains "::", will attempt to load it from a type library. (And will attempt to load that module.)

[lookup($name)](#lookup%28$name%29)

Look up by name, with a DSL.

```
   t->lookup("Int|ArrayRef[Int]")
    
```

The DSL can be summed up as:

```
   X               type from this registry
   My::Lib::X      type from a type library
   ~X              complementary type
   X | Y           union
   X & Y           intersection
   X[...]          parameterized type
   slurpy X        slurpy type
   Foo::Bar::      class type
    
```

Croaks if not found.

[make\_union(@constraints), make\_intersection(@constraints), make\_class\_type($class), make\_role\_type($role)](#make_union%28@constraints%29,)

Convenience methods for creating certain common type constraints.

"AUTOLOAD"

Overloaded to call "lookup".

```
   $registry->Str;  # like $registry->lookup("Str")
    
```

"get\_parent", set\_parent($reg), "clear\_parent", "has\_parent"

Advanced stuff. Allows a registry to have a "parent" registry which it inherits type constraints from.

## [Functions](#Functions)

"t"

This class can export a function "t" which acts like ""Type::Registry"-&gt;for\_class($importing\_class)".

# [BUGS](#BUGS)

Please report any bugs to &lt;https://github.com/tobyink/p5-type-tiny/issues&gt;.

# [SEE ALSO](#SEE_ALSO)

Type::Library.

# [AUTHOR](#AUTHOR)

Toby Inkster &lt;tobyink@cpan.org&gt;.

# [COPYRIGHT AND LICENCE](#COPYRIGHT_AND_LICENCE)

This software is copyright (c) 2013-2014, 2017-2025 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](#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.

2026-10-25 perl v5.44.0

---

Document: Type::Registry(3pm) from perl-type-tiny 2.010001-r4 (Chainguard OS)
Source: https://github.com/tobyink/p5-type-tiny
