1#!/usr/bin/env perl 2use strict; 3use Test::More; 4 5use Bread::Board; 6 7my $seen; 8 9{ 10 package Bot; 11 use Moose; 12 13 has plugin => ( 14 isa => 'Plugin', 15 is => 'ro', 16 required => 1 17 ); 18} 19 20{ 21 package Plugin; 22 use Moose; 23 24 has bot => ( 25 isa => 'Bot', 26 is => 'ro', 27 weak_ref => 1, 28 required => 1 29 ); 30} 31 32my $c = container 'Config' => as { 33 service plugin => ( 34 class => 'Plugin', 35 lifecycle => 'Singleton', 36 dependencies => ['bot'], 37 ); 38 39 service bot => ( 40 class => 'Bot', 41 block => sub { 42 my ($s) = @_; 43 $seen++; 44 Bot->new(plugin => $s->param('plugin')); 45 }, 46 lifecycle => 'Singleton', 47 dependencies => ['plugin'], 48 ); 49}; 50 51ok($c->resolve(service => 'bot'), 'can resolve bot service'); 52is($seen, 1, '... and it is seen only once'); 53 54done_testing; 55