Subject: | Constraint error message ignored |
Date: | Mon, 19 Sep 2011 16:18:12 +0200 |
To: | bug-MooseX-Types-Structured [...] rt.cpan.org |
From: | Tobias Nissen <tn [...] movb.de> |
Hi,
MooseX-Types-Structured doesn't seem to care for constraint error
messages provided in a subtype declaration:
{
package Foo;
use Moose;
use Moose::Util::TypeConstraints;
use MooseX::Types::Moose qw(Str);
use MooseX::Types::Structured qw(Dict);
use MooseX::Types -declare => [qw(IPv4Address)];
subtype IPv4Address,
as Str,
where { /^\s*(\d{1,3}\.){3}\d{1,3}\s*$/ },
message { "Not an IPv4 address: '$_'" };
has 'foo' => (
is => 'rw',
isa => Dict[ address => IPv4Address ],
);
sub BUILD {
my $self = shift;
$self->foo({address => '0.0.BAD.0'});
}
1;
}
my $foo = Foo->new();
This results in
Attribute (foo) does not pass the type constraint because: Validation failed for 'MooseX::Types::Structured::Dict[address,Foo::IPv4Address]' with value { address: "0.0.BAD.0" } at accessor Foo::foo (defined at ex.pl line 16) line 4
Foo::foo('Foo=HASH(0x2a0e450)', 'HASH(0x2ce1290)') called at ex.pl line 24
Foo::BUILD('Foo=HASH(0x2a0e450)', 'HASH(0x1dbdd80)') called at /usr/lib/perl5/Class/MOP/Method.pm line 125
[and so on...]
I would have expected to get the provided message "Not an IPv4 address..."
This is perl 5, version 12, subversion 4 (v5.12.4) built for
x86_64-linux-gnu-thread-multi on a recently updated Debian Wheezy.
Cheers,
Tobias
Message body not shown because it is not plain text.