File: 045_parameters_in_dependency.t

package info (click to toggle)
libbread-board-perl 0.29-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 620 kB
  • sloc: perl: 5,280; makefile: 13
file content (75 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Moose;

use Bread::Board;

{
    package Serializer;
    use Moose;
    has 'format' => ( is => 'ro', isa => 'Str' );

    package Application;
    use Moose;
    has 'json' => ( is => 'ro', isa => 'Serializer' );
}

{
    my $c = container 'Test' => as {

        service 'Serializer' => (
            class      => 'Serializer',
            parameters => {
                'format' => { isa => 'Str' }
            }
        );

        service 'App' => (
            class        => 'Application',
            dependencies => {
                json => Bread::Board::Dependency->new(
                    service_path   => 'Serializer',
                    service_params => { 'format' => 'JSON' }
                )
            }
        );

    };

    my $app = $c->resolve( service => 'App' );
    isa_ok($app, 'Application');
    isa_ok($app->json, 'Serializer');
    is($app->json->format, 'JSON', '... got the right format');
}

{
    my $c = container 'Test' => as {

        service 'Serializer' => (
            class      => 'Serializer',
            parameters => {
                'format' => { isa => 'Str' }
            }
        );

        service 'App' => (
            class        => 'Application',
            dependencies => {
                json => { 'Serializer' => { 'format' => 'JSON' } }
            }
        );

    };

    my $app = $c->resolve( service => 'App' );
    isa_ok($app, 'Application');
    isa_ok($app->json, 'Serializer');
    is($app->json->format, 'JSON', '... got the right format');
}


done_testing;