summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-02-21 13:29:19 -0600
committerJesse Luehrs <doy@tozt.net>2011-02-21 13:29:19 -0600
commitccb6cf33d33e58eef1937253be5c470f9449354a (patch)
tree0b1801b3e187af3f695abbdd71e41fa0946f98be /lib
parent5067979bd1601d557362d79aa03a51665a761a39 (diff)
downloadbread-board-declare-ccb6cf33d33e58eef1937253be5c470f9449354a.tar.gz
bread-board-declare-ccb6cf33d33e58eef1937253be5c470f9449354a.zip
make constructor injections just use the tc
also provide the 'service' key to override creating a service
Diffstat (limited to 'lib')
-rw-r--r--lib/MooseX/Bread/Board/Meta/Role/Attribute.pm34
1 files changed, 18 insertions, 16 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 {