10 use_ok("Moose::Util::TypeConstraints");
11 use_ok('Moose::Meta::TypeConstraint::Parameterized');
18 bless { items => \@_ }, $class;
23 return @{ $self->{items} };
27 subtype 'MyList' => as 'Object' => where { $_->isa('MyList') };
32 => via { [ $_->items ] }
33 }, undef, '... created the coercion okay' );
35 my $mylist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('MyList[Int]');
37 ok($mylist->check(MyList->new(10, 20, 30)), '... validated it correctly (pass)');
38 ok(!$mylist->check(MyList->new(10, "two")), '... validated it correctly (fail)');
39 ok(!$mylist->check([10]), '... validated it correctly (fail)');
41 subtype 'EvenList' => as 'MyList' => where { $_->items % 2 == 0 };
43 # XXX: get this to work *without* the declaration. I suspect it'll be a new
44 # method in Moose::Meta::TypeCoercion that will look at the parents of the
45 # coerced type as well. but will that be too "action at a distance"-ey?
49 => via { [ $_->items ] }
50 }, undef, '... created the coercion okay' );
52 my $evenlist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('EvenList[Int]');
54 ok(!$evenlist->check(MyList->new(10, 20, 30)), '... validated it correctly (fail)');
55 ok($evenlist->check(MyList->new(10, 20, 30, 40)), '... validated it correctly (pass)');
56 ok(!$evenlist->check(MyList->new(10, "two")), '... validated it correctly (fail)');
57 ok(!$evenlist->check([10, 20]), '... validated it correctly (fail)');