Commit | Line | Data |
e46edf94 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7ff56534 |
6 | use Test::More tests => 10; |
e46edf94 |
7 | use Test::Exception; |
8 | |
7ff56534 |
9 | |
e46edf94 |
10 | |
11 | { |
12 | package Foo::Role; |
e46edf94 |
13 | use Moose::Role; |
14 | |
15 | requires 'foo'; |
16 | } |
17 | |
fa1be058 |
18 | is_deeply( |
19 | [ sort Foo::Role->meta->get_required_method_list ], |
20 | [ 'foo' ], |
21 | '... the Foo::Role has a required method (foo)'); |
22 | |
e46edf94 |
23 | # classes which does not implement required method |
24 | { |
25 | package Foo::Class; |
e46edf94 |
26 | use Moose; |
27 | |
28 | ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class'; |
29 | } |
30 | |
31 | # class which does implement required method |
32 | { |
33 | package Bar::Class; |
e46edf94 |
34 | use Moose; |
35 | |
687e52bb |
36 | ::dies_ok { with('Foo::Class') } '... cannot consume a class, it must be a role'; |
37 | ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Class'; |
e46edf94 |
38 | |
39 | sub foo { 'Bar::Class::foo' } |
40 | } |
41 | |
42 | # role which does implement required method |
43 | { |
44 | package Bar::Role; |
e46edf94 |
45 | use Moose::Role; |
46 | |
47 | ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role'; |
48 | |
49 | sub foo { 'Bar::Role::foo' } |
50 | } |
51 | |
fa1be058 |
52 | is_deeply( |
53 | [ sort Bar::Role->meta->get_required_method_list ], |
54 | [], |
55 | '... the Bar::Role has not inherited the required method from Foo::Role'); |
56 | |
e46edf94 |
57 | # role which does not implement required method |
58 | { |
59 | package Baz::Role; |
fa1be058 |
60 | use Moose::Role; |
e46edf94 |
61 | |
581674fc |
62 | ::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role'; |
e46edf94 |
63 | } |
64 | |
fa1be058 |
65 | is_deeply( |
66 | [ sort Baz::Role->meta->get_required_method_list ], |
67 | [ 'foo' ], |
68 | '... the Baz::Role has inherited the required method from Foo::Role'); |
69 | |
70 | # classes which does not implement required method |
71 | { |
72 | package Baz::Class; |
fa1be058 |
73 | use Moose; |
74 | |
75 | ::dies_ok { with('Baz::Role') } '... no foo method implemented by Baz::Class2'; |
76 | } |
77 | |
78 | # class which does implement required method |
79 | { |
80 | package Baz::Class2; |
fa1be058 |
81 | use Moose; |
82 | |
83 | ::lives_ok { with('Baz::Role') } '... has a foo method implemented by Baz::Class2'; |
84 | |
85 | sub foo { 'Baz::Class2::foo' } |
86 | } |
87 | |
88 | |