File: //usr/local/share/man/man3/Type::Tiny::Enum.3pm
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Type::Tiny::Enum 3"
.TH Type::Tiny::Enum 3 "2021-07-31" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Type::Tiny::Enum \- string enum type constraints
.SH "STATUS"
.IX Header "STATUS"
This module is covered by the
Type-Tiny stability policy.
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Enum type constraints.
.PP
This package inherits from Type::Tiny; see that for most documentation.
Major differences are listed below:
.SS "Attributes"
.IX Subsection "Attributes"
.ie n .IP """values""" 4
.el .IP "\f(CWvalues\fR" 4
.IX Item "values"
Arrayref of allowable value strings. Non-string values (e.g. objects with
overloading) will be stringified in the constructor.
.ie n .IP """constraint""" 4
.el .IP "\f(CWconstraint\fR" 4
.IX Item "constraint"
Unlike Type::Tiny, you \fIcannot\fR pass a constraint coderef to the constructor.
Instead rely on the default.
.ie n .IP """inlined""" 4
.el .IP "\f(CWinlined\fR" 4
.IX Item "inlined"
Unlike Type::Tiny, you \fIcannot\fR pass an inlining coderef to the constructor.
Instead rely on the default.
.ie n .IP """parent""" 4
.el .IP "\f(CWparent\fR" 4
.IX Item "parent"
Parent is always \fBTypes::Standard::Str\fR, and cannot be passed to the
constructor.
.ie n .IP """unique_values""" 4
.el .IP "\f(CWunique_values\fR" 4
.IX Item "unique_values"
The list of \f(CW\*(C`values\*(C'\fR but sorted and with duplicates removed. This cannot
be passed to the constructor.
.ie n .IP """coercion""" 4
.el .IP "\f(CWcoercion\fR" 4
.IX Item "coercion"
If \f(CW\*(C`coercion => 1\*(C'\fR is passed to the constructor, the type will have a
coercion using the \f(CW\*(C`closest_match\*(C'\fR method.
.SS "Methods"
.IX Subsection "Methods"
.ie n .IP """as_regexp""" 4
.el .IP "\f(CWas_regexp\fR" 4
.IX Item "as_regexp"
Returns the enum as a regexp which strings can be checked against. If you're
checking \fIa lot\fR of strings, then using this regexp might be faster than
checking each string against
.Sp
.Vb 3
\& my $enum = Type::Tiny::Enum\->new(...);
\& my $check = $enum\->compiled_check;
\& my $re = $enum\->as_regexp;
\&
\& # fast
\& my @valid_tokens = grep $enum\->check($_), @all_tokens;
\&
\& # faster
\& my @valid_tokens = grep $check\->($_), @all_tokens;
\&
\& # fastest
\& my @valid_tokens = grep /$re/, @all_tokens;
.Ve
.Sp
You can get a case-insensitive regexp using \f(CW\*(C`$enum\->as_regexp(\*(Aqi\*(Aq)\*(C'\fR.
.ie n .IP """closest_match""" 4
.el .IP "\f(CWclosest_match\fR" 4
.IX Item "closest_match"
Returns the closest match in the enum for a string.
.Sp
.Vb 3
\& my $enum = Type::Tiny::Enum\->new(
\& values => [ qw( foo bar baz quux ) ],
\& );
\&
\& say $enum\->closest_match("FO"); # ==> foo
.Ve
.Sp
It will try to find an exact match first, fall back to a case-insensitive
match, if it still can't find one, will try to find a head substring match,
and finally, if given an integer, will use that as an index.
.Sp
.Vb 3
\& my $enum = Type::Tiny::Enum\->new(
\& values => [ qw( foo bar baz quux ) ],
\& );
\&
\& say $enum\->closest_match( 0 ); # ==> foo
\& say $enum\->closest_match( 1 ); # ==> bar
\& say $enum\->closest_match( 2 ); # ==> baz
\& say $enum\->closest_match( \-1 ); # ==> quux
.Ve
.SS "Overloading"
.IX Subsection "Overloading"
.IP "\(bu" 4
Arrayrefification calls \f(CW\*(C`values\*(C'\fR.
.SH "BUGS"
.IX Header "BUGS"
Please report any bugs to
<https://github.com/tobyink/p5\-type\-tiny/issues>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Type::Tiny::Manual.
.PP
Type::Tiny.
.PP
Moose::Meta::TypeConstraint::Enum.
.SH "AUTHOR"
.IX Header "AUTHOR"
Toby Inkster <tobyink@cpan.org>.
.SH "COPYRIGHT AND LICENCE"
.IX Header "COPYRIGHT AND LICENCE"
This software is copyright (c) 2013\-2014, 2017\-2021 by Toby Inkster.
.PP
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
.SH "DISCLAIMER OF WARRANTIES"
.IX Header "DISCLAIMER OF WARRANTIES"
\&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0