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