X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FTypeConstraint.pm;h=3eb6eb61b6f9e335e0038641f9ad1ff36ac38167;hp=9b1acc789f08b4c665b5f321504e64a053bffa38;hb=935400114c35ad1b2481c48ff471e180e9c93d93;hpb=2125ee6b834fe1e8e917df6e1bf7f7059d9579fc diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 9b1acc7..3eb6eb6 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -2,7 +2,7 @@ package Mouse::Meta::TypeConstraint; use Mouse::Util qw(:meta); # enables strict and warnings use overload - '""' => sub { shift->{name} }, # stringify to tc name + '""' => sub { $_[0]->name }, # stringify to tc name fallback => 1; use Carp qw(confess); @@ -183,13 +183,11 @@ sub check { sub coerce { my $self = shift; - if(!$self->{_compiled_type_coercion}){ - confess("Cannot coerce without a type coercion ($self)"); - } return $_[0] if $self->_compiled_type_constraint->(@_); - return $self->{_compiled_type_coercion}->(@_); + my $coercion = $self->_compiled_type_coercion; + return $coercion ? $coercion->(@_) : $_[0]; } sub get_message {