From: Stevan Little Date: Tue, 31 Jul 2007 21:19:06 +0000 (+0000) Subject: sorry_Debolaz X-Git-Tag: 0_25~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7a5ebc4095c54b0420df515494e32acafbd5fcf0;p=gitmo%2FMoose.git sorry_Debolaz --- diff --git a/Changes b/Changes index 717ae97..7c6622c 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,9 @@ Revision history for Perl extension Moose - 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 diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 7bd0bbe..c6e4abf 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -226,7 +226,7 @@ sub initialize_instance_slot { $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) { @@ -237,7 +237,7 @@ sub initialize_instance_slot { $self->name . ") does not pass the type constraint (" . $type_constraint->name . - ") with '$val'"; + ") with '" . (defined $val ? $val : 'undef') . "'"; } } diff --git a/t/071_misc_attribute_tests.t b/t/071_misc_attribute_tests.t index bdab707..808e646 100644 --- a/t/071_misc_attribute_tests.t +++ b/t/071_misc_attribute_tests.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 9; use Test::Exception; BEGIN { @@ -84,3 +84,23 @@ 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'; + +} +