Improve enum to accept "enum($name, $arrayref)" construction
[gitmo/Mouse.git] / lib / Mouse / Util / TypeConstraints.pm
index 9658ca5..2b2d558 100644 (file)
@@ -184,16 +184,12 @@ sub typecast_constraints { # DEPRECATED
 sub enum {
     my($name, %valid);
 
-    # enum ['small', 'medium', 'large']
-    if (ref($_[0]) eq 'ARRAY') {
-        %valid = map{ $_ => undef } @{ $_[0] };
-        $name  = sprintf '(%s)', join '|', sort @{$_[0]};
-    }
-    # enum size => 'small', 'medium', 'large'
-    else{
-        $name  = shift;
-        %valid = map{ $_ => undef } @_;
+    if(!(@_ == 1 && ref($_[0]) eq 'ARRAY')){
+        $name = shift;
     }
+
+    %valid = map{ $_ => undef } (@_ == 1 && ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_);
+
     return _create_type 'type', $name => (
         optimized_as  => sub{ defined($_[0]) && !ref($_[0]) && exists $valid{$_[0]} },
 
@@ -342,7 +338,6 @@ sub find_or_create_isa_type_constraint {
 }
 
 1;
-
 __END__
 
 =head1 NAME
@@ -351,7 +346,7 @@ Mouse::Util::TypeConstraints - Type constraint system for Mouse
 
 =head1 VERSION
 
-This document describes Mouse version 0.40_03
+This document describes Mouse version 0.43
 
 =head2 SYNOPSIS
 
@@ -419,18 +414,18 @@ yet to have been created, is to quote the type name:
 This module also provides a simple hierarchy for Perl 5 types, here is
 that hierarchy represented visually.
 
-  Any
+ Any
   Item
       Bool
       Maybe[`a]
       Undef
       Defined
           Value
-              Num
-                Int
               Str
-                ClassName
-                RoleName
+                  Num
+                      Int
+                  ClassName
+                  RoleName
           Ref
               ScalarRef
               ArrayRef[`a]
@@ -438,7 +433,7 @@ that hierarchy represented visually.
               CodeRef
               RegexpRef
               GlobRef
-                FileHandle
+                  FileHandle
               Object
 
 B<NOTE:> Any type followed by a type parameter C<[`a]> can be