diff options
-rw-r--r-- | lib/MooseX/Bread/Board/Role/Object.pm | 14 | ||||
-rw-r--r-- | t/04-block.t | 39 |
2 files changed, 52 insertions, 1 deletions
diff --git a/lib/MooseX/Bread/Board/Role/Object.pm b/lib/MooseX/Bread/Board/Role/Object.pm index 552bc75..e25fdf5 100644 --- a/lib/MooseX/Bread/Board/Role/Object.pm +++ b/lib/MooseX/Bread/Board/Role/Object.pm @@ -17,7 +17,19 @@ after BUILD => sub { return unless $meta->has_services; for my $service ($meta->services) { - $self->add_service($service->clone); + if ($service->isa('MooseX::Bread::Board::BlockInjection')) { + my $block = $service->block; + $self->add_service( + $service->clone( + block => sub { + $block->(@_, $self) + }, + ) + ); + } + else { + $self->add_service($service->clone); + } } }; diff --git a/t/04-block.t b/t/04-block.t new file mode 100644 index 0000000..a06a950 --- /dev/null +++ b/t/04-block.t @@ -0,0 +1,39 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Foo; + use Moose; + use MooseX::Bread::Board; + + has foo => ( + is => 'ro', + isa => 'Str', + default => 'FOO', + ); + + has bar => ( + is => 'ro', + isa => 'Str', + value => 'BAR', + ); + + has baz => ( + is => 'ro', + isa => 'Baz', + block => sub { + my ($s, $self) = @_; + return $s->param('bar') . $self->foo; + }, + dependencies => ['bar'], + ); +} + +{ + my $foo = Foo->new; + is($foo->baz, 'BARFOO', "self is passed properly"); +} + +done_testing; |