Skip to content

Commit

Permalink
Support inheriting services in parameterized containers
Browse files Browse the repository at this point in the history
  • Loading branch information
rafl committed Aug 29, 2013
1 parent 02e499f commit 16b7a62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Bread/Board.pm
Expand Up @@ -161,7 +161,8 @@ sub service ($@) {
confess "Inheriting services isn't possible outside of the context of a container"
unless defined $CC;

my $prototype_service = $CC->fetch($name);
my $container = ($CC->isa('Bread::Board::Container::Parameterized') ? $CC->container : $CC);
my $prototype_service = $container->fetch($name);

confess sprintf(
"Trying to inherit from service '%s', but found a %s",
Expand Down
14 changes: 14 additions & 0 deletions t/152_sugar_service_inheritance.t
Expand Up @@ -87,6 +87,20 @@ use Bread::Board;
}
}

{
my $parameterized = container MyApp => ['Config'] => as {
service foo => (block => sub { 42 });
};

container $parameterized => as {
service '+foo' => (block => sub { 23 });
};

my $c = $parameterized->create(Config => container Config => as {});

is $c->resolve(service => 'foo'), 23;
}

like exception {
service '+foo' => 42;
}, qr/^Service inheritance doesn't make sense for literal services/;
Expand Down

0 comments on commit 16b7a62

Please sign in to comment.