Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 42544
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: stevan.little [...] gmail.com
Requestors: perl [...] galumph.com
Cc:
AdminCc:

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



Subject: Type constraint violations don't use custom messages when the type being violated isn't the immediate type of a variable.
Date: Mon, 19 Jan 2009 17:17:45 -0600
To: bug-Moose [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
With this code package Foo; use Moose; use Moose::Util::TypeConstraints; subtype 'MyType' => as 'Str' => where { m/foo/ } => message { qq/"$_" doesn't look like foo./ }; subtype 'MyTypeList' => as 'ArrayRef[MyType]'; has 'foo' => (is => 'rw', isa => 'MyTypeList'); package main; Foo->new( foo => ['bar'] ); the resulting exception does not include the content of the custom message, which makes it hard to figure out what's wrong.
Subject: Re: [rt.cpan.org #42544] Type constraint violations don't use custom messages when the type being violated isn't the immediate type of a variable.
Date: Mon, 19 Jan 2009 17:28:28 -0600 (CST)
To: Elliot Shank via RT <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 19 Jan 2009, Elliot Shank via RT wrote: Show quoted text
> package Foo; > > use Moose; > use Moose::Util::TypeConstraints; > > > subtype 'MyType' > => as 'Str' > => where { m/foo/ } > => message { qq/"$_" doesn't look like foo./ }; > > subtype 'MyTypeList' > => as 'ArrayRef[MyType]';
This extra subtype is a red herring. Show quoted text
> has 'foo' => (is => 'rw', isa => 'MyTypeList');
Even with has 'foo' => (is => 'rw', isa => 'ArrayRef[MyType]'); it _still_ gives the same unhelpful message. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
The type violation is on the MyTypeList, not on the MyType because that is what is being checked against. Type constraints do not work that way. This is the same reasoning why coercions for MyType would not apply to the items within a MyTypeList. This is not a bug, more of a feature request and unfortunately not a simple feature (ex: how would you resolve the message for this type ArrayRef[HashRef[MyTypeList|Str]]? the problem grows in complexity pretty quickly). The current solution is to add a message to your MyTypeList. - Stevan
Subject: Re: [rt.cpan.org #42544] Type constraint violations don't use custom messages when the type being violated isn't the immediate type of a variable.
Date: Mon, 19 Jan 2009 19:29:58 -0600
To: bug-Moose [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Stevan Little via RT wrote: Show quoted text
> The type violation is on the MyTypeList, not on the MyType because that is what is being > checked against.
Oog. The constraint on MyType gets copied into the constraint on MyTypeList, so at the time the constraint is violated, the link to MyType is gone. Well, there's a case where efficiency sucks.
This feature may get supported in the big type-system re-write (which will probably happen soon), but for now it is not a bug but just "how things work" - Stevan