rudementary support for attribute traits
[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 no_plan => 1;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');
11 }
12
13 {
14     package My::Role;
15     use Moose::Role;
16     
17     around 'baz' => sub { 
18         my $next = shift;
19         'My::Role::baz(' . $next->(@_) . ')';
20     };
21 }
22
23 {
24     package Foo;
25     use Moose;
26     
27     sub baz { 'Foo::baz' }
28     
29         __PACKAGE__->meta->make_immutable(debug => 0);
30 }
31
32 my $foo = Foo->new;
33 isa_ok($foo, 'Foo');
34
35 is($foo->baz, 'Foo::baz', '... got the right value');
36
37 lives_ok {
38     My::Role->meta->apply($foo)
39 } '... successfully applied the role to immutable instance';
40
41 is($foo->baz, 'My::Role::baz(Foo::baz)', '... got the right value');
42
43