Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 001_meta_role.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
98bbe659 6use Test::More tests => 25;
67199842 7use Test::Exception;
8
9use Mouse::Meta::Role;
10
11{
12 package FooRole;
13
14 our $VERSION = '0.01';
15
16 sub foo { 'FooRole::foo' }
17}
18
19my $foo_role = Mouse::Meta::Role->initialize('FooRole');
20isa_ok($foo_role, 'Mouse::Meta::Role');
21#isa_ok($foo_role, 'Class::MOP::Module'); ## Mouse: doesn't use Class::MOP
22
23is($foo_role->name, 'FooRole', '... got the right name of FooRole');
24#is($foo_role->version, '0.01', '... got the right version of FooRole'); ## Mouse: ->version is cfrom Class::MOP
25
26# methods ...
27
28ok($foo_role->has_method('foo'), '... FooRole has the foo method');
29is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
30
31isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
32
33is_deeply(
34 [ $foo_role->get_method_list() ],
35 [ 'foo' ],
36 '... got the right method list');
37
38# attributes ...
39
40is_deeply(
41 [ $foo_role->get_attribute_list() ],
42 [],
43 '... got the right attribute list');
44
45ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
46
47lives_ok {
48 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
49} '... added the bar attribute okay';
50
51is_deeply(
52 [ $foo_role->get_attribute_list() ],
53 [ 'bar' ],
54 '... got the right attribute list');
55
56ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
57
58is_deeply(
59 $foo_role->get_attribute('bar'),
60 { is => 'rw', isa => 'Foo' },
61 '... got the correct description of the bar attribute');
62
63lives_ok {
64 $foo_role->add_attribute('baz' => (is => 'ro'));
65} '... added the baz attribute okay';
66
67is_deeply(
68 [ sort $foo_role->get_attribute_list() ],
69 [ 'bar', 'baz' ],
70 '... got the right attribute list');
71
72ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
73
74is_deeply(
75 $foo_role->get_attribute('baz'),
76 { is => 'ro' },
77 '... got the correct description of the baz attribute');
78
79lives_ok {
80 $foo_role->remove_attribute('bar');
81} '... removed the bar attribute okay';
82
83is_deeply(
84 [ $foo_role->get_attribute_list() ],
85 [ 'baz' ],
86 '... got the right attribute list');
87
88ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
89ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
90
91# method modifiers
92
93ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
94
95my $method = sub { "FooRole::boo:before" };
96lives_ok {
97 $foo_role->add_before_method_modifier('boo' => $method);
98} '... added a method modifier okay';
99
100ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
101is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
102
103is_deeply(
104 [ $foo_role->get_method_modifier_list('before') ],
105 [ 'boo' ],
106 '... got the right list of before method modifiers');