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