diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-02-21 12:52:56 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-02-21 12:52:56 -0600 |
commit | eb3f39183f1e1039a4d9a73cb1c2b19ea514c436 (patch) | |
tree | 24d5a2c1c27b5d35661fa078040b4ad9f87aff5d | |
parent | 7254fb6a608b1f54d52572a859356236d0a0ba2e (diff) | |
download | bread-board-declare-eb3f39183f1e1039a4d9a73cb1c2b19ea514c436.tar.gz bread-board-declare-eb3f39183f1e1039a4d9a73cb1c2b19ea514c436.zip |
also disallow builder
-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; |