Subject: | Type constraints check behaviour - changed thrown message? |
Hi,
after installing Moose 0.25 my type constraint checks suddenly turned
into some rant against overload.pm. Am I using all this badly?
Here follows an example (also attached):
package ClassA;
use strict;
use warnings;
use Moose;
use Moose::Util::TypeConstraints;
has attribute => (
is => 'rw',
required => 1,
isa => subtype 'Int' => where {
my $value = shift;
return $value > 0 && $value <= 255;
},
);
package main;
use Test::More 'no_plan';
use Test::Exception;
lives_ok { ClassA->new(attribute => 3) } 'constructor with good value';
throws_ok { ClassA->new(attribute => -3) }
qr/Attribute .* does not pass the type constraint/,
'constructor with bad value';
__END__
poletti@PolettiX:~/sviluppo/perl/moose$ perl test03.pl
ok 1 - constructor with good value
not ok 2 - constructor with bad value
# Failed test 'constructor with bad value'
# at test03.pl line 22.
# expecting: Regexp ((?-xism:Attribute .* does not pass the type
constraint))
# found: Can't call method "can" without a package or object reference
at /opt/perl/lib/5.8.8/overload.pm line 54.
1..2
# Looks like you failed 1 test of 2.
Subject: | test03.pl |
package ClassA;
use strict;
use warnings;
use Moose;
use Moose::Util::TypeConstraints;
has attribute => (
is => 'rw',
required => 1,
isa => subtype 'Int' => where {
my $value = shift;
return $value > 0 && $value <= 255;
},
);
package main;
use Test::More 'no_plan';
use Test::Exception;
lives_ok { ClassA->new(attribute => 3) } 'constructor with good value';
throws_ok { ClassA->new(attribute => -3) }
qr/Attribute .* does not pass the type constraint/,
'constructor with bad value';
__END__