![]() |
![]()
| ![]() |
![]()
NAMEType::Tiny::Enum - string enum type constraints SYNOPSISUsing via Types::Standard: package Horse { use Moo; use Types::Standard qw( Str Enum ); has name => ( is => 'ro', isa => Str ); has status => ( is => 'ro', isa => Enum[ 'alive', 'dead' ] ); sub neigh { my ( $self ) = @_; return if $self->status eq 'dead'; ...; } } Using Type::Tiny::Enum's export feature: package Horse { use Moo; use Types::Standard qw( Str ); use Type::Tiny::Enum Status => [ 'alive', 'dead' ]; has name => ( is => 'ro', isa => Str ); has status => ( is => 'ro', isa => Status, default => STATUS_ALIVE ); sub neigh { my ( $self ) = @_; return if $self->status eq STATUS_DEAD; ...; } } Using Type::Tiny::Enum's object-oriented interface: package Horse { use Moo; use Types::Standard qw( Str ); use Type::Tiny::Enum; my $Status = Type::Tiny::Enum->new( name => 'Status', values => [ 'alive', 'dead' ], ); has name => ( is => 'ro', isa => Str ); has status => ( is => 'ro', isa => $Status, default => $Status->[0] ); sub neigh { my ( $self ) = @_; return if $self->status eq $Status->[0]; ...; } } STATUSThis module is covered by the Type-Tiny stability policy. DESCRIPTIONEnum type constraints. This package inherits from Type::Tiny; see that for most documentation. Major differences are listed below: ConstructorsThe "new" constructor from Type::Tiny still works, of course. But there is also:
Attributes
Methods
ExportsType::Tiny::Enum can be used as an exporter. use Type::Tiny::Enum Status => [ 'dead', 'alive' ]; This will export the following functions into your namespace:
Multiple enumerations can be exported at once: use Type::Tiny::Enum ( Status => [ 'dead', 'alive' ], TaxStatus => [ 'paid', 'pending' ], ); Overloading
BUGSPlease report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. SEE ALSOType::Tiny::Manual. Type::Tiny. Moose::Meta::TypeConstraint::Enum. AUTHORToby Inkster <tobyink@cpan.org>. COPYRIGHT AND LICENCEThis 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 WARRANTIESTHIS 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.
|