From: John Napiorkowski Date: Mon, 6 Apr 2009 18:11:30 +0000 (+0000) Subject: fixed incorrect alway finding an error with TC->validate X-Git-Tag: 0.12~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types-Structured.git;a=commitdiff_plain;h=d716430a1f595e7bd54039e440a0286102fc87f1 fixed incorrect alway finding an error with TC->validate --- diff --git a/Changes b/Changes index 0cfde2e..55d3b1e 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for MooseX-Types-Structured +0.11 06 April 2009 + - Fixed braindead bug in the way I override ->validate, which caused + valiate to never correctly pass a constraint. 0.10 02 April 2009 - Minor documentation grammar fixes and one major example error fixed - Much improved error reporting. Now we return the 'internal' error diff --git a/lib/MooseX/Meta/TypeConstraint/Structured.pm b/lib/MooseX/Meta/TypeConstraint/Structured.pm index dba4a5e..d7b655b 100644 --- a/lib/MooseX/Meta/TypeConstraint/Structured.pm +++ b/lib/MooseX/Meta/TypeConstraint/Structured.pm @@ -78,13 +78,13 @@ Messing with validate so that we can support niced error messages. override 'validate' => sub { my ($self, @args) = @_; - my $compiled_type_constraint = $self->_compiled_type_constraint; my $message = bless {message=>undef}, 'MooseX::Types::Structured::Message'; - my $result = $compiled_type_constraint->(@args, $message); - if($result) { - return $result; + if ($self->_compiled_type_constraint->(@args, $message)) { + ## Everything is good, no error message to return + return undef; } else { + ## Whoops, need to figure out the right error message my $args = Devel::PartialDump::dump(@args); if(my $message = $message->{message}) { return $self->get_message("$args, Internal Validation Error is: $message"); diff --git a/lib/MooseX/Types/Structured.pm b/lib/MooseX/Types/Structured.pm index 0030f8f..81e5d39 100644 --- a/lib/MooseX/Types/Structured.pm +++ b/lib/MooseX/Types/Structured.pm @@ -8,7 +8,7 @@ use MooseX::Types -declare => [qw(Dict Tuple Optional)]; use Sub::Exporter -setup => { exports => [ qw(Dict Tuple Optional slurpy) ] }; use Devel::PartialDump; -our $VERSION = '0.10'; +our $VERSION = '0.11'; our $AUTHORITY = 'cpan:JJNAPIORK'; =head1 NAME diff --git a/t/12-error.t b/t/12-error.t index 49c1b27..2c3ca14 100644 --- a/t/12-error.t +++ b/t/12-error.t @@ -1,7 +1,7 @@ BEGIN { use strict; use warnings; - use Test::More tests=>24; + use Test::More tests=>25; } use Moose::Util::TypeConstraints; @@ -119,3 +119,7 @@ ok $deep_tuple->check([1,{a=>2},{name=>'Vincent',age=>15}]), like $deep_tuple->validate([1,{a=>2},{name=>'Vincent',age=>'Hello'}]), qr/Error is: Validation failed for 'MooseX::Types::Structured::Dict\[name,Str,age,Int\]'/, 'Example deeper error'; + +## Success Tests... + +ok !$deep_tuple->validate([1,{a=>2},{name=>'John',age=>40}]), 'Validates ok';