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