From: Dave Rolsky Date: Fri, 15 Oct 2010 15:54:24 +0000 (-0500) Subject: Check for lazy_build when assign default default for native trait. X-Git-Tag: 1.16~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b558f8a652d9137478278100dd94c3222a566d49;p=gitmo%2FMoose.git Check for lazy_build when assign default default for native trait. Add tests for this. --- diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index 4406d02..d92a469 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -32,7 +32,7 @@ before '_process_options' => sub { if ( !( $options->{required} - || any { exists $options->{$_} } qw( default builder ) + || any { exists $options->{$_} } qw( default builder lazy_build ) ) && $self->can('_default_default') ) { diff --git a/t/010_basics/030_deprecations.t b/t/010_basics/030_deprecations.t index 5db3574..3a40f68 100644 --- a/t/010_basics/030_deprecations.t +++ b/t/010_basics/030_deprecations.t @@ -1,6 +1,7 @@ use strict; use warnings; +use Test::Exception; use Test::More; use Test::Requires { @@ -67,14 +68,15 @@ use Test::Requires { } q{}, 'Providing a reader for a String trait avoids default is warning'; - ::stderr_is{ has bar => ( - traits => ['String'], - is => 'ro', - isa => 'Str', - builder => '_build_foo', - ); - } q{}, + ::lives_and{ ::stderr_is{ has bar => ( + traits => ['String'], + is => 'ro', + isa => 'Str', + builder => '_build_foo', + ); + } q{}, 'Providing a builder for a String trait avoids default default warning'; + } 'Providing a builder for a String trait does not die'; sub _build_foo { } } @@ -118,6 +120,18 @@ use Test::Requires { ); } q{}, 'Providing an accessor for a String trait avoids default is warning'; + + ::lives_and{ ::stderr_is{ has bar => ( + traits => ['String'], + is => 'ro', + isa => 'Str', + lazy_build => 1, + ); + } q{}, + 'Making a String trait lazy_build avoids default default warning'; + } 'Providing lazy_build for a String trait lives'; + + sub _build_bar { } } done_testing;