-
Notifications
You must be signed in to change notification settings - Fork 24
/
071_typemap_with_basic_infer.t
103 lines (84 loc) · 2.28 KB
/
071_typemap_with_basic_infer.t
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
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Moose;
use Bread::Board;
{
package Foo::Role;
use Moose::Role;
package My::Foo;
use Moose;
with 'Foo::Role';
}
# give infer() enough information to create
# the service all by itself ...
{
my $c = container 'MyTestContainer' => as {
typemap 'Foo::Role' => infer( class => 'My::Foo' );
};
ok($c->has_type_mapping_for('Foo::Role'), '... have a type mapping for Foo::Role');
does_ok(
$c->get_type_mapping_for('Foo::Role'),
'Bread::Board::Service'
);
{
my $foo = $c->resolve( type => 'Foo::Role' );
isa_ok($foo, 'My::Foo');
}
}
# don't give infer enough information
# and make it figure it out for itself
{
my $c = container 'MyTestContainer' => as {
typemap 'My::Foo' => infer;
};
ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
does_ok(
$c->get_type_mapping_for('My::Foo'),
'Bread::Board::Service'
);
{
my $foo = $c->resolve( type => 'My::Foo' );
isa_ok($foo, 'My::Foo');
}
}
{
my $c = container 'MyTestContainer' => as {
typemap 'My::Foo' => infer(
dependencies => { thing => service('thing' => 'THING') }
);
};
ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
my $s = $c->get_type_mapping_for('My::Foo');
does_ok($s, 'Bread::Board::Service');
ok($s->has_dependency('thing'), "service_args were passed along");
{
my $foo = $c->resolve( type => 'My::Foo' );
isa_ok($foo, 'My::Foo');
}
}
{
package My::ConstructorInjection;
use Moose;
extends 'Bread::Board::ConstructorInjection';
}
{
my $c = container 'MyTestContainer' => as {
typemap 'My::Foo' => infer(
My::ConstructorInjection->new(
name => 'foo',
class => 'My::Foo',
)
);
};
ok($c->has_type_mapping_for('My::Foo'), '... have a type mapping for My::Foo');
my $s = $c->get_type_mapping_for('My::Foo');
does_ok($s, 'Bread::Board::Service');
isa_ok($s, 'My::ConstructorInjection');
{
my $foo = $c->resolve( type => 'My::Foo' );
isa_ok($foo, 'My::Foo');
}
}
done_testing;