File: inline-builder-conflict-toclass.t

package info (click to toggle)
libmoosex-attributeshortcuts-perl 0.037-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 691; makefile: 2
file content (74 lines) | stat: -rw-r----- 1,909 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use strict;
use warnings;

use constant ATTRIBUTE_TRAIT      => 'MooseX::AttributeShortcuts::Trait::Attribute';
use constant ROLE_ATTRIBUTE_TRAIT => 'MooseX::AttributeShortcuts::Trait::Role::Attribute';

# Here we test how anonymous builders in roles work.  Until recently, the
# corresponding builder method was only created when a role was applied to a
# class, so the usual logic of excluding, etc, failed.
#
# Was this a problem in practice?  I never ran into it, and I haven't seen any
# bug reports about it, so... probably not?

use Moose::Util 'find_meta';
use Test::More;
use Test::Moose::More 0.047;

{
    package TestRole::A;
    use Moose::Role;
    use MooseX::AttributeShortcuts;

    has bar => (is => 'ro', builder => sub { 2 });
}
{
    package TestRole::B;
    use Moose::Role;
    sub _build_bar { 4 }
}
{
    package TestClass;
    use Moose;
    with 'TestRole::A', 'TestRole::B';
    sub _build_bar { 16 }
}

validate_role 'TestRole::A' => (
    -subtest       => 'TestRole::A',
    methods        => [ qw{ _build_bar } ],
    role_metaroles => {
        attribute         => [ ROLE_ATTRIBUTE_TRAIT ],
        applied_attribute => [ ATTRIBUTE_TRAIT      ],
    },
    attributes => [
        bar => {
            -does => [ ROLE_ATTRIBUTE_TRAIT ],
        },
    ],
);

validate_role 'TestRole::B' => (
    -subtest => 'TestRole::B',
    methods  => [ qw{ _build_bar } ],
);

validate_class TestClass => (
    -subtest   => 'TestClass',
    does       => ['TestRole::A', 'TestRole::B'],
    methods    => ['_build_bar'],
    attributes => [
        bar => {
            -does   => [ATTRIBUTE_TRAIT],
            builder => '_build_bar',
        },
    ],
);

is TestClass::_build_bar() => 16, '...::_build_bar() is correct (16)';
my $tc = TestClass->new;
is $tc->bar() => 16, 'builder method as expected (16)';

method_from_pkg_ok TestClass => '_build_bar', 'TestClass';

done_testing;