File: 070_with_basic_typemap.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 (91 lines) | stat: -rw-r--r-- 2,212 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Bread::Board;

{
    package My::Foo;
    use Moose;
}

{
    # typemap directly getting a service object ...
    my $c = container 'MyTestContainer' => as {
        typemap 'My::Foo' => (service 'my_foo' => (class => 'My::Foo'));
    };

    ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
    is(
        $c->get_type_mapping_for('My::Foo'),
        $c->fetch('my_foo'),
        '... the type mapping for My::Foo is the my_foo service'
    );

    {
        my $foo = $c->resolve( service => 'my_foo' );
        isa_ok($foo, 'My::Foo');
    }
    {
        my $foo = $c->resolve( type => 'My::Foo' );
        isa_ok($foo, 'My::Foo');
    }
}

{
    # typemap mapping to a service object name ...
    my $c = container 'MyTestContainer' => as {
        service 'my_foo' => (class => 'My::Foo');
        typemap 'My::Foo' => 'my_foo';
    };

    ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
    is(
        $c->get_type_mapping_for('My::Foo'),
        $c->fetch('my_foo'),
        '... the type mapping for My::Foo is the my_foo service'
    );

    {
        my $foo = $c->resolve( service => 'my_foo' );
        isa_ok($foo, 'My::Foo');
    }
    {
        my $foo = $c->resolve( type => 'My::Foo' );
        isa_ok($foo, 'My::Foo');
    }
}

{
    # typemap mapping to a service object name
    # that is a path to a sub-container service
    my $c = container 'MyTestContainer' => as {

        container 'MyTestSubContainer' => as {
            service 'my_foo' => (class => 'My::Foo');
        };

        typemap 'My::Foo' => 'MyTestSubContainer/my_foo';
    };

    ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
    is(
        $c->get_type_mapping_for('My::Foo'),
        $c->fetch('MyTestSubContainer/my_foo'),
        '... the type mapping for My::Foo is the MyTestSubContainer/my_foo service'
    );

    {
        my $foo = $c->resolve( service => 'MyTestSubContainer/my_foo' );
        isa_ok($foo, 'My::Foo');
    }
    {
        my $foo = $c->resolve( type => 'My::Foo' );
        isa_ok($foo, 'My::Foo');
    }
}

done_testing;