From: Ricardo Signes Date: Wed, 5 Oct 2011 14:25:26 +0000 (-0400) Subject: allow single-value enums X-Git-Tag: 2.0301~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c748165a457d3e8768ffc48e5e3bcf5bb73a41c;p=gitmo%2FMoose.git allow single-value enums --- diff --git a/lib/Moose/Meta/TypeConstraint/Enum.pm b/lib/Moose/Meta/TypeConstraint/Enum.pm index 7b52645..3ef7234 100644 --- a/lib/Moose/Meta/TypeConstraint/Enum.pm +++ b/lib/Moose/Meta/TypeConstraint/Enum.pm @@ -36,9 +36,9 @@ sub new { $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str'); $args{inlined} = $inliner; - if ( scalar @{ $args{values} } < 2 ) { + if ( scalar @{ $args{values} } < 1 ) { require Moose; - Moose->throw_error("You must have at least two values to enumerate through"); + Moose->throw_error("You must have at least one value to enumerate through"); } for (@{ $args{values} }) { diff --git a/t/type_constraints/enum.t b/t/type_constraints/enum.t index 6a55ec1..7349c48 100644 --- a/t/type_constraints/enum.t +++ b/t/type_constraints/enum.t @@ -63,9 +63,9 @@ ok( !$anon_enum->is_subtype_of('ThisTypeDoesNotExist'), 'enum not a subtype of n ok( !$anon_enum->is_a_type_of('ThisTypeDoesNotExist'), 'enum not type of nonexistant type'); # validation -like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ZeroValues', values => []) }, qr/You must have at least two values to enumerate through/ ); +like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ZeroValues', values => []) }, qr/You must have at least one value to enumerate through/ ); -like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'OneValue', values => [ 'a' ]) }, qr/You must have at least two values to enumerate through/ ); +is( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'OneValue', values => [ 'a' ]) }, undef); like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ReferenceInEnum', values => [ 'a', {} ]) }, qr/Enum values must be strings, not 'HASH\(0x\w+\)'/ );