Update some doc
[gitmo/Mouse.git] / t / 402-attribute-application.t
CommitLineData
086c223b 1#!/usr/bin/env perl
2use strict;
3use warnings;
f650b4b2 4use Test::More tests => 11;
69ac1dcf 5use Test::Exception;
086c223b 6
7do {
8 package Role;
9 use Mouse::Role;
10
69ac1dcf 11 has 'attr' => (
12 default => 'Role',
13 );
086c223b 14
15 no Mouse::Role;
16};
17
69ac1dcf 18is_deeply(Role->meta->get_attribute('attr'), {default => 'Role'});
19
086c223b 20do {
21 package Class;
22 use Mouse;
23 with 'Role';
24
25 no Mouse;
26};
27
28ok(Class->meta->has_attribute('attr'), "role application added the attribute");
69ac1dcf 29is(Class->meta->get_attribute('attr')->default, 'Role');
30
31do {
32 package Role2;
33 use Mouse::Role;
34
35 has 'attr' => (
36 default => 'Role2',
37 );
38
39 no Mouse::Role;
40};
41
42lives_ok {
43 package Class2;
44 use Mouse;
45 with 'Role';
46 with 'Role2';
47};
48
0ba3591e 49is(Class2->meta->get_attribute('attr')->default, 'Role');
086c223b 50
f650b4b2 51lives_ok {
52 package Class3;
53 use Mouse;
54
55 with 'Role';
56
57 has attr => (
58 default => 'Class3',
59 );
60};
61
62is(Class3->meta->get_attribute('attr')->default, 'Class3');
63
64lives_ok {
65 package Class::Parent;
66 use Mouse;
67
68 has attr => (
69 default => 'Class::Parent',
70 );
71};
72
73is(Class::Parent->meta->get_attribute('attr')->default, 'Class::Parent', 'local class wins over the role');
74
75lives_ok {
76 package Class::Child;
77 use Mouse;
78
79 extends 'Class::Parent';
80
81 with 'Role';
82};
83
84is(Class::Child->meta->get_attribute('attr')->default, 'Role', 'role wins over the parent method');