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 | |
48 | sub try_apply_to { |
49 | my $to = shift; |
50 | exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } |
51 | } |
52 | |
53 | is(try_apply_to('MyClass'), undef, 'role applies cleanly'); |
54 | is(MyClass->foo, 'role foo class foo', 'method modifier'); |
06b06c8e |
55 | is(ExtraClass->foo, 'role foo class foo', 'method modifier with composition'); |
e32a2123 |
56 | |
57 | ok(exception { |
58 | my $new_class = Role::Tiny->create_class_with_roles('MyClass', 'BrokenRole'); |
59 | }, 'exception caught creating class with broken modifier in a role'); |
60 | |
61 | done_testing; |
62 | |