removed parenthesis hackage and updated docs
John Napiorkowski [Mon, 22 Sep 2008 14:38:50 +0000 (14:38 +0000)]
lib/MooseX/Types.pm
t/13_typedecorator.t
t/lib/DecoratorLibrary.pm

index 364faa2..f2c60a7 100644 (file)
@@ -56,17 +56,17 @@ my $UndefMsg = q{Action for type '%s' not yet defined in library '%s'};
       from Int,
           via { 1 };
 
-  # with parameterized constraints.  Please note the containing '(...)'
+  # with parameterized constraints.
   
   subtype ArrayRefOfPositiveInt,
-    as (ArrayRef[PositiveInt]);
+    as ArrayRef[PositiveInt];
     
   subtype ArrayRefOfAtLeastThreeNegativeInts,
-    as (ArrayRef[NegativeInt]),
+    as ArrayRef[NegativeInt],
     where { scalar(@$_) > 2 };
 
   subtype LotsOfInnerConstraints,
-    as (ArrayRef[ArrayRef[HashRef[Int]]]);
+    as ArrayRef[ArrayRef[HashRef[Int]]];
     
   # with TypeConstraint Unions
   
@@ -263,28 +263,6 @@ The fully qualified name of this type as L<Moose> knows it.
 A message that will be thrown when type functionality is used but the
 type does not yet exist.
 
-=back
-
-=head1 NOTES REGARDING PARAMETERIZED CONSTRAINTS
-
-L<MooseX::Types> uses L<MooseX::Types::TypeDecorator> to do some overloading
-which generally allows you to easily create types with parameters such as:
-
-    subtype ParameterType,
-      as (ArrayRef[Int]);
-
-However, due to an outstanding issue you will need to wrap the parameterized
-type inside parenthesis, as in the example above.  Hopefully this limitation
-will be lifted in a future version of this module.
-
-If you are using paramterized types in the options section of an attribute
-declaration, the parenthesis are not needed:
-
-    use Moose;
-    use MooseX::Types::Moose qw(HashRef Int);
-    
-    has 'attr' => (isa=>HashRef[Str]);
-
 =head1 NOTES REGARDING TYPE UNIONS
 
 L<MooseX::Types> uses L<MooseX::Types::TypeDecorator> to do some overloading
@@ -375,8 +353,13 @@ sub type_export_generator {
         $type_constraint = defined($type_constraint) ? $type_constraint
          : MooseX::Types::UndefinedType->new($name);
          
-        return $class->create_type_decorator($type_constraint);
+        my $type_decorator = $class->create_type_decorator($type_constraint);
         
+        if(@_) {
+            return ($type_decorator, @_);
+        } else {
+            return $type_decorator;
+        }
     };
 }
 
index 5104a82..c225938 100644 (file)
@@ -142,7 +142,7 @@ is_deeply $type->AtLeastOneInt, [1,2]
  
 throws_ok sub {
     $type->AtLeastOneInt([]);
-}, qr/Attribute \(AtLeastOneInt\) does not pass the type constraint/ => 'properly fails';
+}, qr/Attribute \(AtLeastOneInt\) does not pass the type constraint/ => 'properly fails to assign as []';
 
 throws_ok sub {
     $type->AtLeastOneInt(['a','b']);
index 9eee6ff..180a959 100644 (file)
@@ -59,20 +59,14 @@ coerce MyArrayRefInt02,
     via {[sort values(%$_)]},
     from MyHashRefOfStr,
     via {[ sort map { length $_ } values(%$_) ]},
-    ## Can't do HashRef[ArrayRef] here since if I do HashRef get the via {}
-    ## Stuff passed as args and the associated prototype messed with it.  MST
-    ## seems to have a line on it but might not fix fixable.
-    from (HashRef[ArrayRef]),
+    from HashRef[ArrayRef],
     via {[ sort map { @$_ } values(%$_) ]};
 
 subtype StrOrArrayRef,
     as Str|ArrayRef;
 
 subtype AtLeastOneInt,
-    ## Same problem as MyArrayRefInt02, see above.  Another way to solve it by
-    ## forcing some sort of context.  Tried to fix this with method prototypes
-    ## but just couldn't make it work.
-    as (ArrayRef[Int]),
+    as ArrayRef[Int],
     where { @$_ > 0 };
 
 1;