1Type::Tiny::Class(3)  User Contributed Perl Documentation Type::Tiny::Class(3)
2
3
4

NAME

6       Type::Tiny::Class - type constraints based on the "isa" method
7

STATUS

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

DESCRIPTION

12       Type constraints of the general form "{ $_->isa("Some::Class") }".
13
14       This package inherits from Type::Tiny; see that for most documentation.
15       Major differences are listed below:
16
17   Constructor
18       "new"
19           When the constructor is called on an instance of Type::Tiny::Class,
20           it passes the call through to the constructor of the class for the
21           constraint.  So for example:
22
23              my $type = Type::Tiny::Class->new(class => "Foo::Bar");
24              my $obj  = $type->new(hello => "World");
25              say ref($obj);   # prints "Foo::Bar"
26
27           This little bit of DWIM was borrowed from
28           MooseX::Types::TypeDecorator, but Type::Tiny doesn't take the idea
29           quite as far.
30
31   Attributes
32       "class"
33           The class for the constraint.
34
35       "constraint"
36           Unlike Type::Tiny, you cannot pass a constraint coderef to the
37           constructor.  Instead rely on the default.
38
39       "inlined"
40           Unlike Type::Tiny, you cannot pass an inlining coderef to the
41           constructor.  Instead rely on the default.
42
43       "parent"
44           Parent is automatically calculated, and cannot be passed to the
45           constructor.
46
47   Methods
48       "plus_constructors($source, $method_name)"
49           Much like "plus_coercions" but adds coercions that go via a
50           constructor.  (In fact, this is implemented as a wrapper for
51           "plus_coercions".)
52
53           Example:
54
55              package MyApp::Minion;
56
57              use Moose; extends "MyApp::Person";
58
59              use Types::Standard qw( HashRef Str );
60              use Type::Utils qw( class_type );
61
62              my $Person = class_type({ class => "MyApp::Person" });
63
64              has boss => (
65                 is     => "ro",
66                 isa    => $Person->plus_constructors(
67                    HashRef,     "new",
68                    Str,         "_new_from_name",
69                 ),
70                 coerce => 1,
71              );
72
73              package main;
74
75              MyApp::Minion->new(
76                 ...,
77                 boss => "Bob",  ## via MyApp::Person->_new_from_name
78              );
79
80              MyApp::Minion->new(
81                 ...,
82                 boss => { name => "Bob" },  ## via MyApp::Person->new
83              );
84
85           Because coercing "HashRef" via constructor is a common desire, if
86           you call "plus_constructors" with no arguments at all, this is the
87           default.
88
89              $classtype->plus_constructors(HashRef, "new")
90              $classtype->plus_constructors()  ## identical to above
91
92           This is handy for Moose/Mouse/Moo-based classes.
93
94       "stringifies_to($constraint)"
95           See Type::Tiny::ConstrainedObject.
96
97       "numifies_to($constraint)"
98           See Type::Tiny::ConstrainedObject.
99
100       "with_attribute_values($attr1 => $constraint1, ...)"
101           See Type::Tiny::ConstrainedObject.
102

BUGS

104       Please report any bugs to
105       <http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny>.
106

SEE ALSO

108       Type::Tiny::Manual.
109
110       Type::Tiny.
111
112       Moose::Meta::TypeConstraint::Class.
113

AUTHOR

115       Toby Inkster <tobyink@cpan.org>.
116
118       This software is copyright (c) 2013-2014, 2017-2020 by Toby Inkster.
119
120       This is free software; you can redistribute it and/or modify it under
121       the same terms as the Perl 5 programming language system itself.
122

DISCLAIMER OF WARRANTIES

124       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
125       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
126       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
127
128
129
130perl v5.30.1                      2020-02-12              Type::Tiny::Class(3)
Impressum