Commit | Line | Data |
4060c871 |
1 | #!/usr/bin/perl |
f1a8bff3 |
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; |
4060c871 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
f1a8bff3 |
9 | use Test::More; |
4060c871 |
10 | use Test::Exception; |
11 | |
12 | |
4060c871 |
13 | { |
14 | package Foo::Role; |
15 | use Mouse::Role; |
16 | use Mouse::Util::TypeConstraints; |
17 | |
18 | # if does() exists on its own, then |
19 | # we create a type constraint for |
20 | # it, just as we do for isa() |
21 | has 'bar' => (is => 'rw', does => 'Bar::Role'); |
22 | has 'baz' => ( |
23 | is => 'rw', |
f1a8bff3 |
24 | does => role_type('Bar::Role') |
4060c871 |
25 | ); |
26 | |
f1a8bff3 |
27 | package Foo::Class; |
28 | use Mouse; |
29 | |
30 | with 'Foo::Role'; |
31 | |
4060c871 |
32 | package Bar::Role; |
33 | use Mouse::Role; |
34 | |
35 | # if isa and does appear together, then see if Class->does(Role) |
36 | # if it does work... then the does() check is actually not needed |
37 | # since the isa() check will imply the does() check |
f1a8bff3 |
38 | has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role'); |
4060c871 |
39 | |
40 | package Bar::Class; |
41 | use Mouse; |
42 | |
43 | with 'Bar::Role'; |
4060c871 |
44 | } |
45 | |
46 | my $foo = Foo::Class->new; |
47 | isa_ok($foo, 'Foo::Class'); |
48 | |
49 | my $bar = Bar::Class->new; |
50 | isa_ok($bar, 'Bar::Class'); |
51 | |
52 | lives_ok { |
53 | $foo->bar($bar); |
54 | } '... bar passed the type constraint okay'; |
55 | |
56 | dies_ok { |
57 | $foo->bar($foo); |
58 | } '... foo did not pass the type constraint okay'; |
59 | |
60 | lives_ok { |
61 | $foo->baz($bar); |
62 | } '... baz passed the type constraint okay'; |
63 | |
64 | dies_ok { |
65 | $foo->baz($foo); |
66 | } '... foo did not pass the type constraint okay'; |
67 | |
68 | lives_ok { |
69 | $bar->foo($foo); |
70 | } '... foo passed the type constraint okay'; |
71 | |
72 | |
73 | |
74 | # some error conditions |
75 | |
76 | { |
77 | package Baz::Class; |
4060c871 |
78 | use Mouse; |
79 | |
4060c871 |
80 | # if isa and does appear together, then see if Class->does(Role) |
81 | # if it does not,.. we have a conflict... so we die loudly |
82 | ::dies_ok { |
f1a8bff3 |
83 | has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class'); |
4060c871 |
84 | } '... cannot have a does() which is not done by the isa()'; |
85 | } |
86 | |
87 | { |
88 | package Bling; |
89 | use strict; |
90 | use warnings; |
91 | |
92 | sub bling { 'Bling::bling' } |
93 | |
94 | package Bling::Bling; |
4060c871 |
95 | use Mouse; |
96 | |
4060c871 |
97 | # if isa and does appear together, then see if Class->does(Role) |
98 | # if it does not,.. we have a conflict... so we die loudly |
99 | ::dies_ok { |
f1a8bff3 |
100 | has 'foo' => (isa => 'Bling', does => 'Bar::Class'); |
4060c871 |
101 | } '... cannot have a isa() which is cannot does()'; |
102 | } |
103 | |
f1a8bff3 |
104 | done_testing; |