summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-02 23:25:22 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-02 23:25:22 -0500
commitcbb4a91e2fcbafa6d64889717763c6a8a9033412 (patch)
treef0b5a1354bd14280f125deb6255dce0a184b5384
parent84d0f191f1e1030bcc1470bdd2cd5a43a2b997dc (diff)
downloadbread-board-declare-cbb4a91e2fcbafa6d64889717763c6a8a9033412.tar.gz
bread-board-declare-cbb4a91e2fcbafa6d64889717763c6a8a9033412.zip
set the 'class' attribute on block services if possible
-rw-r--r--lib/Bread/Board/Declare/Meta/Role/Attribute.pm3
-rw-r--r--t/12-circular-dependency.t59
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/Bread/Board/Declare/Meta/Role/Attribute.pm b/lib/Bread/Board/Declare/Meta/Role/Attribute.pm
index d4d59b9..f6584ae 100644
--- a/lib/Bread/Board/Declare/Meta/Role/Attribute.pm
+++ b/lib/Bread/Board/Declare/Meta/Role/Attribute.pm
@@ -131,6 +131,9 @@ after attach_to_class => sub {
my $service;
if ($self->has_block) {
+ if ($tc && $tc->isa('Moose::Meta::TypeConstraint::Class')) {
+ %params = (%params, class => $tc->class);
+ }
$service = Bread::Board::Declare::BlockInjection->new(
%params,
block => $self->block,
diff --git a/t/12-circular-dependency.t b/t/12-circular-dependency.t
new file mode 100644
index 0000000..28431c9
--- /dev/null
+++ b/t/12-circular-dependency.t
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ package Foo;
+ use Moose;
+
+ has bar => (
+ is => 'rw',
+ isa => 'Bar',
+ );
+}
+
+{
+ package Bar;
+ use Moose;
+
+ has foo => (
+ is => 'rw',
+ isa => 'Foo',
+ weak_ref => 1,
+ );
+}
+
+{
+ package MyApp;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ block => sub {
+ my ($s, $self) = @_;
+ Foo->new(bar => $s->param('bar'));
+ },
+ lifecycle => 'Singleton',
+ dependencies => ['bar'],
+ );
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ block => sub {
+ my ($s, $self) = @_;
+ Bar->new(foo => $s->param('foo'));
+ },
+ lifecycle => 'Singleton',
+ dependencies => ['foo'],
+ );
+}
+
+
+is exception { MyApp->new->foo->bar }, undef,
+ 'circular block-injection deps should survive';
+
+done_testing();