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 (see UNIVERSAL). 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 always Types::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>.


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