79766355df71ee3beaee6caea1621127f0c3695d
[gitmo/Moose.git] / t / 300_immutable / 002_apply_roles_to_immutable.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4;
7 use Test::Exception;
8
9
10
11 {
12     package My::Role;
13     use Moose::Role;
14
15     around 'baz' => sub {
16         my $next = shift;
17         'My::Role::baz(' . $next->(@_) . ')';
18     };
19 }
20
21 {
22     package Foo;
23     use Moose;
24
25     sub baz { 'Foo::baz' }
26
27     __PACKAGE__->meta->make_immutable(debug => 0);
28 }
29
30 my $foo = Foo->new;
31 isa_ok($foo, 'Foo');
32
33 is($foo->baz, 'Foo::baz', '... got the right value');
34
35 lives_ok {
36     My::Role->meta->apply($foo)
37 } '... successfully applied the role to immutable instance';
38
39 is($foo->baz, 'My::Role::baz(Foo::baz)', '... got the right value');
40
41