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