From: Hans Dieter Pearcey Date: Fri, 24 Apr 2009 20:37:59 +0000 (-0400) Subject: simpler test case X-Git-Tag: 0.76~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a232d913b9544a5d2597dec1359c9a80cb7698fd;p=gitmo%2FMoose.git simpler test case --- diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 559ef20..1671d07 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -82,8 +82,6 @@ sub coerce { Moose->throw_error("Cannot coerce without a type coercion"); } - return $_[0] if $self->check($_[0]); - return $coercion->coerce(@_); } diff --git a/t/040_type_constraints/005_util_type_coercion.t b/t/040_type_constraints/005_util_type_coercion.t index a6feaa4..64e4684 100644 --- a/t/040_type_constraints/005_util_type_coercion.t +++ b/t/040_type_constraints/005_util_type_coercion.t @@ -89,22 +89,14 @@ foreach my $coercion ( } } -subtype 'MyHashRef' - => as 'HashRef' - => where { $_->{is_awesome} }; +subtype 'StrWithTrailingX' + => as 'Str' + => where { /X$/ }; -coerce 'MyHashRef' - => from 'HashRef' - => via { $_->{my_hash_ref} }; +coerce 'StrWithTrailingX' + => from 'Str' + => via { $_ . 'X' }; -my $tc = find_type_constraint('MyHashRef'); -is_deeply( - $tc->coerce({ my_hash_ref => { is_awesome => 1 } }), - { is_awesome => 1 }, - "coercion runs on HashRef (not MyHashRef)", -); -is_deeply( - $tc->coerce({ is_awesome => 1 }), - { is_awesome => 1 }, - "did not coerce MyHashRef", -); +my $tc = find_type_constraint('StrWithTrailingX'); +is($tc->coerce("foo"), "fooX", "coerce when needed"); +is($tc->coerce("fooX"), "fooX", "do not coerce when unneeded");