Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

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

People
Owner: stevan.little [...] gmail.com
Requestors: dan.harbin [...] gmail.com
Cc:
AdminCc:

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



Subject: TypeConstraints do not observe the user-defined message
I coded the example from the Moose::Util::TypeConstraints POD. And it gives me the following error message rather than "This number ($_) is not less than ten!": Attribute (a) does not pass the type constraint (NaturalLessThanTen) with '11' at lib/Moose/Meta/Attribute.pm line 244 Moose::Meta::Attribute::initialize_instance_slot('Moose::Meta::Attribute=HASH(0x66e550)', 'Moose::Meta::Instance=HASH(0xb87900)', 'Testy=HASH(0xb879f0)', 'HASH(0x903460)') called at lib/Moose/Meta/Class.pm line 102 Moose::Meta::Class::construct_instance('Moose::Meta::Class=HASH(0xb7a220)', 'a', 11) called at lib/x86_64-linux/Class/MOP/Class.pm line 336 Class::MOP::Class::new_object('Moose::Meta::Class=HASH(0xb7a220)', 'a', 11) called at lib/Moose/Meta/Class.pm line 81 Moose::Meta::Class::new_object('Moose::Meta::Class=HASH(0xb7a220)', 'a', 11) called at lib/Moose/Object.pm line 28 Moose::Object::new('Testy', 'a', 11) called at ./messagebug.pl line 36 I've attached the code.
Subject: messagebug.pl
#!/usr/bin/env perl5.85 #use lib './lib'; I installed in ./lib, commented out for your testing package Testy; use Moose; use Moose::Util::TypeConstraints; #type 'Num' => where { Scalar::Util::looks_like_number($_) }; subtype 'Natural' => as 'Num' => where { $_ > 0 }; subtype 'NaturalLessThanTen' => as 'Natural' => where { $_ < 10 } => message { "This number ($_) is not less than ten!" }; coerce 'Num' => from 'Str' => via { 0+$_ }; enum 'RGBColors' => qw(red green blue); has 'a' => (isa => 'NaturalLessThanTen'); 1; package main; use strict; use warnings; my $o1 = Testy->new(a => 1); my $o2 = Testy->new(a => 11);
Dan, This is actually a well known issue, the message bit was added to support the ->validate method of the Moose::Meta::TypeConstraint module, and it has never been fixed to be supported for the normal usage. At this point it is low on the priority list, however if you feel up to patching it, I would gladly accept it. Otherwise it will have to wait until some other more important refactorings are completed. - Stevan On Wed Jan 23 11:58:24 2008, dlharbin wrote: Show quoted text
> I coded the example from the Moose::Util::TypeConstraints POD. And it > gives me the following error message rather than "This number ($_) is > not less than ten!": > > Attribute (a) does not pass the type constraint (NaturalLessThanTen) > with '11' at lib/Moose/Meta/Attribute.pm line 244 > > Moose::Meta::Attribute::initialize_instance_slot('Moose::Meta::Attribute=HASH(0x66e550)', > 'Moose::Meta::Instance=HASH(0xb87900)', 'Testy=HASH(0xb879f0)', > 'HASH(0x903460)') called at lib/Moose/Meta/Class.pm line 102 > > Moose::Meta::Class::construct_instance('Moose::Meta::Class=HASH(0xb7a220)', > 'a', 11) called at lib/x86_64-linux/Class/MOP/Class.pm line 336 > > Class::MOP::Class::new_object('Moose::Meta::Class=HASH(0xb7a220)', > 'a', > 11) called at lib/Moose/Meta/Class.pm line 81 > > Moose::Meta::Class::new_object('Moose::Meta::Class=HASH(0xb7a220)', > 'a', > 11) called at lib/Moose/Object.pm line 28 > Moose::Object::new('Testy', 'a', 11) called at ./messagebug.pl > line 36 > > > I've attached the code.
Dan, This has been fixed in the 0.37 (or greater) release, available on CPAN. The error message for types now uses a combination of a generic message (which details which attribute it is coming from, etc.) and the custom message (if set). - Stevan