X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FEnum.pm;h=80675d8e83bbe99e6292b2a8d2fef5e541a95d23;hb=55d05fb16429c2150b5337b1a0130ae334e129d0;hp=29f3f2620e68d162428da82db98c43732fb7a17e;hpb=e462f6f3d260687b8f7372b112a50c5c2a2c431c;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Enum.pm b/lib/Moose/Meta/TypeConstraint/Enum.pm index 29f3f26..80675d8 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.05'; +our $VERSION = '1.12'; $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()