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

NAME

6       Type::Tiny::Role - type constraints based on the "DOES" method
7

SYNOPSIS

9       Using via Types::Standard:
10
11         package Local::Horse {
12           use Moo;
13           use Types::Standard qw( Str ConsumerOf );
14
15           has name => (
16             is       => 'ro',
17             isa      => Str,
18           );
19
20           has owner => (
21             is       => 'ro',
22             isa      => ConsumerOf[ 'Local::Traits::DoesOwnership' ],
23             default  => sub { Local::Person->new },
24           );
25         }
26
27       Using Type::Tiny::Class's export feature:
28
29         package Local::Horse {
30           use Moo;
31           use Types::Standard qw( Str );
32           use Type::Tiny::Role (
33             Owner => { role => 'Local::Traits::DoesOwnership' },
34           );
35
36           has name => (
37             is       => 'ro',
38             isa      => Str,
39           );
40
41           has owner => (
42             is       => 'ro',
43             isa      => Owner,
44             default  => sub { Local::Person->new },
45           );
46         }
47
48       Using Type::Tiny::Role's object-oriented interface:
49
50         package Local::Horse {
51           use Moo;
52           use Types::Standard qw( Str );
53           use Type::Tiny::Class;
54
55           my $Owner = Type::Tiny::Role->new(
56             role => 'Local::Traits::DoesOwnership',
57           );
58
59           has name => (
60             is       => 'ro',
61             isa      => Str,
62           );
63
64           has owner => (
65             is       => 'ro',
66             isa      => $Owner,
67             default  => sub { Local::Person->new },
68           );
69         }
70
71       Using Type::Utils's functional interface:
72
73         package Local::Horse {
74           use Moo;
75           use Types::Standard qw( Str );
76           use Type::Utils;
77
78           my $Owner = role_type 'Local::Traits::DoesOwnership';
79
80           has name => (
81             is       => 'ro',
82             isa      => Str,
83           );
84
85           has owner => (
86             is       => 'ro',
87             isa      => $Owner,
88             default  => sub { Local::Person->new },
89           );
90         }
91

STATUS

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

DESCRIPTION

96       Type constraints of the general form "{ $_->DOES("Some::Role") }".
97
98       This package inherits from Type::Tiny; see that for most documentation.
99       Major differences are listed below:
100
101   Attributes
102       "role"
103           The role for the constraint.
104
105           Note that this package doesn't subscribe to any particular flavour
106           of roles (Moose::Role, Mouse::Role, Moo::Role, Role::Tiny, etc). It
107           simply trusts the object's "DOES" method (see UNIVERSAL).
108
109       "constraint"
110           Unlike Type::Tiny, you cannot pass a constraint coderef to the
111           constructor.  Instead rely on the default.
112
113       "inlined"
114           Unlike Type::Tiny, you cannot pass an inlining coderef to the
115           constructor.  Instead rely on the default.
116
117       "parent"
118           Parent is always Types::Standard::Object, and cannot be passed to
119           the constructor.
120
121   Methods
122       stringifies_to($constraint)
123           See Type::Tiny::ConstrainedObject.
124
125       numifies_to($constraint)
126           See Type::Tiny::ConstrainedObject.
127
128       "with_attribute_values($attr1 => $constraint1, ...)"
129           See Type::Tiny::ConstrainedObject.
130
131   Exports
132       Type::Tiny::Role can be used as an exporter.
133
134         use Type::Tiny::Role 'MyApp::Printable';
135
136       This will export the following functions into your namespace:
137
138       "MyAppPrintable"
139       is_MyAppPrintable( $value )
140       assert_MyAppPrintable( $value )
141       to_MyAppPrintable( $value )
142
143       Multiple types can be exported at once:
144
145         use Type::Tiny::Role qw( MyApp::Printable MyApp::Sendable );
146

BUGS

148       Please report any bugs to
149       <https://github.com/tobyink/p5-type-tiny/issues>.
150

SEE ALSO

152       Type::Tiny::Manual.
153
154       Type::Tiny.
155
156       Moose::Meta::TypeConstraint::Role.
157

AUTHOR

159       Toby Inkster <tobyink@cpan.org>.
160
162       This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.
163
164       This is free software; you can redistribute it and/or modify it under
165       the same terms as the Perl 5 programming language system itself.
166

DISCLAIMER OF WARRANTIES

168       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
169       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
170       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
171
172
173
174perl v5.36.0                      2023-04-24               Type::Tiny::Role(3)
Impressum