Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

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

People
Owner: stevan.little [...] gmail.com
Requestors: charlie-perl [...] aldermania.com
Cc:
AdminCc:

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



Subject: Moose::Util::TypeConstraint type/subtype error messages
Date: Wed, 09 Jul 2008 16:21:15 -0400
To: bug-Moose [...] rt.cpan.org
From: Charles Alderman <charlie-perl [...] aldermania.com>
$Moose::Version eq '0.54' Regarding type() and subtype() under Moose::Util::TypeConstraint: $_ passed to the message clause is a stringyfied version of the value passed into an attribute declared of that custom type. It seems like $_ should be the actual value, just like the $_ in the where clause of the custom type. Here's an example: package MyObject; use Moose; package Foo; use Moose; use Moose::Util::TypeConstraints; subtype 'MyArrayRef' => as 'ArrayRef' => where { $_->[0] eq 'some element' } => message { ref $_ ? "ref: ". ref $_ : 'scalar' } # stringy looking 'ARRAY(0x123..)' ; subtype 'MyObjectType' => as 'Object' => where { $_->isa('MyObject') } => message { if ( $_->isa('SomeObject') ) { return 'More detailed error message'; } elsif ( blessed $_ ) { return 'Well it is an object'; } else { return 'Doh!'; } } ; type 'NewType' => where { $_->isa('MyObject') } => message { blessed $_ ? 'blessed' : 'scalar' } ; has 'obj' => ( is => 'rw', isa => 'MyObjectType' ); has 'ar' => ( is => 'rw', isa => 'MyArrayRef' ); has 'nt' => ( is => 'rw', isa => 'NewType' ); package main; my $foo = Foo->new; my $obj = MyObject->new; # Error message $foo->ar([]); # scalar $foo->obj($foo); # Doh! $foo->nt($foo); # scalar Thanks, Charles Alderman
Charles, This is fixed in the svn HEAD (http://code2.0beta.co.uk/moose/svn/Moose/trunk/), and will be in 0.55 when that is released. Thanks, - Stevan
I just uploaded Moose 0.55, so this is now really truly fixed. :)