From: John Napiorkowski Date: Fri, 5 Dec 2008 00:37:46 +0000 (+0000) Subject: got working prototype, but relies on uncommited changes to Moose::Meta::TypeConstraint X-Git-Tag: 0.06~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=968cdea9c36be9b917bac2e24bb7639be13769f5;p=gitmo%2FMooseX-Types-Structured.git got working prototype, but relies on uncommited changes to Moose::Meta::TypeConstraint --- diff --git a/t/09-optional.t b/t/09-optional.t index 0ded179..e1c3a78 100755 --- a/t/09-optional.t +++ b/t/09-optional.t @@ -4,24 +4,21 @@ use warnings; use Test::More tests=>15; use Moose::Util::TypeConstraints; use Moose::Meta::TypeConstraint::Parameterizable; -use Moose; + use Data::Dump qw/dump/; ## Sketch for how this could work + ok my $Optional = Moose::Meta::TypeConstraint::Parameterizable->new( name => 'Optional', package_defined_in => __PACKAGE__, parent => find_type_constraint('Item'), constraint => sub { 1 }, constraint_generator => sub { - my $type_parameter = shift; - my $check = $type_parameter->_compiled_type_constraint; + my ($type_parameter, @args) = @_; + my $check = $type_parameter->_compiled_type_constraint(); return sub { - my (@args) = @_; - warn dump [@args]; - warn exists $args[0]? "exists":"null"; - warn defined $args[0]? "defined":"undef"; - + my (@args) = @_; if(exists($args[0])) { ## If it exists, we need to validate it $check->($args[0]); @@ -48,10 +45,6 @@ ok my $arrayref = Moose::Util::TypeConstraints::find_or_parse_type_constraint('A ok my $Optional_Int = $Optional->parameterize($int), 'Parameterized Int'; ok my $Optional_ArrayRef = $Optional->parameterize($arrayref), 'Parameterized ArrayRef'; -$Optional_Int->check(); - -die; - ok $Optional_Int->check() => 'Optional is allowed to not exist'; ok !$Optional_Int->check(undef) => 'Optional is NOT allowed to be undef';