4 use Test::More tests=>15;
5 use Moose::Util::TypeConstraints;
6 use Moose::Meta::TypeConstraint::Parameterizable;
10 ok my $Optional = Moose::Meta::TypeConstraint::Parameterizable->new(
12 package_defined_in => __PACKAGE__,
13 parent => find_type_constraint('Item'),
14 constraint => sub { 1 },
15 constraint_generator => sub {
16 my $type_parameter = shift;
17 my $check = $type_parameter->_compiled_type_constraint;
20 if(exists($args[0])) {
21 ## If it exists, we need to validate it
24 ## But it's is okay if the value doesn't exists
31 Moose::Util::TypeConstraints::add_parameterizable_type($Optional);
32 use Data::Dump qw/dump/;
34 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
35 if (my $constraint = $type->generate_constraint_for($Optional)) {
36 warn 'got this FARRRRRR..........................................';
42 isa_ok $Optional, 'Moose::Meta::TypeConstraint::Parameterizable';
44 ok my $int = find_type_constraint('Int') => 'Got Int';
45 ok my $arrayref = find_type_constraint('ArrayRef[Int]') => 'Got ArrayRef[Int]';
47 ok my $Optional_Int = $Optional->parameterize($int);
48 ok my $Optional_ArrayRef = $Optional->parameterize($arrayref);
51 ok $Optional_Int->check() => 'Optional is allowed to not exist';
52 ok !$Optional_Int->check(undef) => 'Optional is NOT allowed to be undef';
53 ok $Optional_Int->check(199) => 'Correctly validates 199';
54 ok !$Optional_Int->check("a") => 'Correctly fails "a"';
56 ok $Optional_ArrayRef->check() => 'Optional is allowed to not exist';
57 ok !$Optional_ArrayRef->check(undef) => 'Optional is NOT allowed to be undef';
58 ok $Optional_ArrayRef->check([1,2,3]) => 'Correctly validates [1,2,3]';
59 ok !$Optional_ArrayRef->check("a") => 'Correctly fails "a"';
60 ok !$Optional_ArrayRef->check(["a","b"]) => 'Correctly fails ["a","b"]';