1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Moose;
8
9use Bread::Board;
10
11{
12    package Serializer;
13    use Moose;
14    has 'format' => ( is => 'ro', isa => 'Str' );
15
16    package Application;
17    use Moose;
18    has 'json' => ( is => 'ro', isa => 'Serializer' );
19}
20
21{
22    my $c = container 'Test' => as {
23
24        service 'Serializer' => (
25            class      => 'Serializer',
26            parameters => {
27                'format' => { isa => 'Str' }
28            }
29        );
30
31        service 'App' => (
32            class        => 'Application',
33            dependencies => {
34                json => Bread::Board::Dependency->new(
35                    service_path   => 'Serializer',
36                    service_params => { 'format' => 'JSON' }
37                )
38            }
39        );
40
41    };
42
43    my $app = $c->resolve( service => 'App' );
44    isa_ok($app, 'Application');
45    isa_ok($app->json, 'Serializer');
46    is($app->json->format, 'JSON', '... got the right format');
47}
48
49{
50    my $c = container 'Test' => as {
51
52        service 'Serializer' => (
53            class      => 'Serializer',
54            parameters => {
55                'format' => { isa => 'Str' }
56            }
57        );
58
59        service 'App' => (
60            class        => 'Application',
61            dependencies => {
62                json => { 'Serializer' => { 'format' => 'JSON' } }
63            }
64        );
65
66    };
67
68    my $app = $c->resolve( service => 'App' );
69    isa_ok($app, 'Application');
70    isa_ok($app->json, 'Serializer');
71    is($app->json->format, 'JSON', '... got the right format');
72}
73
74
75done_testing;
76