File: anon-builder.t

package info (click to toggle)
libmoosex-attributeshortcuts-perl 0.024-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 312 kB
  • ctags: 9
  • sloc: perl: 326; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More;
use Test::Moose::More 0.011;

my $i = 0;

{
    package TestClass;

    use Moose;
    use namespace::autoclean;
    use MooseX::AttributeShortcuts;

    has foo => (is => 'ro', builder => sub { $i++ });
}
{
    package TestRole;

    use Moose::Role;
    use namespace::autoclean;
    use MooseX::AttributeShortcuts;

    has bar => (is => 'ro', builder => sub { $i++ });
}

validate_class TestClass => (
    attributes => [ qw{ foo            } ],
    methods    => [ qw{ foo _build_foo } ],
);

is $i, 0, 'counter correct (sanity check)';
my $tc = TestClass->new;
isa_ok $tc, 'TestClass';
is $i, 1, 'counter correct';

TODO: {
    local $TODO = 'not currently setting up anon builder as method in roles yet';

    # using builders in roles and being able to exclude/alias them as
    # necessary when consuming them is a major win.  Because of that -- and
    # because that's what we'd expect to be able to do with a builder when
    # created in the usual fashion (aka not anon sub via us) we want to create
    # the builder as a method in the role when we define the attribute to a
    # role.
    #
    # We don't do that quite yet :)

    validate_role TestRole => (
        attributes => [ qw{ bar } ],
        methods    => [ qw{ _build_bar } ],
    );
}

done_testing;