Type::T...edObject(3)

✨ NAME ✨

ok so this is Type::Tiny::ConstrainedObject β€” it's the shared behaviour vibe that Type::Tiny::Class, etc. all inherit from πŸ’– (the full name in the manual header is Type::Tiny::ConstrainedObject(3), and it lives under User Contributed Perl Documentation, iykyk 🫢)


πŸ§ͺ STATUS πŸ§ͺ

This module is considered experiemental. 😳 like it works but she's still figuring herself out, bestie

πŸ’… DESCRIPTION πŸ’…

πŸŽ€ Methods πŸŽ€

Okay so these methods? They exist for Type::Tiny::Class, Type::Tiny::Role, Type::Tiny::Duck, and literally any type constraints that inherit from "Object" or "Overload" in Types::Standard. iconic behavior honestly πŸ‘‘

They will also work for Type::Tiny::Intersection if at least one of the types in the intersection provides these methods. like, one friend in the group chat showing up is enough ✨

And they'll also work for Type::Tiny::Union if all of the types in the union provide these methods. so for the union it's a whole-group-trip situation, no stragglers πŸ’€


  • stringifies_to($constraint) β€” makes a new child type constraint that checks the object's stringification against a constraint. like it stringifies and we vibe-check the result 🌸

For example:

my $type  = Type::Tiny::Class->new(class => 'URI');
my $child = $type->stringifies_to( StrMatch[qr/^http:/] );

$child->assert_valid( URI->new("http://example.com/") );

In the above example, $child is a type constraint that checks objects are blessed into (or inherit from) the URI class, and when stringified (e.g. though overloading) the result matches the regular expression "qr/^http:/". πŸ¦‹

$constraint may be a type constraint, something that can be coerced to a type constraint (such as a coderef returning a boolean), a string of Perl code operating on $_, or a reference to a regular expression. so like, she's flexible, she contains multitudes πŸ’œ

So the following would work:

my $child = $type->stringifies_to( sub { qr/^http:/ } );
my $child = $type->stringifies_to(       qr/^http:/   );
my $child = $type->stringifies_to(       'm/^http:/'  );

my $child = $type->where('"$_" =~ /^http:/');
  • numifies_to($constraint) β€” same as "stringifies_to" but it checks numification instead. numbers girlie πŸ”’

The following might be useful:

use Types::Standard qw(Int Overload);
my $IntLike = Int | Overload->numifies_to(Int)
  • "with_attribute_values($attr1 => $constraint1, ...)" β€” okay this one is best explained with an example, trust me:
use Types::Common qw( InstanceOf StrMatch IntRange );

my $person = InstanceOf['Local::Human'];
my $woman  = $person->with_attribute_values(
   gender   => StrMatch[ qr/^F/i  ],
   age      => IntRange[ 18 => () ],
);

$woman->assert_valid($alice);

This assertion will firstly check that $alice is a Local::Human, then check that "$alice->gender" starts with an "F", and lastly check that "$alice->age" is an integer at least 18. three checks, one slay, no cap πŸ’…

Again, constraints can be type constraints, coderefs, strings of Perl code, or regular expressions. same energy as before ✨

Technically the "attributes" don't need to be Moo/Moose/Mouse attributes, but any methods which can be called with no parameters and return a scalar. so honestly, live your truth 🌈


πŸ› BUGS πŸ›

Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. πŸ™ˆ she wants to hear about it fr fr


πŸ‘€ SEE ALSO πŸ‘€

  • Type::Tiny::Manual.
  • Type::Tiny.

πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. 🫢


This software is copyright (c) 2019-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. πŸŽ€


πŸ’€ 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.

like bestie if it breaks it breaks, that's on you 😭


okay that's the whole page, mwah πŸ’– this beauty was documented in the perl v5.42.0 era, dated 2026-01-17, filed under Type::T...edObject(3) β€” go forth and constrain ur objects, queen βœ¨πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from