summaryrefslogtreecommitdiffstats
path: root/t/31-auto-deref.t
blob: c86fffdc35b314faa11bbf5e9dd08a49c65ba250 (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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

{
    package Foo;
    use Moose;
    use MooseX::Bread::Board;

    has foo => (
        is         => 'ro',
        isa        => 'ArrayRef',
        auto_deref => 1,
        block      => sub { ['foo', 'bar'] },
    );

    has bar => (
        is         => 'ro',
        isa        => 'HashRef',
        auto_deref => 1,
        block      => sub { {'foo' => 'bar'} },
    );
}

{
    my $foo = Foo->new;

    is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array");
    is_deeply([$foo->foo], ['foo', 'bar'], "list array");
    is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash");
    is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash");
}

{
    my $foo = Foo->new(foo => ['foo', 'bar'], bar => {'foo' => 'bar'});

    is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array");
    is_deeply([$foo->foo], ['foo', 'bar'], "list array");
    is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash");
    is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash");
}

done_testing;