complain loudly if Class::Method::Modifiers is too old (and skip tests)
[gitmo/Role-Tiny.git] / t / modifiers.t
CommitLineData
e32a2123 1use strict;
2use warnings FATAL => 'all';
3use Test::More;
4use Test::Fatal;
5
6BEGIN {
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
11BEGIN {
12 package MyRole;
13
14 use Role::Tiny;
15
16 around foo => sub { my $orig = shift; join ' ', 'role foo', $orig->(@_) };
17}
18
19BEGIN {
06b06c8e 20 package ExtraRole;
21
22 use Role::Tiny;
23}
24
25BEGIN {
e32a2123 26 package MyClass;
27
28 sub foo { 'class foo' }
29}
30
31BEGIN {
06b06c8e 32 package ExtraClass;
33
34 use Role::Tiny::With;
35
36 with qw(MyRole ExtraRole);
37
38 sub foo { 'class foo' }
39}
40
41BEGIN {
e32a2123 42 package BrokenRole;
43 use Role::Tiny;
44
45 around 'broken modifier' => sub { my $orig = shift; $orig->(@_) };
46}
47
48sub try_apply_to {
49 my $to = shift;
50 exception { Role::Tiny->apply_role_to_package($to, 'MyRole') }
51}
52
53is(try_apply_to('MyClass'), undef, 'role applies cleanly');
54is(MyClass->foo, 'role foo class foo', 'method modifier');
06b06c8e 55is(ExtraClass->foo, 'role foo class foo', 'method modifier with composition');
e32a2123 56
57ok(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
61done_testing;
62