summaryrefslogtreecommitdiffstats
path: root/t/hashref-constructor.t
blob: 00deff072b6fe08289b4f1bf4983cc70c5c89045 (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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;

{
    package Foo;

    sub new {
        my $class = shift;
        bless { ref($_[0]) ? %{$_[0]} : @_ }, $class;
    }

    sub foo {
        my $self = shift;
        $self->{foo};
    }
}

{
    package Bar;
    use Moose;
    use MooseX::NonMoose;

    extends 'Foo';

    has _bar => (
        init_arg => 'bar',
        reader   => 'bar',
    );

    __PACKAGE__->meta->make_immutable;
}

{
    package Baz;
    use Moose;

    extends 'Bar';

    has _baz => (
        init_arg => 'baz',
        reader   => 'baz',
    );
}

{
    my $baz;
    is(exception { $baz = Baz->new( foo => 1, bar => 2, baz => 3 ) }, undef,
       "constructor lives");
    is($baz->foo, 1, "foo set");
    is($baz->bar, 2, "bar set");
    is($baz->baz, 3, "baz set");

}

{
    my $baz;
    is(exception { $baz = Baz->new({foo => 1, bar => 2, baz => 3}) }, undef,
       "constructor lives (hashref)");
    is($baz->foo, 1, "foo set (hashref)");
    is($baz->bar, 2, "bar set (hashref)");
    is($baz->baz, 3, "baz set (hashref)");
}

done_testing;