.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Type::Tiny::Class 3pm" .TH Type::Tiny::Class 3pm "2019-05-06" "perl v5.24.1" "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::Class \- type constraints based on the "isa" method .SH "STATUS" .IX Header "STATUS" This module is covered by the Type-Tiny stability policy. .SH "DESCRIPTION" .IX Header "DESCRIPTION" Type constraints of the general form \f(CW\*(C`{ $_\->isa("Some::Class") }\*(C'\fR. .PP This package inherits from Type::Tiny; see that for most documentation. Major differences are listed below: .SS "Constructor" .IX Subsection "Constructor" .ie n .IP """new""" 4 .el .IP "\f(CWnew\fR" 4 .IX Item "new" When the constructor is called on an \fIinstance\fR of Type::Tiny::Class, it passes the call through to the constructor of the class for the constraint. So for example: .Sp .Vb 3 \& my $type = Type::Tiny::Class\->new(class => "Foo::Bar"); \& my $obj = $type\->new(hello => "World"); \& say ref($obj); # prints "Foo::Bar" .Ve .Sp This little bit of \s-1DWIM\s0 was borrowed from MooseX::Types::TypeDecorator, but Type::Tiny doesn't take the idea quite as far. .SS "Attributes" .IX Subsection "Attributes" .ie n .IP """class""" 4 .el .IP "\f(CWclass\fR" 4 .IX Item "class" The class for the constraint. .ie n .IP """constraint""" 4 .el .IP "\f(CWconstraint\fR" 4 .IX Item "constraint" Unlike Type::Tiny, you \fIcannot\fR pass a constraint coderef to the constructor. Instead rely on the default. .ie n .IP """inlined""" 4 .el .IP "\f(CWinlined\fR" 4 .IX Item "inlined" Unlike Type::Tiny, you \fIcannot\fR pass an inlining coderef to the constructor. Instead rely on the default. .ie n .IP """parent""" 4 .el .IP "\f(CWparent\fR" 4 .IX Item "parent" Parent is automatically calculated, and cannot be passed to the constructor. .SS "Methods" .IX Subsection "Methods" .ie n .IP """plus_constructors($source, $method_name)""" 4 .el .IP "\f(CWplus_constructors($source, $method_name)\fR" 4 .IX Item "plus_constructors($source, $method_name)" Much like \f(CW\*(C`plus_coercions\*(C'\fR but adds coercions that go via a constructor. (In fact, this is implemented as a wrapper for \f(CW\*(C`plus_coercions\*(C'\fR.) .Sp Example: .Sp .Vb 1 \& package MyApp::Minion; \& \& use Moose; extends "MyApp::Person"; \& \& use Types::Standard qw( HashRef Str ); \& use Type::Utils qw( class_type ); \& \& my $Person = class_type({ class => "MyApp::Person" }); \& \& has boss => ( \& is => "ro", \& isa => $Person\->plus_constructors( \& HashRef, "new", \& Str, "_new_from_name", \& ), \& coerce => 1, \& ); \& \& package main; \& \& MyApp::Minion\->new( \& ..., \& boss => "Bob", ## via MyApp::Person\->_new_from_name \& ); \& \& MyApp::Minion\->new( \& ..., \& boss => { name => "Bob" }, ## via MyApp::Person\->new \& ); .Ve .Sp Because coercing \f(CW\*(C`HashRef\*(C'\fR via constructor is a common desire, if you call \f(CW\*(C`plus_constructors\*(C'\fR with no arguments at all, this is the default. .Sp .Vb 2 \& $classtype\->plus_constructors(Types::Standard::HashRef, "new") \& $classtype\->plus_constructors() ## identical to above .Ve .Sp This is handy for Moose/Mouse/Moo\-based classes. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" Type::Tiny::Manual. .PP Type::Tiny. .PP Moose::Meta::TypeConstraint::Class. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2013\-2014, 2017\-2019 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