File: moose-override-attribute-with-plus-syntax.t

package info (click to toggle)
libmoo-perl 1.006001-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 772 kB
  • ctags: 202
  • sloc: perl: 2,348; sh: 18; makefile: 6
file content (62 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;
use Test::Fatal;

{
    package MooParent;
    use Moo;

    has foo => (
        is => 'ro',
        default => sub { 'MooParent' },
    );
}
{
    package MooseChild;
    use Moose;
    extends 'MooParent';

    has '+foo' => (
        default => 'MooseChild',
    );
}
{
    package MooseChild2;
    use Moose;
    extends 'MooParent';

    has '+foo' => (
        default => 'MooseChild2',
    );
    __PACKAGE__->meta->make_immutable
}
{
    package MooChild;
    use Moo;
    extends 'MooParent';

    has '+foo' => (
        default => sub { 'MooChild' },
    );
}

is(
    MooseChild->new->foo,
    'MooseChild',
    'default value in Moose child'
);

is(
    MooseChild2->new->foo,
    'MooseChild2',
    'default value in Moose child'
);

is(exception {
    local $SIG{__WARN__} = sub { die $_[0] };
    ok(MooChild->meta->has_attribute('foo'), 'inflated metaclass has overridden attribute');
}, undef, 'metaclass inflation of plus override works without warnings');

done_testing;