File: parameterized.t

package info (click to toggle)
libmoosex-traits-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 316 kB
  • ctags: 11
  • sloc: perl: 320; makefile: 7
file content (110 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Test::Requires { 'MooseX::Role::Parameterized' => '0.13' };

plan tests => 11;

{
    package Role;
    use Moose::Role;

    has 'gorge' => (
        is       => 'ro',
        required => 1,
    );
}

{
    package PRole;
    use MooseX::Role::Parameterized;

    parameter 'foo' => (
        is       => 'ro',
        required => 1,
    );

    role {
        my $p = shift;

        has $p->foo => (
            is       => 'ro',
            required => 1,
        );
    }
}

{
    package Class;
    use Moose;

    with 'MooseX::Traits';
}

is
    exception { Class->new; },
    undef,
    'making class is OK';

is
    exception { Class->new_with_traits; },
    undef,
    'making class with no traits is OK';

my $a;

is
    exception {
        $a = Class->new_with_traits(
            traits => ['PRole' => { foo => 'OHHAI' }],
            OHHAI  => 'I FIXED THAT FOR YOU',
        );
    },
    undef,
    'prole is applied OK';

isa_ok $a, 'Class';
is $a->OHHAI, 'I FIXED THAT FOR YOU', 'OHHAI accessor works';

is
    exception {
        undef $a;
        $a = Class->new_with_traits(
            traits => ['PRole' => { foo => 'OHHAI' }, 'Role'],
            OHHAI  => 'I FIXED THAT FOR YOU',
            gorge  => 'three rivers',
        );
    },
    undef,
    'prole is applied OK along with a normal role';

can_ok $a, 'OHHAI', 'gorge';

is
    exception {
        undef $a;
        $a = Class->new_with_traits(
            traits => ['Role', 'PRole' => { foo => 'OHHAI' }],
            OHHAI  => 'I FIXED THAT FOR YOU',
            gorge  => 'columbia river',
        );
    },
    undef,
    'prole is applied OK along with a normal role (2)';

can_ok $a, 'OHHAI', 'gorge';

is
    exception {
        undef $a;
        $a = Class->new_with_traits(
            traits => ['Role' => { bullshit => 'params', go => 'here' }],
            gorge  => 'i should have just called this foo',
        );
    },
    undef,
    'regular roles with args can be applied, but args are ignored';

can_ok $a, 'gorge';