Commit | Line | Data |
67199842 |
1 | #!/usr/bin/perl |
fde8e43f |
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; |
67199842 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
6475f69d |
9 | use Test::More; |
67199842 |
10 | use Test::Exception; |
11 | use Scalar::Util 'blessed'; |
12 | |
13 | |
67199842 |
14 | { |
15 | package Dog; |
16 | use Mouse::Role; |
17 | |
18 | sub talk { 'woof' } |
19 | |
20 | has fur => ( |
21 | isa => "Str", |
22 | is => "rw", |
23 | default => "dirty", |
24 | ); |
25 | |
26 | package Foo; |
27 | use Mouse; |
28 | |
29 | has 'dog' => ( |
30 | is => 'rw', |
31 | does => 'Dog', |
32 | ); |
33 | } |
34 | |
35 | my $obj = Foo->new; |
6cfa1e5e |
36 | isa_ok($obj, 'Foo'); |
67199842 |
37 | |
38 | ok(!$obj->can( 'talk' ), "... the role is not composed yet"); |
39 | ok(!$obj->can( 'fur' ), 'ditto'); |
40 | ok(!$obj->does('Dog'), '... we do not do any roles yet'); |
41 | |
42 | dies_ok { |
43 | $obj->dog($obj) |
44 | } '... and setting the accessor fails (not a Dog yet)'; |
45 | |
46 | Dog->meta->apply($obj); |
47 | |
48 | ok($obj->does('Dog'), '... we now do the Bark role'); |
49 | ok($obj->can('talk'), "... the role is now composed at the object level"); |
50 | ok($obj->can('fur'), "it has fur"); |
51 | |
52 | is($obj->talk, 'woof', '... got the right return value for the newly composed method'); |
53 | |
54 | lives_ok { |
55 | $obj->dog($obj) |
56 | } '... and setting the accessor is okay'; |
57 | |
58 | is($obj->fur, "dirty", "role attr initialized"); |
6475f69d |
59 | |
60 | done_testing; |