diff options
-rw-r--r-- | lib/MooseX/Bread/Board/Meta/Role/Attribute.pm | 6 | ||||
-rw-r--r-- | t/32-defaults.t | 31 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm index eae04cc..48779fe 100644 --- a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm +++ b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm @@ -98,7 +98,8 @@ after _process_options => sub { my $class = shift; my ($name, $opts) = @_; - return unless exists $opts->{default}; + return unless exists $opts->{default} + || exists $opts->{builder}; return unless exists $opts->{class} || exists $opts->{block} || exists $opts->{value}; @@ -108,7 +109,8 @@ after _process_options => sub { || $_ eq 'Moose::Meta::Attribute::Native::Trait::Counter' } @{ $opts->{traits} }; - die "default is not valid when Bread::Board service options are set"; + my $exists = exists($opts->{default}) ? 'default' : 'builder'; + die "$exists is not valid when Bread::Board service options are set"; }; around get_value => sub { diff --git a/t/32-defaults.t b/t/32-defaults.t index d3f1485..a40a235 100644 --- a/t/32-defaults.t +++ b/t/32-defaults.t @@ -30,6 +30,16 @@ use Test::Fatal; "can't set a default when creating a service"); ::like(::exception { + has bar2 => ( + is => 'ro', + isa => 'Str', + builder => '_build_bar2', + value => 'FOO', + ); + }, qr/builder is not valid when Bread::Board service options are set/, + "can't set a builder when creating a service"); + + ::like(::exception { has baz => ( is => 'ro', isa => 'Str', @@ -50,6 +60,27 @@ use Test::Fatal; ); }, qr/default is not valid when Bread::Board service options are set/, "can't set a default when creating a service"); + + ::like(::exception { + has quux2 => ( + is => 'ro', + isa => 'Str', + lazy => 1, + builder => '_build_quux2', + value => 'FOO', + ); + }, qr/builder is not valid when Bread::Board service options are set/, + "can't set a builder when creating a service"); + + ::like(::exception { + has quux3 => ( + is => 'ro', + isa => 'Str', + lazy_build => 1, + value => 'FOO', + ); + }, qr/builder is not valid when Bread::Board service options are set/, + "can't set lazy_build when creating a service"); } done_testing; |