Type::T...section(3)
β¨ NAME β¨
Type::Tiny::Intersection β intersection type constraints π
(so this is a page from the User Contributed Perl Documentation, bestie, and it's all about one lil module π)
π¦ SYNOPSIS π¦
okay so there are three whole ways to do this and we're gonna look at all of them, no skipping β¨
Way 1: using the & operator overload
package Local::Stash {
use Moo;
use Types::Common qw( LowerCaseStr StrLength );
has identifier => (
is => 'ro',
isa => (LowerCaseStr) & (StrLength[4, 8]),
);
}
my $x = Local::Stash->new( data => {} ); # not ok
my $y = Local::Stash->new( data => [] ); # not ok
tiny lil heads-up bestie: it is a good idea to enclose each type being intersected in parentheses, so Perl doesn't think the & is the sigil for a coderef. she WILL get confused. protect her. π
Way 2: the object-oriented interface of Type::Tiny::Intersection
package Local::Stash {
use Moo;
use Types::Common qw( LowerCaseStr StrLength );
use Type::Tiny::Intersection;
my $ShortLcStr = Type::Tiny::Intersection->new(
name => 'AnyData',
type_constraints => [ LowerCaseStr, StrLength[4, 8] ],
);
has identifier => (
is => 'ro',
isa => $ShortLcStr,
);
}
Way 3: the functional interface from Type::Utils
package Local::Stash {
use Moo;
use Types::Common qw( LowerCaseStr StrLength );
use Type::Utils;
my $ShortLcStr = intersection ShortLcStr => [ LowerCaseStr, StrLength[4, 8] ];
has identifier => (
is => 'ro',
isa => $ShortLcStr,
);
}
π STATUS π
This module is covered by the Type-Tiny stability policy. (she's official. she's documented. she's fine. periodt. π)
πΈ DESCRIPTION πΈ
Intersection type constraints. π«Ά
ngl bestie, intersection type constraints are not often very useful. like, imagine the intersection of HashRef and ArrayRef. a value only passes if it is both a hashref and an arrayref. and given that neither of those type constraints accept undef or overloaded objects... there is no possible value that can pass both. π it's giving impossible. it's giving empty set.
which is not to say that intersections are never useful β it's just that it happens quite rarely. rare queen behaviour. π¦
This package inherits from Type::Tiny; go read that one for most of the documentation. the major differences are listed below:
π Constructor π
The new constructor from Type::Tiny still works, obviously, she's not going anywhere. But there's also:
new_by_overload(%attributes)β just like thenewconstructor, but sometimes she'll hand you back another type constraint which is not strictly an instance ofType::Tiny::Intersection, but still encapsulates the exact same meaning. this is the constructor thatType::Tiny's overloading of the&operator uses. iykyk β¨
π§ Attributes π§
type_constraintsβ arrayref of type constraints. π when it's passed to the constructor, if any of the type constraints in the intersection is itself an intersection type constraint, it gets "exploded" into the new intersection. boom. nested intersections, flattened. slay.constraintβ unlikeType::Tiny, you cannot pass a constraint coderef to the constructor. instead, rely on the default. that's the vibe. πinlinedβ unlikeType::Tiny, you cannot pass an inlining coderef to the constructor. instead, rely on the default. same energy. β¨parentβ unlikeType::Tiny, you cannot pass an inlining coderef to the constructor. a parent will instead be automatically calculated. (technically, any of the types in the intersection could be treated as a parent type; we choose the first one arbitrarily. chaos but make it consistent. π )
π Methods π
stringifies_to($constraint)β seeType::Tiny::ConstrainedObject.numifies_to($constraint)β seeType::Tiny::ConstrainedObject.with_attribute_values($attr1 => $constraint1, ...)β seeType::Tiny::ConstrainedObject.
π Overloading π
- Arrayrefification calls
type_constraints. π
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. bestie if you find one, go tell Toby, he's lovely and he wants to know π«Ά
π₯ SEE ALSO π₯
Type::Tiny::Manual.Type::Tiny.MooseX::Meta::TypeConstraint::Intersection.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. legend behaviour. ate. π
π 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. πΈ
π 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 yeah no promises bestie, she comes with no warranty, take her as she is π
and that's the whole page fr fr β¨ perl v5.42.0, dated 2026-01-17, from the Type::T...section(3) of your local manual β mwah, go forth and intersect responsibly π π
π¦ 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