{
    "mode": "perldoc",
    "parameter": "Type::Tiny::Enum",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AEnum/json",
    "generated": "2026-06-12T00:03:09Z",
    "sections": {
        "NAME": {
            "content": "Type::Tiny::Enum - string enum type constraints\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Enum type constraints.\n\nThis package inherits from Type::Tiny; see that for most documentation. Major differences are\nlisted below:\n",
            "subsections": [
                {
                    "name": "Attributes",
                    "content": "\"values\"\nArrayref of allowable value strings. Non-string values (e.g. objects with overloading) will\nbe stringified in the constructor.\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\"\nParent is always Types::Standard::Str, and cannot be passed to the constructor.\n\n\"uniquevalues\"\nThe list of \"values\" but sorted and with duplicates removed. This cannot be passed to the\nconstructor.\n\n\"coercion\"\nIf \"coercion => 1\" is passed to the constructor, the type will have a coercion using the\n\"closestmatch\" method.\n"
                },
                {
                    "name": "Methods",
                    "content": "\"asregexp\"\nReturns the enum as a regexp which strings can be checked against. If you're checking *a\nlot* of strings, then using this regexp might be faster than checking each string against\n\nmy $enum  = Type::Tiny::Enum->new(...);\nmy $check = $enum->compiledcheck;\nmy $re    = $enum->asregexp;\n\n# fast\nmy @validtokens = grep $enum->check($), @alltokens;\n\n# faster\nmy @validtokens = grep $check->($), @alltokens;\n\n# fastest\nmy @validtokens = grep /$re/, @alltokens;\n\nYou can get a case-insensitive regexp using \"$enum->asregexp('i')\".\n\n\"closestmatch\"\nReturns the closest match in the enum for a string.\n\nmy $enum = Type::Tiny::Enum->new(\nvalues => [ qw( foo bar baz quux ) ],\n);\n\nsay $enum->closestmatch(\"FO\");   # ==> foo\n\nIt will try to find an exact match first, fall back to a case-insensitive match, if it still\ncan't find one, will try to find a head substring match, and finally, if given an integer,\nwill use that as an index.\n\nmy $enum = Type::Tiny::Enum->new(\nvalues => [ qw( foo bar baz quux ) ],\n);\n\nsay $enum->closestmatch(  0 );  # ==> foo\nsay $enum->closestmatch(  1 );  # ==> bar\nsay $enum->closestmatch(  2 );  # ==> baz\nsay $enum->closestmatch( -1 );  # ==> quux\n"
                },
                {
                    "name": "Overloading",
                    "content": "*   Arrayrefification calls \"values\".\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\nMoose::Meta::TypeConstraint::Enum.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017-2021 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::Enum - string enum type constraints",
    "flags": [],
    "examples": [],
    "see_also": []
}