summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/MooseX/Bread/Board/Meta/Role/Attribute.pm12
-rw-r--r--t/32-defaults.t55
2 files changed, 67 insertions, 0 deletions
diff --git a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm
index 9f4c16e..c6c1335 100644
--- a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm
+++ b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm
@@ -83,6 +83,18 @@ after attach_to_class => sub {
$meta->add_service($service);
};
+after _process_options => sub {
+ my $class = shift;
+ my ($name, $opts) = @_;
+
+ return unless exists $opts->{default};
+ return unless exists $opts->{class}
+ || exists $opts->{block}
+ || exists $opts->{value};
+
+ die "default is not valid when Bread::Board service options are set";
+};
+
around get_value => sub {
my $orig = shift;
my $self = shift;
diff --git a/t/32-defaults.t b/t/32-defaults.t
new file mode 100644
index 0000000..d3f1485
--- /dev/null
+++ b/t/32-defaults.t
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ package Foo;
+ use Moose;
+ use MooseX::Bread::Board;
+
+ ::like(::exception {
+ has foo => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'OOF',
+ value => 'FOO',
+ );
+ }, qr/default is not valid when Bread::Board service options are set/,
+ "can't set a default when creating a service");
+
+ ::like(::exception {
+ has bar => (
+ is => 'ro',
+ isa => 'Str',
+ default => sub { 'OOF' },
+ value => 'FOO',
+ );
+ }, qr/default is not valid when Bread::Board service options are set/,
+ "can't set a default when creating a service");
+
+ ::like(::exception {
+ has baz => (
+ is => 'ro',
+ isa => 'Str',
+ lazy => 1,
+ default => 'OOF',
+ value => 'FOO',
+ );
+ }, qr/default is not valid when Bread::Board service options are set/,
+ "can't set a default when creating a service");
+
+ ::like(::exception {
+ has quux => (
+ is => 'ro',
+ isa => 'Str',
+ lazy => 1,
+ default => sub { 'OOF' },
+ value => 'FOO',
+ );
+ }, qr/default is not valid when Bread::Board service options are set/,
+ "can't set a default when creating a service");
+}
+
+done_testing;