Commit | Line | Data |
---|---|---|
d9bb6c63 | 1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
a28e50e4 | 6 | use Test::More; |
be0ed157 | 7 | use Test::Fatal; |
d9bb6c63 | 8 | |
7ff56534 | 9 | |
d9bb6c63 | 10 | { |
11 | package My::Role; | |
12 | use Moose::Role; | |
d03bd989 | 13 | |
14 | around 'baz' => sub { | |
d9bb6c63 | 15 | my $next = shift; |
16 | 'My::Role::baz(' . $next->(@_) . ')'; | |
17 | }; | |
18 | } | |
19 | ||
20 | { | |
21 | package Foo; | |
22 | use Moose; | |
d03bd989 | 23 | |
d9bb6c63 | 24 | sub baz { 'Foo::baz' } |
d03bd989 | 25 | |
9978e85e | 26 | __PACKAGE__->meta->make_immutable(debug => 0); |
d9bb6c63 | 27 | } |
28 | ||
29 | my $foo = Foo->new; | |
30 | isa_ok($foo, 'Foo'); | |
31 | ||
32 | is($foo->baz, 'Foo::baz', '... got the right value'); | |
33 | ||
be0ed157 | 34 | ok ! exception { |
d9bb6c63 | 35 | My::Role->meta->apply($foo) |
be0ed157 | 36 | }, '... successfully applied the role to immutable instance'; |
d9bb6c63 | 37 | |
38 | is($foo->baz, 'My::Role::baz(Foo::baz)', '... got the right value'); | |
39 | ||
a28e50e4 | 40 | done_testing; |