X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FEnum.pm;h=54b558120be59a92754b7664d30932d6ec3d4c40;hb=462bdc732ebe32abf5b9f3cd40033540a5f1388f;hp=25279b1fa3a01b54c8e2fbf6bf2aa0a42f5be628;hpb=56d7c7453888ed2c684bcdb1d905841d8d03aeb1;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Enum.pm b/lib/Moose/Meta/TypeConstraint/Enum.pm index 25279b1..54b5581 100644 --- a/lib/Moose/Meta/TypeConstraint/Enum.pm +++ b/lib/Moose/Meta/TypeConstraint/Enum.pm @@ -6,10 +6,6 @@ use metaclass; use Moose::Util::TypeConstraints (); -our $VERSION = '0.73'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - use base 'Moose::Meta::TypeConstraint'; __PACKAGE__->meta->add_attribute('values' => ( @@ -21,6 +17,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() @@ -74,14 +86,12 @@ sub create_child_type { 1; +# ABSTRACT: Type constraint for enumerated values. + __END__ =pod -=head1 NAME - -Moose::Meta::TypeConstraint::Enum - Type constraint for enumerated values. - =head1 DESCRIPTION This class represents type constraints based on an enumerated list of @@ -98,7 +108,7 @@ L. =item B<< Moose::Meta::TypeConstraint::Enum->new(%options) >> -This creates a new class type constraint based on the given +This creates a new enum type constraint based on the given C<%options>. It takes the same options as its parent, with several @@ -107,7 +117,7 @@ should be an array reference containing a list of valid string values. Second, it automatically sets the parent to the C type. Finally, it ignores any provided C option. The constraint -is generated automatically based on the provided C +is generated automatically based on the provided C. =item B<< $constraint->values >> @@ -126,22 +136,7 @@ object! =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Yuval Kogman Enothingmuch@cpan.orgE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +See L for details on reporting bugs. =cut