1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More; 7use Test::Moose; 8 9use Bread::Board::Container; 10use Bread::Board::ConstructorInjection; 11use Bread::Board::Literal; 12 13my $c = Bread::Board::Container->new(name => '/'); 14isa_ok($c, 'Bread::Board::Container'); 15 16$c->add_sub_container( 17 Bread::Board::Container->new( 18 name => 'Application', 19 sub_containers => [ 20 Bread::Board::Container->new( 21 name => 'Model', 22 services => [ 23 Bread::Board::Literal->new(name => 'dsn', value => ''), 24 Bread::Board::ConstructorInjection->new( 25 name => 'schema', 26 class => 'My::App::Schema', 27 dependencies => { 28 dsn => Bread::Board::Dependency->new(service_path => '../dsn'), 29 user => Bread::Board::Literal->new(name => 'user', value => ''), 30 pass => Bread::Board::Literal->new(name => 'pass', value => ''), 31 }, 32 ) 33 ] 34 ), 35 Bread::Board::Container->new( 36 name => 'View', 37 services => [ 38 Bread::Board::ConstructorInjection->new( 39 name => 'TT', 40 class => 'My::App::View::TT', 41 dependencies => { 42 tt_include_path => Bread::Board::Literal->new(name => 'include_path', value => []), 43 }, 44 ) 45 ] 46 ), 47 Bread::Board::Container->new(name => 'Controller'), 48 ] 49 ) 50); 51 52my $app = $c->get_sub_container('Application'); 53isa_ok($app, 'Bread::Board::Container'); 54 55is($app->name, 'Application', '... got the right container'); 56 57{ 58 my $controller = $app->get_sub_container('Controller'); 59 isa_ok($controller, 'Bread::Board::Container'); 60 61 is($controller->name, 'Controller', '... got the right container'); 62 is($controller->parent, $app, '... app is the parent of the controller'); 63 64 ok(!$controller->has_services, '... the controller has no services'); 65} 66{ 67 my $view = $app->get_sub_container('View'); 68 isa_ok($view, 'Bread::Board::Container'); 69 70 is($view->name, 'View', '... got the right container'); 71 is($view->parent, $app, '... app is the parent of the view'); 72 73 ok($view->has_services, '... the veiw has services'); 74 75 my $service = $view->get_service('TT'); 76 does_ok($service, 'Bread::Board::Service'); 77 78 is($service->parent, $view, '... the parent of the service is the view'); 79} 80{ 81 my $model = $app->get_sub_container('Model'); 82 isa_ok($model, 'Bread::Board::Container'); 83 84 is($model->name, 'Model', '... got the right container'); 85 is($model->parent, $app, '... app is the parent of the model'); 86 87 ok($model->has_services, '... the model has services'); 88 89 my $service = $model->get_service('schema'); 90 does_ok($service, 'Bread::Board::Service'); 91 92 is($service->parent, $model, '... the parent of the service is the model'); 93} 94 95done_testing; 96