From 30579545ce1517fb1b42a84dbb940e8d75aaa081 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 16 Apr 2011 16:42:28 -0500 Subject: more tests --- t/50-infer.t | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 't/50-infer.t') diff --git a/t/50-infer.t b/t/50-infer.t index bae915d..75879fa 100644 --- a/t/50-infer.t +++ b/t/50-infer.t @@ -124,6 +124,13 @@ use Test::Fatal; isa_ok($c->baz, 'Baz2'); isa_ok($c->baz->foo, 'Foo'); isa_ok($c->baz->bar, 'Bar'); + + is( + $c->fetch('baz')->get_dependency('foo')->service, + $c->fetch('foo'), + "inferred the right dependency" + ); + is($c->baz->foo->data, 'THING', "inference finds services in the container"); is($c->baz->thing, 'THING', "partial dependency specification works"); @@ -185,4 +192,58 @@ use Test::Fatal; is($c->quux2->foo->data, 'DATA', "but can be explicitly specified"); } +{ + package State; + use Moose; + + has counter => ( + traits => ['Counter'], + is => 'rw', + isa => 'Int', + handles => { inc => 'inc' }, + default => 0, + ); +} + +{ + package Controller; + use Moose; + + has counter => ( + is => 'ro', + isa => 'State', + required => 1, + handles => { inc => 'inc', counter_val => 'counter' }, + ); +} + +{ + package App; + use Moose; + use Bread::Board::Declare; + + has counter => ( + is => 'ro', + isa => 'State', + lifecycle => 'Singleton', + ); + + has controller => ( + is => 'ro', + isa => 'Controller', + ); +} + +{ + my $c = App->new; + is( + $c->fetch('controller')->get_dependency('counter')->service, + $c->fetch('counter'), + "inferred the right dependency" + ); + $c->controller->inc; + $c->controller->inc; + is($c->controller->counter_val, 2, "state persisted as a singleton"); +} + done_testing; -- cgit v1.2.3