s/make_immutable/metaclass->make_immutable/
[gitmo/Moose.git] / t / 030_roles / 016_runtime_roles_and_nonmoose.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7 use Test::Exception;
8 use Scalar::Util 'blessed';
9
10 BEGIN {
11     use_ok('Moose');
12 }
13
14
15 {
16     package Dog;
17     use Moose::Role;
18
19     sub talk { 'woof' }
20
21     package Foo;
22     use Moose;
23
24     has 'dog' => (
25         is   => 'rw',
26         does => 'Dog',
27     );
28
29     no Moose;
30
31     package Bar;
32
33     sub new {
34       return bless {}, shift;
35     }
36 }
37
38 my $bar = Bar->new;
39 isa_ok($bar, 'Bar');    
40
41 my $foo = Foo->new;
42 isa_ok($foo, 'Foo');  
43
44 ok(!$bar->can( 'talk' ), "... the role is not composed yet");
45
46 dies_ok {
47     $foo->dog($bar)
48 } '... and setting the accessor fails (not a Dog yet)';
49
50 Dog->meta->apply($bar);
51
52 ok($bar->can('talk'), "... the role is now composed at the object level");
53
54 is($bar->talk, 'woof', '... got the right return value for the newly composed method');
55
56 lives_ok {
57     $foo->dog($bar)
58 } '... and setting the accessor is okay';
59