1Type::Tiny::Enum(3) User Contributed Perl Documentation Type::Tiny::Enum(3)
2
3
4
6 Type::Tiny::Enum - string enum type constraints
7
9 This module is covered by the Type-Tiny stability policy.
10
12 Enum type constraints.
13
14 This package inherits from Type::Tiny; see that for most documentation.
15 Major differences are listed below:
16
17 Attributes
18 "values"
19 Arrayref of allowable value strings. Non-string values (e.g.
20 objects with overloading) will be stringified in the constructor.
21
22 "constraint"
23 Unlike Type::Tiny, you cannot pass a constraint coderef to the
24 constructor. Instead rely on the default.
25
26 "inlined"
27 Unlike Type::Tiny, you cannot pass an inlining coderef to the
28 constructor. Instead rely on the default.
29
30 "parent"
31 Parent is always Types::Standard::Str, and cannot be passed to the
32 constructor.
33
34 "unique_values"
35 The list of "values" but sorted and with duplicates removed. This
36 cannot be passed to the constructor.
37
38 Methods
39 "as_regexp"
40 Returns the enum as a regexp which strings can be checked against.
41 If you're checking a lot of strings, then using this regexp might
42 be faster than checking each string against
43
44 my $enum = Type::Tiny::Enum->new(...);
45 my $check = $enum->compiled_check;
46 my $re = $enum->as_regexp;
47
48 # fast
49 my @valid_tokens = grep $enum->check($_), @all_tokens;
50
51 # faster
52 my @valid_tokens = grep $check->($_), @all_tokens;
53
54 # fastest
55 my @valid_tokens = grep /$re/, @all_tokens;
56
57 You can get a case-insensitive regexp using
58 "$enum->as_regexp('i')".
59
60 Overloading
61 ยท Arrayrefification calls "values".
62
64 Please report any bugs to
65 <http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny>.
66
68 Type::Tiny::Manual.
69
70 Type::Tiny.
71
72 Moose::Meta::TypeConstraint::Enum.
73
75 Toby Inkster <tobyink@cpan.org>.
76
78 This software is copyright (c) 2013-2014, 2017-2020 by Toby Inkster.
79
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82
84 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
85 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
86 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
87
88
89
90perl v5.32.0 2020-09-17 Type::Tiny::Enum(3)