X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FEnum.pm;h=9d9e91acbf9620eac15da8684ecd4adbfbf36b19;hb=0953b5a4784ae9e36130d87ad9bff255b5c581c8;hp=c5a1981cfb4c9aa564162ce850204228fde103ac;hpb=3eb89f709f04907580b508f821d6be2316fcb65f;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Enum.pm b/lib/Moose/Meta/TypeConstraint/Enum.pm index c5a1981..9d9e91a 100644 --- a/lib/Moose/Meta/TypeConstraint/Enum.pm +++ b/lib/Moose/Meta/TypeConstraint/Enum.pm @@ -6,7 +6,7 @@ use metaclass; use Moose::Util::TypeConstraints (); -our $VERSION = '1.01'; +our $VERSION = '1.15'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -21,6 +21,22 @@ sub new { $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str'); + if ( scalar @{ $args{values} } < 2 ) { + require Moose; + Moose->throw_error("You must have at least two values to enumerate through"); + } + + for (@{ $args{values} }) { + if (!defined($_)) { + require Moose; + Moose->throw_error("Enum values must be strings, not undef"); + } + elsif (ref($_)) { + require Moose; + Moose->throw_error("Enum values must be strings, not '$_'"); + } + } + my $self = $class->_new(\%args); $self->compile_type_constraint()