summaryrefslogtreecommitdiffstats
path: root/t/circular-dependency.t
blob: 28431c907ca09eecc4cff067bf5a87a34b07743c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();