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
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
$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;
+ }
};
}
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;