Type::Registry(3)
π Type::Registry π
okay bestie, welcome to Type::Registry(3) β that's the User Contributed Perl Documentation section, iykyk. this page is your little guided tour, and honestly? it's giving organized. let's go π¦
β¨ NAME β¨
Type::Registry β a glorified hashref for looking up type constraints π
β¨ 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 β¨
This module is covered by the Type-Tiny stability policy. periodt π
β¨ DESCRIPTION β¨
so likeβ¦ a type registry is basically just a hashref mapping type names to type constraint objects. that's it. that's the whole vibe. lowkey iconic in its simplicity πΈ
π Constructors π
newβ Create a new glorified hashref. brand new, fresh out the box β¨for_class($class)β Create or return the existing glorified hashref associated with the given class.
bestie heads up: any type constraint you have imported from Type::Library-based type libraries will be automatically available in your class' registry. no extra work, slay π
for_meβ Create or return the existing glorified hashref associated with the caller. it's giving self-care π«Ά
πΈ Methods πΈ
add_types(@libraries)β 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. noted π
add_type($type, $name)β The long-awaited singular form ofadd_types. Given a type constraint object, adds it to the registry with a given name. The name may be omitted, in which case$type->nameis called, and Type::Registry will throw an error if$typeis 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. rebranding era πsimple_lookup($name)β Look up a type in the registry by name.
Returns undef if not found. no drama, just undef π
foreign_lookup($name)β Likesimple_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)β 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)β Convenience methods for creating certain common type constraints. little helpers, love them for you πAUTOLOADβ Overloaded to calllookup.
$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. family tree energy π³
π Functions π
tβ This class can export a functiontwhich acts like"Type::Registry"->for_class($importing_class). short, sweet, iconic β
β¨ BUGS β¨
Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. bestie please do not suffer in silence, the issue tracker is right there π«Ά
β¨ SEE ALSO β¨
Type::Library.
β¨ AUTHOR β¨
Toby Inkster <tobyink@cpan.org>. legend behavior π
β¨ 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. fr fr π
β¨ 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.
no cap, that one's all caps for a reason π
aaaand that's the whole page, bestie π
this was Type::Registry(3) from perl v5.42.0, dated 2026-01-17. go forth and look up your type constraints, you absolute main character ππ¦π
π¦ where this page comes from
- fedora 44: perl-Type-Tiny 2.010001-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms