Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 92591
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.038
Fixed in: (no value)



Subject: anonymous coercions (via declare_coercion) ignore passed coercion maps if not in a Type::Library
I'm trying to construct an anonymous coercion using Type::Utils::declare_coercion in a class definition (not a type library). e.g., my $foo = declare_coercion to_type ArrayRef, from Any, via { [$_] }; However, it looks like declare_coercion only pays attention to the "type, coderef" arguments if it is called from a type library. Attached is some test code, which results in the following output: ok 1 - Type library, coercion mapped not ok 2 - Not in Type library, coercion mapped # Failed test 'Not in Type library, coercion mapped' # at coerce2 line 28. # got: undef # expected: 'Any' 1..2 Bug or Feature? The documentation for "declare" explicitly notes that it can be used outside of a type library. While that for "declare_coercion" doesn't, it seems a reasonable assumption that it would. Thanks, Diab
Subject: anonymous_coercion.t
#! perl use Test::More; { package lib; use Test::More; use Type::Library -base; use Types::Standard -all; use Type::Utils -all; my $foo = declare_coercion to_type ArrayRef, from Any, via { [$_] }; is( $foo->type_coercion_map->[0], 'Any', "Type library, coercion mapped" ); } { package notlib; use Test::More; use Types::Standard -all; use Type::Utils -all; my $foo = declare_coercion to_type ArrayRef, from Any, via { [$_] }; is( $foo->type_coercion_map->[0], 'Any', "Not in Type library, coercion mapped" ); } done_testing;
This looks like a bug to me.
Fixed in 0.040.