.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Type::Tiny::Manual 3pm" .TH Type::Tiny::Manual 3pm "2023-07-21" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Type::Tiny::Manual \- an overview of Type::Tiny .SH "SYNOPSIS" .IX Header "SYNOPSIS" Type::Tiny is a small Perl class for writing type constraints, inspired by Moose's type constraint \s-1API\s0 and MooseX::Types. It has only one non-core dependency (and even that is simply a module that was previously distributed as part of Type::Tiny but has since been spun off), and can be used with Moose, Mouse, or Moo (or none of the above). .PP Type::Tiny is used by over 800 Perl distributions on the \s-1CPAN\s0 (Comprehensive Perl Archive Network) and can be considered a stable and mature framework for efficiently and reliably enforcing data types. .PP Type::Tiny is bundled with Type::Library a framework for organizing type constraints into collections. Also bundled is Types::Standard, a Moose-inspired library of useful type constraints. Type::Params is also provided, to allow very fast checking and coercion of function and method parameters. .PP The following example gives you an idea of some of the features of these modules. If you don't understand it all, that's fine; that's what the rest of the manual is for. Although the example uses Moo, the \f(CW\*(C`use Moo\*(C'\fR could be changed to \f(CW\*(C`use Moose\*(C'\fR or \f(CW\*(C`use Mouse\*(C'\fR and it would still work. .PP .Vb 3 \& use v5.12; \& use strict; \& use warnings; \& \& package Horse { \& use Moo; \& use Types::Standard qw( Str Int Enum ArrayRef InstanceOf ); \& use Type::Params qw( signature ); \& use namespace::autoclean; \& \& has name => ( \& is => \*(Aqro\*(Aq, \& isa => Str, \& required => 1, \& ); \& has gender => ( \& is => \*(Aqro\*(Aq, \& isa => Enum[qw( f m )], \& ); \& has age => ( \& is => \*(Aqrw\*(Aq, \& isa => Int\->where( \*(Aq$_ >= 0\*(Aq ), \& ); \& has children => ( \& is => \*(Aqro\*(Aq, \& isa => ArrayRef[ InstanceOf[\*(AqHorse\*(Aq] ], \& default => sub { return [] }, \& ); \& \& sub add_child { \& state $check = signature( \& method => Object, \& positional => [ InstanceOf[\*(AqHorse\*(Aq] ] \& ); \& \& my ( $self, $child ) = $check\->(@_); # unpack @_ \& push @{ $self\->children }, $child; \& \& return $self; \& } \& } \& \& package main; \& \& my $boldruler = Horse\->new( \& name => "Bold Ruler", \& gender => \*(Aqm\*(Aq, \& age => 16, \& ); \& \& my $secretariat = Horse\->new( \& name => "Secretariat", \& gender => \*(Aqm\*(Aq, \& age => 0, \& ); \& \& $boldruler\->add_child( $secretariat ); \& \& use Types::Standard qw( is_Object assert_Object ); \& \& # is_Object will return a boolean \& # \& if ( is_Object($boldruler) ) { \& say $boldruler\->name; \& } \& \& # assert_Object will return $secretariat or die \& # \& say assert_Object( $secretariat )\->name; .Ve .SH "MANUAL" .IX Header "MANUAL" Even if you are using Type::Tiny with other object-oriented programming toolkits (such as Moose or Mouse), you should start with the Moo sections of the manual. Most of the information is directly transferrable and the Moose and Mouse sections of the manual list the minor differences between using Type::Tiny with Moo and with them. .PP In general, this manual assumes you use Perl 5.12 or above and may use examples that do not work on older versions of Perl. Type::Tiny does work on earlier versions of Perl, but not all the examples and features in the manual will run without adjustment. (For instance, you may need to replace \f(CW\*(C`state\*(C'\fR variables with lexical variables, avoid the \&\f(CW\*(C`package NAME { BLOCK }\*(C'\fR syntax, etc.) .IP "\(bu" 4 Type::Tiny::Manual::Installation .Sp How to install Type::Tiny. If Type::Tiny is already installed, you can skip this. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMoo .Sp Basic use of Type::Tiny with Moo, including attribute type constraints, parameterized type constraints, coercions, and method parameter checking. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMoo2 .Sp Advanced use of Type::Tiny with Moo, including unions and intersections, \&\f(CW\*(C`stringifies_to\*(C'\fR, \f(CW\*(C`numifies_to\*(C'\fR, \f(CW\*(C`with_attribute_values\*(C'\fR, and \f(CW\*(C`where\*(C'\fR. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMoo3 .Sp There's more than one way to do it! Alternative ways of using Type::Tiny, including type registries, exported functions, and \f(CW\*(C`dwim_type\*(C'\fR. .IP "\(bu" 4 Type::Tiny::Manual::Libraries .Sp Defining your own type libraries, including extending existing libraries, defining new types, adding coercions, defining parameterizable types, and the declarative style. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMoose .Sp How to use Type::Tiny with Moose, including the advantages of Type::Tiny over built-in type constraints, and Moose-specific features. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMouse .Sp How to use Type::Tiny with Mouse, including the advantages of Type::Tiny over built-in type constraints, and Mouse-specific features. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithMite .Sp How to use Type::Tiny with Mite, including how to write an entire Perl project using clean Moose-like code and no non-core dependencies. (Not even dependencies on Mite or Type::Tiny!) .IP "\(bu" 4 Type::Tiny::Manual::UsingWithClassTiny .Sp Including how to Type::Tiny in your object's \f(CW\*(C`BUILD\*(C'\fR method, and third-party shims between Type::Tiny and Class::Tiny. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithOther .Sp Using Type::Tiny with Class::InsideOut, Params::Check, and Object::Accessor. .IP "\(bu" 4 Type::Tiny::Manual::UsingWithTestMore .Sp Type::Tiny for test suites. .IP "\(bu" 4 Type::Tiny::Manual::Params .Sp Advanced information on Type::Params, and using Type::Tiny with other signature modules like Function::Parameters and Kavorka. .IP "\(bu" 4 Type::Tiny::Manual::NonOO .Sp Type::Tiny in non-object-oriented code. .IP "\(bu" 4 Type::Tiny::Manual::Optimization .Sp Squeeze the most out of your \s-1CPU.\s0 .IP "\(bu" 4 Type::Tiny::Manual::Coercions .Sp Advanced information on coercions. .IP "\(bu" 4 Type::Tiny::Manual::AllTypes .Sp An alphabetical list of all type constraints bundled with Type::Tiny. .IP "\(bu" 4 Type::Tiny::Manual::Policies .Sp Policies related to Type::Tiny development. .IP "\(bu" 4 Type::Tiny::Manual::Contributing .Sp Contributing to Type::Tiny development. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" The Type::Tiny homepage . .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2013\-2014, 2017\-2023 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0