1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More; 7use Test::Moose; 8 9use Bread::Board; 10 11{ 12 package My::Bar; 13 use Moose; 14 15 package My::Foo; 16 use Moose; 17 18 has 'bar' => ( 19 is => 'ro', 20 isa => 'My::Bar', 21 required => 1, 22 ); 23} 24 25{ 26 my $c = container 'MyTestContainer' => as { 27 typemap 'My::Bar' => infer; 28 typemap 'My::Foo' => infer; 29 }; 30 31 ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo'); 32 does_ok( 33 $c->get_type_mapping_for('My::Foo'), 34 'Bread::Board::Service' 35 ); 36 ok($c->has_type_mapping_for('My::Bar'), '... we do not have a type mapping for My::Bar'); 37 does_ok( 38 $c->get_type_mapping_for('My::Bar'), 39 'Bread::Board::Service' 40 ); 41 is( 42 $c->get_type_mapping_for('My::Foo')->get_dependency('bar')->service, 43 $c->get_type_mapping_for('My::Bar'), 44 '... the My::Bar dependency for My::Foo is the same as in the type map' 45 ); 46 47 { 48 my $foo = $c->resolve( type => 'My::Foo' ); 49 isa_ok($foo, 'My::Foo'); 50 isa_ok($foo->bar, 'My::Bar'); 51 } 52} 53 54# don't give infer enough information 55# and make it figure it out for itself 56# including inferring the embedded object 57{ 58 my $c = container 'MyTestContainer' => as { 59 typemap 'My::Foo' => infer; 60 }; 61 62 ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo'); 63 does_ok( 64 $c->get_type_mapping_for('My::Foo'), 65 'Bread::Board::Service' 66 ); 67 ok(!$c->has_type_mapping_for('My::Bar'), '... we do not have a type mapping for My::Bar'); 68 69 { 70 my $foo = $c->resolve( type => 'My::Foo' ); 71 isa_ok($foo, 'My::Foo'); 72 isa_ok($foo->bar, 'My::Bar'); 73 } 74} 75 76done_testing; 77