Moose::TypeConstraint->create_structured(%opt, %signature_opts);
Moose::TypeConstraint->create_parameterized(%opt, %);
+Or some sort of pattern for type constraints that accept args?
+
then a ...->create(%opt) that chooses one of the above????
=cut
+use Data::Dump qw/dump/;
+
sub type_export_generator {
my ($class, $type, $full) = @_;
return sub {
- my @args = @_;
- #use Data::Dump qw/dump/; warn dump @args if @args;
+ ## todo, this needs to be some sort of ->process_args on the actual
+ ## containing type constraints. This is ugly proof of concept
+ if(my $param = shift @_) {
+ #my @tc_args = map { find_type_constraint($full) } @args;
+ $full = $full .'['. $param->[0]->name .']';
+ }
+
my $type_constraint = find_type_constraint($full)
|| MooseX::Types::UndefinedType->new($full);
-
- if(@args) {
- my $tc = $args[0]->[0];
- # warn dump $tc;
- # $type_constraint->type_constraint($tc);
- }
+
return MooseX::Types::TypeDecorator->new(type_constraint=>$type_constraint);
};
}
## test arrayrefint01 normal and coercion
-ok $type->arrayrefint01([qw(a b c)])
- => 'Assigned arrayrefbase qw(a b c)';
+ok $type->arrayrefint01([qw(1 2 3)])
+ => 'Assigned arrayrefbase qw(1 2 3)';
-is_deeply $type->arrayrefint01, [qw(a b c)],
+is_deeply $type->arrayrefint01, [qw(1 2 3)],
=> 'Assigment is correct';
-ok $type->arrayrefint01('d.e.f')
- => 'Assigned arrayrefbase d,e,f to test coercion';
+ok $type->arrayrefint01('4.5.6')
+ => 'Assigned arrayrefbase 4.5.6 to test coercion from Str';
-is_deeply $type->arrayrefint01, [qw(d e f)],
+is_deeply $type->arrayrefint01, [qw(4 5 6)],
=> 'Assigment and coercion is correct';
+ok $type->arrayrefint01({a=>7,b=>8})
+ => 'Assigned arrayrefbase {a=>7,b=>8} to test coercion from HashRef';
+
+is_deeply $type->arrayrefint01, [qw(7 8)],
+ => 'Assigment and coercion is correct';
+
#use Data::Dump qw/dump/;
#warn dump MyArrayRefInt01;
#warn dump MyArrayRefBase->validate('aaa,bbb,ccc');