6 use Test::More tests => 36;
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 ok($foo_class_meta->does_role('FooRole'), '... the FooClass->meta does_role FooRole');
57 ok(!$foo_class_meta->does_role('OtherRole'), '... the FooClass->meta !does_role OtherRole');
59 foreach my $method_name (qw(bar baz foo boo blau goo)) {
60 ok($foo_class_meta->has_method($method_name), '... FooClass has the method ' . $method_name);
63 foreach my $attr_name (qw(bar baz)) {
64 ok($foo_class_meta->has_attribute($attr_name), '... FooClass has the attribute ' . $attr_name);
67 can_ok('FooClass', 'does');
68 ok(FooClass->does('FooRole'), '... the FooClass does FooRole');
69 ok(!FooClass->does('OtherRole'), '... the FooClass does not do OtherRole');
71 my $foo = FooClass->new();
72 isa_ok($foo, 'FooClass');
75 ok($foo->does('FooRole'), '... an instance of FooClass does FooRole');
76 ok(!$foo->does('OtherRole'), '... and instance of FooClass does not do OtherRole');
85 is($foo->foo, 'FooRole::foo', '... got the right value of foo');
86 is($foo->goo, 'FooClass::goo', '... got the right value of goo');
88 ok(!defined($foo->baz), '... $foo->baz is undefined');
89 ok(!defined($foo->bar), '... $foo->bar is undefined');
93 } '... baz is a read-only accessor';
97 } '... bar is a read-write accessor with a type constraint';
99 my $foo2 = FooClass->new();
100 isa_ok($foo2, 'FooClass');
104 } '... bar is a read-write accessor with a type constraint';
106 is($foo->bar, $foo2, '... got the right value for bar now');
108 is($foo->boo, 'FooRole::boo -> BarClass::boo', '... got the right value from ->boo');
109 is($foo->blau, 'FooRole::blau -> FooClass::blau', '... got the right value from ->blau');