diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-04-02 23:25:22 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-04-02 23:25:22 -0500 |
commit | cbb4a91e2fcbafa6d64889717763c6a8a9033412 (patch) | |
tree | f0b5a1354bd14280f125deb6255dce0a184b5384 /t | |
parent | 84d0f191f1e1030bcc1470bdd2cd5a43a2b997dc (diff) | |
download | bread-board-declare-cbb4a91e2fcbafa6d64889717763c6a8a9033412.tar.gz bread-board-declare-cbb4a91e2fcbafa6d64889717763c6a8a9033412.zip |
set the 'class' attribute on block services if possible
Diffstat (limited to 't')
-rw-r--r-- | t/12-circular-dependency.t | 59 |
1 files changed, 59 insertions, 0 deletions
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(); |