From: nperez Date: Thu, 21 May 2009 09:42:20 +0000 (-0500) Subject: Let the user know which constraint they have violated in the confessed message X-Git-Tag: 0.18_01~8^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-AttributeHelpers.git;a=commitdiff_plain;h=d071f896e163e4f4d15cc79e08a62d68cdfb05b9 Let the user know which constraint they have violated in the confessed message --- diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm index 400c46e..dd70274 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Array.pm @@ -15,7 +15,7 @@ sub push : method { return sub { my $instance = CORE::shift; $container_type_constraint->check($_) - || confess "Value " . ($_||'undef') . " did not pass container type constraint" + || confess "Value " . ($_||'undef') . " did not pass container type constraint '$container_type_constraint'" foreach @_; CORE::push @{$reader->($instance)} => @_; }; @@ -42,7 +42,7 @@ sub unshift : method { return sub { my $instance = CORE::shift; $container_type_constraint->check($_) - || confess "Value " . ($_||'undef') . " did not pass container type constraint" + || confess "Value " . ($_||'undef') . " did not pass container type constraint '$container_type_constraint'" foreach @_; CORE::unshift @{$reader->($instance)} => @_; }; @@ -75,7 +75,7 @@ sub set : method { my $container_type_constraint = $attr->type_constraint->type_parameter; return sub { ($container_type_constraint->check($_[2])) - || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint"; + || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint '$container_type_constraint'"; $reader->($_[0])->[$_[1]] = $_[2] }; } @@ -99,7 +99,7 @@ sub accessor : method { } elsif (@_ == 2) { # writer ($container_type_constraint->check($_[1])) - || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint"; + || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'"; $reader->($self)->[$_[0]] = $_[1]; } else { @@ -144,7 +144,7 @@ sub insert : method { my $container_type_constraint = $attr->type_constraint->type_parameter; return sub { ($container_type_constraint->check($_[2])) - || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint"; + || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint '$container_type_constraint'"; CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2]; }; } @@ -162,7 +162,7 @@ sub splice : method { return sub { my ( $self, $i, $j, @elems ) = @_; ($container_type_constraint->check($_)) - || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint" for @elems; + || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint '$container_type_constraint'" for @elems; CORE::splice @{$reader->($self)}, $i, $j, @elems; }; } diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm index e3f03f9..6d25ed3 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm @@ -19,7 +19,7 @@ sub set : method { while ( @kvp ) { my ( $key, $value ) = ( shift(@kvp), shift(@kvp) ); ($container_type_constraint->check($value)) - || confess "Value " . ($value||'undef') . " did not pass container type constraint"; + || confess "Value " . ($value||'undef') . " did not pass container type constraint '$container_type_constraint'"; push @keys, $key; push @values, $value; } @@ -63,7 +63,7 @@ sub accessor : method { } elsif (@_ == 2) { # writer ($container_type_constraint->check($_[1])) - || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint"; + || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'"; $reader->($self)->{$_[0]} = $_[1]; } else {