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;
|