File: parameterized.t

package info (click to toggle)
libmoosex-traits-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 184 kB
  • sloc: perl: 1,372; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 2,024 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
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
use strict;
use warnings;
use Test::More;
use Test::Exception;

BEGIN {
    plan 'skip_all', 'testing parameterized roles requires MooseX::Role::Parameterized 0.13'
      unless eval {
        require MooseX::Role::Parameterized;
        MooseX::Role::Parameterized->VERSION('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';
}

lives_ok {
    Class->new;
} 'making class is OK';

lives_ok {
    Class->new_with_traits;
} 'making class with no traits is OK';

my $a;

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

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

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

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

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

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

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

can_ok $a, 'gorge';