Type::Tiny::Role(3)
π Type::Tiny::Role π
okay bestie, so this is the manual page for Type::Tiny::Role, a lil module that makes type constraints based on the "DOES" method β¨ like, it checks whether your object does a role, no cap.
πΈ SYNOPSIS πΈ
There's like, five whole ways to do this and they're all valid and all iconic. pick your fighter π
Using via Types::Standard:
package Local::Horse {
use Moo;
use Types::Standard qw( Str ConsumerOf );
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => ConsumerOf[ 'Local::Traits::DoesOwnership' ],
default => sub { Local::Person->new },
);
}
Using Type::Tiny::Class's export feature:
package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Tiny::Role (
Owner => { role => 'Local::Traits::DoesOwnership' },
);
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => Owner,
default => sub { Local::Person->new },
);
}
Using Type::Tiny::Role's object-oriented interface:
package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Tiny::Class;
my $Owner = Type::Tiny::Role->new(
role => 'Local::Traits::DoesOwnership',
);
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => $Owner,
default => sub { Local::Person->new },
);
}
Using Type::Utils's functional interface:
package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Utils;
my $Owner = role_type 'Local::Traits::DoesOwnership';
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => $Owner,
default => sub { Local::Person->new },
);
}
π¦ STATUS π¦
This module is covered by the Type-Tiny stability policy. so it's stable, it's not gonna ghost you π«Ά
β¨ DESCRIPTION β¨
These are type constraints of the general form { $_->DOES("Some::Role") }. that's the whole vibe π«
This package inherits from Type::Tiny β go read that for most of the documentation, fr fr. The major differences are listed below:
π Attributes π
roleβ the role for the constraint. and like, a lil heads up: this package does not subscribe to any particular flavour of roles (Moose::Role,Mouse::Role,Moo::Role,Role::Tiny, etc). it simply trusts the object's"DOES"method (seeUNIVERSAL). it's giving "i trust you bestie" energy πconstraintβ unlike Type::Tiny, you cannot pass a constraint coderef to the constructor. Instead, rely on the default. that's it, that's the rule πinlinedβ unlike Type::Tiny, you cannot pass an inlining coderef to the constructor. Instead, rely on the default. same deal πparentβ Parent is alwaysTypes::Standard::Object, and it cannot be passed to the constructor. it's already decided for you, periodt π
π Methods π
stringifies_to($constraint)β See Type::Tiny::ConstrainedObject.numifies_to($constraint)β See Type::Tiny::ConstrainedObject."with_attribute_values($attr1 => $constraint1, ...)"β See Type::Tiny::ConstrainedObject.
π Exports π
Type::Tiny::Role can be used as an exporter. iconic behaviour honestly.
use Type::Tiny::Role 'MyApp::Printable';
This will export the following functions into your namespace:
"MyAppPrintable"is_MyAppPrintable( $value )assert_MyAppPrintable( $value )to_MyAppPrintable( $value )
and you can do multiple types at once, no biggie:
use Type::Tiny::Role qw( MyApp::Printable MyApp::Sendable );
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. do it bestie, the maintainer wants to know π
π SEE ALSO π
- Type::Tiny::Manual.
- Type::Tiny.
- Moose::Meta::TypeConstraint::Role.
π¦ AUTHOR π¦
Toby Inkster <tobyink@cpan.org>.
πΈ 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. slay π
β 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.
(translation: no promises, bestie, it is what it is π)
and that's a wrap! this page came from perl v5.42.0, dated 2026-01-17, and it's the Type::Tiny::Role(3) manpage. ily, go write some type constraints π«Άπβ¨
π¦ 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