summaryrefslogtreecommitdiffstats
path: root/t/20-inheritance.t
blob: b1517e8677466cc1bd41091d784933f40054c126 (plain) (blame)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Moose;

{
    package Parent;
    use Moose;
    use Bread::Board::Declare;

    has foo => (
        is    => 'ro',
        isa   => 'Str',
        value => 'FOO',
    );

    has bar => (
        is    => 'ro',
        isa   => 'Str',
        block => sub {
            my $s = shift;
            return $s->param('foo') . 'BAR';
        },
        dependencies => ['foo'],
    );
}

{
    package Child;
    use Moose;
    use Bread::Board::Declare;

    extends 'Parent';

    has baz => (
        is    => 'ro',
        isa   => 'Str',
        value => 'BAZ',
    );

    has quux => (
        is    => 'ro',
        isa   => 'Str',
        block => sub {
            my $s = shift;
            return $s->param('foo')
                 . $s->param('bar')
                 . $s->param('baz')
                 . 'QUUX';
        },
        dependencies => ['foo', 'bar', 'baz'],
    );
}

with_immutable {
{
    my $parent = Parent->new;
    ok($parent->has_service('foo'), "parent has foo");
    ok($parent->has_service('bar'), "parent has bar");

    my $child = Child->new;
    ok($child->has_service('foo'), "child has foo");
    ok($child->has_service('bar'), "child has bar");
    ok($child->has_service('baz'), "child has baz");
    ok($child->has_service('quux'), "child has quux");
}

{
    my $parent = Parent->new;
    isa_ok($parent, 'Bread::Board::Container');
    is($parent->foo, 'FOO');
    is($parent->bar, 'FOOBAR');
}

{
    my $parent = Parent->new(foo => 'OOF', bar => 'RAB');
    isa_ok($parent, 'Bread::Board::Container');
    is($parent->foo, 'OOF');
    is($parent->bar, 'RAB');
}

{
    my $parent = Parent->new(foo => 'OOF');
    isa_ok($parent, 'Bread::Board::Container');
    is($parent->foo, 'OOF');
    is($parent->bar, 'OOFBAR');
}

{
    my $child = Child->new;
    is($child->foo, 'FOO');
    is($child->bar, 'FOOBAR');
    is($child->baz, 'BAZ');
    is($child->quux, 'FOOFOOBARBAZQUUX');
}

{
    my $child = Child->new(
        foo  => 'OOF',
        bar  => 'RAB',
        baz  => 'ZAB',
        quux => 'XUUQ',
    );
    is($child->foo, 'OOF');
    is($child->bar, 'RAB');
    is($child->baz, 'ZAB');
    is($child->quux, 'XUUQ');
}

{
    my $child = Child->new(
        foo  => 'OOF',
        baz  => 'ZAB',
    );
    is($child->foo, 'OOF');
    is($child->bar, 'OOFBAR');
    is($child->baz, 'ZAB');
    is($child->quux, 'OOFOOFBARZABQUUX');
}
} 'Parent', 'Child';

done_testing;