From: Dave Rolsky Date: Thu, 8 Jul 2010 23:31:31 +0000 (-0500) Subject: Include type name in error when coerce => 1 is given for a type without a coercion X-Git-Tag: 1.09~55 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=470bc6528ad1694103c9caddf7d4fecce8166fa8;p=gitmo%2FMoose.git Include type name in error when coerce => 1 is given for a type without a coercion --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index f82b863..dfdfbbe 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -323,8 +323,10 @@ sub _process_options { $class->throw_error("You cannot have a weak reference to a coerced value on attribute ($name)", data => $options) if $options->{weak_ref}; - $options->{type_constraint}->has_coercion - || $class->throw_error("You cannot coerce an attribute ($name) unless its type has a coercion", data => $options); + unless ( $options->{type_constraint}->has_coercion ) { + my $type = $options->{type_constraint}->name; + $class->throw_error("You cannot coerce an attribute ($name) unless its type ($type) has a coercion", data => $options); + } } if (exists $options->{trigger}) { diff --git a/t/020_attributes/034_bad_coerce.t b/t/020_attributes/034_bad_coerce.t index 10d234b..da987ab 100644 --- a/t/020_attributes/034_bad_coerce.t +++ b/t/020_attributes/034_bad_coerce.t @@ -16,7 +16,7 @@ use Test::Exception; isa => 'Str', coerce => 1, ); - } qr/\QYou cannot coerce an attribute (foo) unless its type has a coercion/, + } qr/\QYou cannot coerce an attribute (foo) unless its type (Str) has a coercion/, 'Cannot coerce unless the type has a coercion'; }