{
    "mode": "perldoc",
    "parameter": "Type::Tiny::Intersection",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AIntersection/json",
    "generated": "2026-10-01T16:23:39Z",
    "synopsis": "Using via the \"&\" operator overload:\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\nhas identifier => (\nis   => 'ro',\nisa  => (LowerCaseStr) & (StrLength[4, 8]),\n);\n}\nmy $x = Local::Stash->new( data => {} );  # not ok\nmy $y = Local::Stash->new( data => [] );  # not ok\nNote that it is a good idea to enclose each type being intersected in parentheses to avoid Perl\nthinking the \"&\" is the sigil for a coderef.\nUsing Type::Tiny::Intersection's object-oriented interface:\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\nuse Type::Tiny::Intersection;\nmy $ShortLcStr = Type::Tiny::Intersection->new(\nname             => 'AnyData',\ntypeconstraints => [ LowerCaseStr, StrLength[4, 8] ],\n);\nhas identifier => (\nis   => 'ro',\nisa  => $ShortLcStr,\n);\n}\nUsing Type::Utils's functional interface:\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\nuse Type::Utils;\nmy $ShortLcStr = intersection ShortLcStr => [ LowerCaseStr, StrLength[4, 8] ];\nhas identifier => (\nis   => 'ro',\nisa  => $ShortLcStr,\n);\n}",
    "sections": {
        "NAME": {
            "content": "Type::Tiny::Intersection - intersection type constraints\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Using via the \"&\" operator overload:\n\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\n\nhas identifier => (\nis   => 'ro',\nisa  => (LowerCaseStr) & (StrLength[4, 8]),\n);\n}\n\nmy $x = Local::Stash->new( data => {} );  # not ok\nmy $y = Local::Stash->new( data => [] );  # not ok\n\nNote that it is a good idea to enclose each type being intersected in parentheses to avoid Perl\nthinking the \"&\" is the sigil for a coderef.\n\nUsing Type::Tiny::Intersection's object-oriented interface:\n\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\nuse Type::Tiny::Intersection;\n\nmy $ShortLcStr = Type::Tiny::Intersection->new(\nname             => 'AnyData',\ntypeconstraints => [ LowerCaseStr, StrLength[4, 8] ],\n);\n\nhas identifier => (\nis   => 'ro',\nisa  => $ShortLcStr,\n);\n}\n\nUsing Type::Utils's functional interface:\n\npackage Local::Stash {\nuse Moo;\nuse Types::Common qw( LowerCaseStr StrLength );\nuse Type::Utils;\n\nmy $ShortLcStr = intersection ShortLcStr => [ LowerCaseStr, StrLength[4, 8] ];\n\nhas identifier => (\nis   => 'ro',\nisa  => $ShortLcStr,\n);\n}\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Intersection type constraints.\n\nIntersection type constraints are not often very useful. Consider the intersection of HashRef\nand ArrayRef. A value will only pass if it is both a hashref and an arrayref. Given that neither\nof those type constraints accept \"undef\" or overloaded objects, there is no possible value that\ncan pass both.\n\nWhich is not to say that intersections are never useful, but it happens quite rarely.\n\nThis package inherits from Type::Tiny; see that for most documentation. Major differences are\nlisted below:\n",
            "subsections": [
                {
                    "name": "Constructor",
                    "content": "The \"new\" constructor from Type::Tiny still works, of course. But there is also:\n"
                },
                {
                    "name": "new_by_overload",
                    "content": "Like the \"new\" constructor, but will sometimes return another type constraint which is not\nstrictly an instance of Type::Tiny::Intersection, but still encapsulates the same meaning.\nThis constructor is used by Type::Tiny's overloading of the \"&\" operator.\n"
                },
                {
                    "name": "Attributes",
                    "content": "\"typeconstraints\"\nArrayref of type constraints.\n\nWhen passed to the constructor, if any of the type constraints in the intersection is itself\nan intersection type constraint, this is \"exploded\" into the new intersection.\n\n\"constraint\"\nUnlike Type::Tiny, you *cannot* pass a constraint coderef to the constructor. Instead rely\non the default.\n\n\"inlined\"\nUnlike Type::Tiny, you *cannot* pass an inlining coderef to the constructor. Instead rely on\nthe default.\n\n\"parent\"\nUnlike Type::Tiny, you *cannot* pass an inlining coderef to the constructor. A parent will\ninstead be automatically calculated.\n\n(Technically any of the types in the intersection could be treated as a parent type; we\nchoose the first arbitrarily.)\n"
                },
                {
                    "name": "Methods",
                    "content": ""
                },
                {
                    "name": "stringifies_to",
                    "content": "See Type::Tiny::ConstrainedObject.\n"
                },
                {
                    "name": "numifies_to",
                    "content": "See Type::Tiny::ConstrainedObject.\n\n\"withattributevalues($attr1 => $constraint1, ...)\"\nSee Type::Tiny::ConstrainedObject.\n"
                },
                {
                    "name": "Overloading",
                    "content": "*   Arrayrefification calls \"typeconstraints\".\n"
                }
            ]
        },
        "BUGS": {
            "content": "Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Type::Tiny::Manual.\n\nType::Tiny.\n\nMooseX::Meta::TypeConstraint::Intersection.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nWITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        }
    },
    "summary": "Type::Tiny::Intersection - intersection type constraints",
    "flags": [],
    "examples": [],
    "see_also": []
}