I'm an idiot. A complete, drooling idiot.
[gitmo/Role-Tiny.git] / t / modifiers.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More;
4 use Test::Fatal;
5
6 BEGIN {
7   plan skip_all => "Class::Method::Modifiers not installed"
8     unless eval "use Class::Method::Modifiers; 1";
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 {
20   package MyClass;
21
22   sub foo { 'class foo' }
23 }
24
25 BEGIN {
26   package BrokenRole;
27   use Role::Tiny;
28
29   around 'broken modifier' => sub { my $orig = shift; $orig->(@_) };
30 }
31
32 sub try_apply_to {
33   my $to = shift;
34   exception { Role::Tiny->apply_role_to_package($to, 'MyRole') }
35 }
36
37 is(try_apply_to('MyClass'), undef, 'role applies cleanly');
38 is(MyClass->foo, 'role foo class foo', 'method modifier');
39
40 ok(exception {
41     my $new_class = Role::Tiny->create_class_with_roles('MyClass', 'BrokenRole');
42 }, 'exception caught creating class with broken modifier in a role');
43
44 done_testing;
45