Commit | Line | Data |
67199842 |
1 | #!/usr/bin/perl |
c47cf415 |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
67199842 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
c47cf415 |
9 | use Test::More; |
10 | $TODO = q{Mouse is not yet completed}; |
67199842 |
11 | use Test::Exception; |
12 | |
13 | =pod |
14 | |
15 | The idea and examples for this feature are taken |
16 | from the Fortress spec. |
17 | |
18 | http://research.sun.com/projects/plrg/fortress0903.pdf |
19 | |
6cfa1e5e |
20 | trait OrganicMolecule extends Molecule |
21 | excludes { InorganicMolecule } |
22 | end |
23 | trait InorganicMolecule extends Molecule end |
67199842 |
24 | |
25 | =cut |
26 | |
27 | { |
28 | package Molecule; |
29 | use Mouse::Role; |
30 | |
31 | package Molecule::Organic; |
32 | use Mouse::Role; |
6cfa1e5e |
33 | |
67199842 |
34 | with 'Molecule'; |
35 | excludes 'Molecule::Inorganic'; |
6cfa1e5e |
36 | |
67199842 |
37 | package Molecule::Inorganic; |
6cfa1e5e |
38 | use Mouse::Role; |
39 | |
40 | with 'Molecule'; |
67199842 |
41 | } |
42 | |
43 | ok(Molecule::Organic->meta->excludes_role('Molecule::Inorganic'), '... Molecule::Organic exludes Molecule::Inorganic'); |
44 | is_deeply( |
6cfa1e5e |
45 | [ Molecule::Organic->meta->get_excluded_roles_list() ], |
67199842 |
46 | [ 'Molecule::Inorganic' ], |
47 | '... Molecule::Organic exludes Molecule::Inorganic'); |
48 | |
49 | =pod |
50 | |
6cfa1e5e |
51 | Check some basic conflicts when combining |
67199842 |
52 | the roles into the same class |
53 | |
54 | =cut |
55 | |
56 | { |
57 | package My::Test1; |
58 | use Mouse; |
6cfa1e5e |
59 | |
67199842 |
60 | ::lives_ok { |
61 | with 'Molecule::Organic'; |
62 | } '... adding the role (w/ excluded roles) okay'; |
63 | |
64 | package My::Test2; |
65 | use Mouse; |
6cfa1e5e |
66 | |
67199842 |
67 | ::throws_ok { |
68 | with 'Molecule::Organic', 'Molecule::Inorganic'; |
6cfa1e5e |
69 | } qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/, |
70 | '... adding the role w/ excluded role conflict dies okay'; |
71 | |
67199842 |
72 | package My::Test3; |
73 | use Mouse; |
6cfa1e5e |
74 | |
67199842 |
75 | ::lives_ok { |
76 | with 'Molecule::Organic'; |
6cfa1e5e |
77 | } '... adding the role (w/ excluded roles) okay'; |
78 | |
67199842 |
79 | ::throws_ok { |
80 | with 'Molecule::Inorganic'; |
6cfa1e5e |
81 | } qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/, |
82 | '... adding the role w/ excluded role conflict dies okay'; |
67199842 |
83 | } |
84 | |
85 | ok(My::Test1->does('Molecule::Organic'), '... My::Test1 does Molecule::Organic'); |
86 | ok(My::Test1->does('Molecule'), '... My::Test1 does Molecule'); |
87 | ok(My::Test1->meta->excludes_role('Molecule::Inorganic'), '... My::Test1 excludes Molecule::Organic'); |
88 | |
89 | ok(!My::Test2->does('Molecule::Organic'), '... ! My::Test2 does Molecule::Organic'); |
90 | ok(!My::Test2->does('Molecule::Inorganic'), '... ! My::Test2 does Molecule::Inorganic'); |
91 | |
92 | ok(My::Test3->does('Molecule::Organic'), '... My::Test3 does Molecule::Organic'); |
93 | ok(My::Test3->does('Molecule'), '... My::Test1 does Molecule'); |
94 | ok(My::Test3->meta->excludes_role('Molecule::Inorganic'), '... My::Test3 excludes Molecule::Organic'); |
95 | ok(!My::Test3->does('Molecule::Inorganic'), '... ! My::Test3 does Molecule::Inorganic'); |
96 | |
97 | =pod |
98 | |
6cfa1e5e |
99 | Check some basic conflicts when combining |
67199842 |
100 | the roles into the a superclass |
101 | |
102 | =cut |
103 | |
104 | { |
105 | package Methane; |
106 | use Mouse; |
6cfa1e5e |
107 | |
67199842 |
108 | with 'Molecule::Organic'; |
6cfa1e5e |
109 | |
67199842 |
110 | package My::Test4; |
111 | use Mouse; |
6cfa1e5e |
112 | |
113 | extends 'Methane'; |
114 | |
67199842 |
115 | ::throws_ok { |
6cfa1e5e |
116 | with 'Molecule::Inorganic'; |
67199842 |
117 | } qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/, |
118 | '... cannot add exculded role into class which extends Methane'; |
119 | } |
120 | |
121 | ok(Methane->does('Molecule::Organic'), '... Methane does Molecule::Organic'); |
122 | ok(My::Test4->isa('Methane'), '... My::Test4 isa Methane'); |
123 | ok(My::Test4->does('Molecule::Organic'), '... My::Test4 does Molecule::Organic'); |
124 | ok(My::Test4->meta->does_role('Molecule::Organic'), '... My::Test4 meat does_role Molecule::Organic'); |
125 | ok(My::Test4->meta->excludes_role('Molecule::Inorganic'), '... My::Test4 meta excludes Molecule::Organic'); |
126 | ok(!My::Test4->does('Molecule::Inorganic'), '... My::Test4 does Molecule::Inorganic'); |
127 | |
c47cf415 |
128 | done_testing; |