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