diff options
-rw-r--r-- | lib/MooseX/Bread/Board/Meta/Role/Attribute.pm | 34 | ||||
-rw-r--r-- | t/01-basic.t | 14 | ||||
-rw-r--r-- | t/02-deps.t | 1 | ||||
-rw-r--r-- | t/03-lifecycle.t | 1 | ||||
-rw-r--r-- | t/33-constructor-name.t | 1 |
5 files changed, 28 insertions, 23 deletions
diff --git a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm index 48779fe..f45cd6d 100644 --- a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm +++ b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm @@ -9,10 +9,10 @@ use MooseX::Bread::Board::BlockInjection; use MooseX::Bread::Board::ConstructorInjection; use MooseX::Bread::Board::Literal; -has class => ( - is => 'ro', - isa => 'Str', - predicate => 'has_class', +has service => ( + is => 'ro', + isa => 'Bool', + default => 1, ); has block => ( @@ -51,6 +51,8 @@ has constructor_name => ( after attach_to_class => sub { my $self = shift; + return unless $self->service; + my $meta = $self->associated_class; my $attr_reader = $self->get_read_method; @@ -69,29 +71,29 @@ after attach_to_class => sub { ); my $service; - if ($self->has_class) { - $service = MooseX::Bread::Board::ConstructorInjection->new( - %params, - class => $self->class, - ) - } - elsif ($self->has_block) { + if ($self->has_block) { $service = MooseX::Bread::Board::BlockInjection->new( %params, block => $self->block, - ) + ); } elsif ($self->has_literal_value) { $service = MooseX::Bread::Board::Literal->new( %params, value => $self->literal_value, - ) + ); } - else { - return; + elsif ($self->has_type_constraint) { + my $tc = $self->type_constraint; + if ($tc->isa('Moose::Meta::TypeConstraint::Class')) { + $service = MooseX::Bread::Board::ConstructorInjection->new( + %params, + class => $tc->class, + ); + } } - $meta->add_service($service); + $meta->add_service($service) if $service; }; after _process_options => sub { diff --git a/t/01-basic.t b/t/01-basic.t index 38590df..5aff0eb 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -28,9 +28,14 @@ my $i; ); has baz => ( - is => 'ro', - isa => 'Baz', - class => 'Baz', + is => 'ro', + isa => 'Baz', + ); + + has baz2 => ( + is => 'ro', + isa => 'Baz', + service => 0, ); has quux => ( @@ -47,7 +52,8 @@ $i = 0; isa_ok($foo, 'Bread::Board::Container'); ok($foo->has_service($_), "has service $_") for qw(bar baz quux); - ok(!$foo->has_service('foo'), "doesn't have service foo"); + ok(!$foo->has_service($_), "doesn't have service $_") + for qw(foo baz2); isa_ok($foo->get_service('bar'), 'MooseX::Bread::Board::Literal'); isa_ok($foo->get_service('baz'), 'MooseX::Bread::Board::ConstructorInjection'); isa_ok($foo->get_service('quux'), 'MooseX::Bread::Board::BlockInjection'); diff --git a/t/02-deps.t b/t/02-deps.t index 4b1143a..578db20 100644 --- a/t/02-deps.t +++ b/t/02-deps.t @@ -30,7 +30,6 @@ my $i; has baz => ( is => 'ro', isa => 'Baz', - class => 'Baz', dependencies => ['bar'], ); } diff --git a/t/03-lifecycle.t b/t/03-lifecycle.t index 8308e59..8b39175 100644 --- a/t/03-lifecycle.t +++ b/t/03-lifecycle.t @@ -30,7 +30,6 @@ my $i; has baz => ( is => 'ro', isa => 'Baz', - class => 'Baz', dependencies => ['bar'], lifecycle => 'Singleton', ); diff --git a/t/33-constructor-name.t b/t/33-constructor-name.t index ef46338..abe367d 100644 --- a/t/33-constructor-name.t +++ b/t/33-constructor-name.t @@ -18,7 +18,6 @@ use Test::Moose; has bar => ( is => 'ro', isa => 'Bar', - class => 'Bar', constructor_name => 'create', ); } |