Commit | Line | Data |
e32a2123 |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | use Test::More; |
4 | use Test::Fatal; |
5 | |
6 | BEGIN { |
3117a19e |
7 | plan skip_all => "Class::Method::Modifiers not installed or too old" |
8 | unless eval "use Class::Method::Modifiers 1.05; 1"; |
e32a2123 |
9 | } |
10 | |
11 | BEGIN { |
12 | package MyRole; |
13 | |
14 | use Role::Tiny; |
15 | |
16 | around foo => sub { my $orig = shift; join ' ', 'role foo', $orig->(@_) }; |
17 | } |
18 | |
19 | BEGIN { |
06b06c8e |
20 | package ExtraRole; |
21 | |
22 | use Role::Tiny; |
23 | } |
24 | |
25 | BEGIN { |
e32a2123 |
26 | package MyClass; |
27 | |
28 | sub foo { 'class foo' } |
29 | } |
30 | |
31 | BEGIN { |
06b06c8e |
32 | package ExtraClass; |
33 | |
34 | use Role::Tiny::With; |
35 | |
36 | with qw(MyRole ExtraRole); |
37 | |
38 | sub foo { 'class foo' } |
39 | } |
40 | |
41 | BEGIN { |
e32a2123 |
42 | package BrokenRole; |
43 | use Role::Tiny; |
44 | |
45 | around 'broken modifier' => sub { my $orig = shift; $orig->(@_) }; |
46 | } |
47 | |
291d3b5e |
48 | BEGIN { |
49 | package MyRole2; |
50 | use Role::Tiny; |
51 | with 'MyRole'; |
52 | } |
53 | |
54 | BEGIN { |
55 | package ExtraClass2; |
56 | use Role::Tiny::With; |
57 | with 'MyRole2'; |
58 | sub foo { 'class foo' } |
59 | } |
60 | |
e32a2123 |
61 | sub try_apply_to { |
62 | my $to = shift; |
63 | exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } |
64 | } |
65 | |
66 | is(try_apply_to('MyClass'), undef, 'role applies cleanly'); |
67 | is(MyClass->foo, 'role foo class foo', 'method modifier'); |
06b06c8e |
68 | is(ExtraClass->foo, 'role foo class foo', 'method modifier with composition'); |
e32a2123 |
69 | |
291d3b5e |
70 | is(ExtraClass2->foo, 'role foo class foo', |
71 | 'method modifier with role composed into role'); |
72 | |
e32a2123 |
73 | ok(exception { |
74 | my $new_class = Role::Tiny->create_class_with_roles('MyClass', 'BrokenRole'); |
75 | }, 'exception caught creating class with broken modifier in a role'); |
76 | |
77 | done_testing; |
78 | |