Perltidy this code a bit.
[gitmo/Moose.git] / t / 030_roles / 015_runtime_roles_and_attrs.t
CommitLineData
c3b35392 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
519e8a1f 6use Test::More tests => 12;
c3b35392 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
519e8a1f 21 has fur => (
22 isa => "Str",
23 is => "rw",
24 default => "dirty",
25 );
26
c3b35392 27 package Foo;
28 use Moose;
29
30 has 'dog' => (
31 is => 'rw',
32 does => 'Dog',
33 );
34}
35
36my $obj = Foo->new;
37isa_ok($obj, 'Foo');
38
39ok(!$obj->can( 'talk' ), "... the role is not composed yet");
519e8a1f 40ok(!$obj->can( 'fur' ), 'ditto');
c3b35392 41ok(!$obj->does('Dog'), '... we do not do any roles yet');
42
43dies_ok {
44 $obj->dog($obj)
45} '... and setting the accessor fails (not a Dog yet)';
46
47Dog->meta->apply($obj);
48
49ok($obj->does('Dog'), '... we now do the Bark role');
50ok($obj->can('talk'), "... the role is now composed at the object level");
519e8a1f 51ok($obj->can('fur'), "it has fur");
c3b35392 52
53is($obj->talk, 'woof', '... got the right return value for the newly composed method');
54
55lives_ok {
56 $obj->dog($obj)
57} '... and setting the accessor is okay';
58
519e8a1f 59is($obj->fur, "dirty", "role attr initialized");