6 use Test::More tests => 28;
10 use_ok('Moose::Role');
19 has 'bar' => (is => 'rw', isa => 'FooClass');
20 has 'baz' => (is => 'ro');
22 sub goo { 'FooRole::goo' }
23 sub foo { 'FooRole::foo' }
25 override 'boo' => sub { 'FooRole::boo -> ' . super() };
27 around 'blau' => sub {
29 'FooRole::blau -> ' . $c->();
37 sub boo { 'BarClass::boo' }
38 sub foo { 'BarClass::foo' } # << the role overrides this ...
48 sub blau { 'FooClass::blau' }
50 sub goo { 'FooClass::goo' } # << overrides the one from the role ...
53 my $foo_class_meta = FooClass->meta;
54 isa_ok($foo_class_meta, 'Moose::Meta::Class');
56 foreach my $method_name (qw(bar baz foo boo blau goo)) {
57 ok($foo_class_meta->has_method($method_name), '... FooClass has the method ' . $method_name);
60 foreach my $attr_name (qw(bar baz)) {
61 ok($foo_class_meta->has_attribute($attr_name), '... FooClass has the attribute ' . $attr_name);
64 my $foo = FooClass->new();
65 isa_ok($foo, 'FooClass');
74 is($foo->foo, 'FooRole::foo', '... got the right value of foo');
75 is($foo->goo, 'FooClass::goo', '... got the right value of goo');
77 ok(!defined($foo->baz), '... $foo->baz is undefined');
78 ok(!defined($foo->bar), '... $foo->bar is undefined');
82 } '... baz is a read-only accessor';
86 } '... bar is a read-write accessor with a type constraint';
88 my $foo2 = FooClass->new();
89 isa_ok($foo2, 'FooClass');
93 } '... bar is a read-write accessor with a type constraint';
95 is($foo->bar, $foo2, '... got the right value for bar now');
97 is($foo->boo, 'FooRole::boo -> BarClass::boo', '... got the right value from ->boo');
98 is($foo->blau, 'FooRole::blau -> FooClass::blau', '... got the right value from ->blau');