X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F030_roles%2F001_meta_role.t;fp=t%2F030_roles%2F001_meta_role.t;h=b6acf2bd7cdbf679507f9c80fbea1ad9a0f0066e;hp=0000000000000000000000000000000000000000;hb=6cfa1e5e70616fb102915489c02d8347ffa912fb;hpb=4f9945f5a128e120049ce8a7a30cf469d1568b9b diff --git a/t/030_roles/001_meta_role.t b/t/030_roles/001_meta_role.t new file mode 100755 index 0000000..b6acf2b --- /dev/null +++ b/t/030_roles/001_meta_role.t @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 26; +use Test::Exception; + +use Mouse::Meta::Role; + +{ + package FooRole; + + our $VERSION = '0.01'; + + sub foo { 'FooRole::foo' } +} + +my $foo_role = Mouse::Meta::Role->initialize('FooRole'); +isa_ok($foo_role, 'Mouse::Meta::Role'); +#isa_ok($foo_role, 'Class::MOP::Module'); + +is($foo_role->name, 'FooRole', '... got the right name of FooRole'); +is($foo_role->version, '0.01', '... got the right version of FooRole'); + +# methods ... + +ok($foo_role->has_method('foo'), '... FooRole has the foo method'); +is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method'); + +isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method'); + +is_deeply( + [ $foo_role->get_method_list() ], + [ 'foo' ], + '... got the right method list'); + +# attributes ... + +is_deeply( + [ $foo_role->get_attribute_list() ], + [], + '... got the right attribute list'); + +ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute'); + +lives_ok { + $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo')); +} '... added the bar attribute okay'; + +is_deeply( + [ $foo_role->get_attribute_list() ], + [ 'bar' ], + '... got the right attribute list'); + +ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); + +is_deeply( + join('|', %{$foo_role->get_attribute('bar')}), + join('|', %{+{ is => 'rw', isa => 'Foo' }}), + '... got the correct description of the bar attribute'); + +lives_ok { + $foo_role->add_attribute('baz' => (is => 'ro')); +} '... added the baz attribute okay'; + +is_deeply( + [ sort $foo_role->get_attribute_list() ], + [ 'bar', 'baz' ], + '... got the right attribute list'); + +ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); + +is_deeply( + $foo_role->get_attribute('baz'), + { is => 'ro' }, + '... got the correct description of the baz attribute'); + +lives_ok { + $foo_role->remove_attribute('bar'); +} '... removed the bar attribute okay'; + +is_deeply( + [ $foo_role->get_attribute_list() ], + [ 'baz' ], + '... got the right attribute list'); + +ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute'); +ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute'); + +# method modifiers + +ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier'); + +my $method = sub { "FooRole::boo:before" }; +lives_ok { + $foo_role->add_before_method_modifier('boo' => $method); +} '... added a method modifier okay'; + +ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier'); +is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back'); + +is_deeply( + [ $foo_role->get_method_modifier_list('before') ], + [ 'boo' ], + '... got the right list of before method modifiers');