From: John Napiorkowski Date: Mon, 22 Sep 2008 14:38:50 +0000 (+0000) Subject: removed parenthesis hackage and updated docs X-Git-Tag: 0.06~4^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types.git;a=commitdiff_plain;h=d9002a8523567e24b0787a81d891928f937bd6af removed parenthesis hackage and updated docs --- diff --git a/lib/MooseX/Types.pm b/lib/MooseX/Types.pm index 364faa2..f2c60a7 100644 --- a/lib/MooseX/Types.pm +++ b/lib/MooseX/Types.pm @@ -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 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 uses L 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 uses L 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; + } }; } diff --git a/t/13_typedecorator.t b/t/13_typedecorator.t index 5104a82..c225938 100644 --- a/t/13_typedecorator.t +++ b/t/13_typedecorator.t @@ -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']); diff --git a/t/lib/DecoratorLibrary.pm b/t/lib/DecoratorLibrary.pm index 9eee6ff..180a959 100644 --- a/t/lib/DecoratorLibrary.pm +++ b/t/lib/DecoratorLibrary.pm @@ -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;