(failing) test for runtime roles and non-moose classes + does attrs
[gitmo/Moose.git] / t / 030_roles / 016_runtime_roles_and_nonmoose.t
CommitLineData
a6ff1f9e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 7;
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 no Moose;
30
31 package Bar;
32
33 sub new {
34 return bless {}, shift;
35 }
36}
37
38my $obj = Bar->new;
39isa_ok($obj, 'Bar');
40
41my $foo = Foo->new;
42
43ok(!$obj->can( 'talk' ), "... the role is not composed yet");
44
45dies_ok {
46 $foo->dog($obj)
47} '... and setting the accessor fails (not a Dog yet)';
48
49Dog->meta->apply($obj);
50
51ok($obj->can('talk'), "... the role is now composed at the object level");
52
53is($obj->talk, 'woof', '... got the right return value for the newly composed method');
54
55lives_ok {
56 $foo->dog($obj)
57} '... and setting the accessor is okay';
58