Regenerate test files
[gitmo/Mouse.git] / t / 030_roles / 015_runtime_roles_and_attrs.t
CommitLineData
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!!!
4use t::lib::MooseCompat;
67199842 5
6use strict;
7use warnings;
8
6475f69d 9use Test::More;
67199842 10use Test::Exception;
11use 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
35my $obj = Foo->new;
6cfa1e5e 36isa_ok($obj, 'Foo');
67199842 37
38ok(!$obj->can( 'talk' ), "... the role is not composed yet");
39ok(!$obj->can( 'fur' ), 'ditto');
40ok(!$obj->does('Dog'), '... we do not do any roles yet');
41
42dies_ok {
43 $obj->dog($obj)
44} '... and setting the accessor fails (not a Dog yet)';
45
46Dog->meta->apply($obj);
47
48ok($obj->does('Dog'), '... we now do the Bark role');
49ok($obj->can('talk'), "... the role is now composed at the object level");
50ok($obj->can('fur'), "it has fur");
51
52is($obj->talk, 'woof', '... got the right return value for the newly composed method');
53
54lives_ok {
55 $obj->dog($obj)
56} '... and setting the accessor is okay';
57
58is($obj->fur, "dirty", "role attr initialized");
6475f69d 59
60done_testing;