- required attributes now will no longer accept undef
from the constructor, even if there is a default and lazy
- added tests for this
+ - default subroutines must return a value which passes the
+ type constraint
+ - added tests for this
* Moose::Meta::Role
- massive refactoring of this code
$val = $self->default($instance);
}
- if (defined $val) {
+ if (defined $val || $self->has_default) {
if ($self->has_type_constraint) {
my $type_constraint = $self->type_constraint;
if ($self->should_coerce && $type_constraint->has_coercion) {
$self->name .
") does not pass the type constraint (" .
$type_constraint->name .
- ") with '$val'";
+ ") with '" . (defined $val ? $val : 'undef') . "'";
}
}
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More tests => 9;
use Test::Exception;
BEGIN {
can_ok($test, qw(foo bar baz));
}
+
+{
+ {
+ package Test::UndefDefault::Attributes;
+ use Moose;
+
+ has 'foo' => (
+ is => 'ro',
+ isa => 'Str',
+ default => sub { return }
+ );
+
+ }
+
+ dies_ok {
+ Test::UndefDefault::Attributes->new;
+ } '... default must return a value which passes the type constraint';
+
+}
+