support traits/metaclasses in clone_and_inherit_whatever_id_dont_remember_the_name_of...
[gitmo/Moose.git] / t / 030_roles / 015_runtime_roles_and_attrs.t
CommitLineData
c3b35392 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 9;
7use Test::Exception;
8use Scalar::Util 'blessed';
9
10BEGIN {
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
30my $obj = Foo->new;
31isa_ok($obj, 'Foo');
32
33ok(!$obj->can( 'talk' ), "... the role is not composed yet");
34ok(!$obj->does('Dog'), '... we do not do any roles yet');
35
36dies_ok {
37 $obj->dog($obj)
38} '... and setting the accessor fails (not a Dog yet)';
39
40Dog->meta->apply($obj);
41
42ok($obj->does('Dog'), '... we now do the Bark role');
43ok($obj->can('talk'), "... the role is now composed at the object level");
44
45is($obj->talk, 'woof', '... got the right return value for the newly composed method');
46
47lives_ok {
48 $obj->dog($obj)
49} '... and setting the accessor is okay';
50