On 24/08/2009, at 4:45 AM, Hans Dieter Pearcey wrote:
Background: http://rt.cpan.org/Public/Bug/Display.html?id=48849
This fails:
coerce ArrayRef[MyObject],
from ArrayRef[HashRef],
via { [ map { MyObject->new($_) } @$_ ] };
# later
has objects => (isa => ArrayRef[MyObject], coerce => 1);
It succeeds with a subtype of ArrayRef[MyObject] or if the generated
type
constraint is saved in a variable and reused in the 'isa'.
<snip>
Three possibilities come to mind:
1. provide a helper function to twiddle some global in MooseX::Types
to avoid
auto-registering the parameterized types that are generated:
my $tc = unregistered_type_constraint { Tuple[ArrayRef[Str], Int,
GlobRef] };
2. Tell people to manually register the parameterized types that
they want to
use:
register_type_constraint ArrayRef[MyObject];
3. Have the 'coerce' sugar automatically register parameterized type
constraints and make sure that there's an alternative API for
programmatic TC
generation (e.g. MXMS) to use that avoids the automatic behavior.
I ran into this issue last week. As a complete 'end-user', I vote for
which ever makes it easiest to provide the parameterised type to my
classes without any extra knowledge of the inner workings of TCs, so I
guess that is number 3?
Tom