File: 032_singleton_cycle.t

package info (click to toggle)
libbread-board-perl 0.29-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 620 kB
  • sloc: perl: 5,280; makefile: 13
file content (54 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
use strict;
use Test::More;

use Bread::Board;

my $seen;

{
    package Bot;
    use Moose;

    has plugin => (
        isa      => 'Plugin',
        is       => 'ro',
        required => 1
    );
}

{
    package Plugin;
    use Moose;

    has bot => (
        isa      => 'Bot',
        is       => 'ro',
        weak_ref => 1,
        required => 1
    );
}

my $c = container 'Config' => as {
    service plugin => (
        class        => 'Plugin',
        lifecycle    => 'Singleton',
        dependencies => ['bot'],
    );

    service bot => (
        class        => 'Bot',
        block        => sub {
            my ($s) = @_;
            $seen++;
            Bot->new(plugin => $s->param('plugin'));
        },
        lifecycle    => 'Singleton',
        dependencies => ['plugin'],
    );
};

ok($c->resolve(service => 'bot'));
is($seen, 1, 'seen only once');

done_testing;