use strict;
use warnings;
-use Test::More tests => 33;
+use Test::More tests => 39;
use Test::Exception;
BEGIN {
use_ok('Moose::Role');
}
-
-
{
package FooRole;
use Moose::Role;
sub goo { 'FooRole::goo' }
sub foo { 'FooRole::foo' }
+
+ override 'boo' => sub { 'FooRole::boo -> ' . super() };
+
+ around 'blau' => sub {
+ my $c = shift;
+ 'FooRole::blau -> ' . $c->();
+ };
+}{
package BarClass;
use Moose;
sub boo { 'BarClass::boo' }
sub foo { 'BarClass::foo' } # << the role overrides this ...
+
+ __PACKAGE__->meta->make_immutable(debug => 0);
+}{
package FooClass;
use Moose;
extends 'BarClass';
with 'FooRole';
+
+ sub blau { 'FooClass::blau' }
sub goo { 'FooClass::goo' } # << overrides the one from the role ...
+
+ __PACKAGE__->meta->make_immutable(debug => 0);
}
my $foo_class_meta = FooClass->meta;
ok($foo_class_meta->does_role('FooRole'), '... the FooClass->meta does_role FooRole');
ok(!$foo_class_meta->does_role('OtherRole'), '... the FooClass->meta !does_role OtherRole');
-foreach my $method_name (qw(bar baz foo goo)) {
+foreach my $method_name (qw(bar baz foo boo blau goo)) {
ok($foo_class_meta->has_method($method_name), '... FooClass has the method ' . $method_name);
}
can_ok($foo, 'bar');
can_ok($foo, 'baz');
can_ok($foo, 'foo');
+can_ok($foo, 'boo');
can_ok($foo, 'goo');
+can_ok($foo, 'blau');
is($foo->foo, 'FooRole::foo', '... got the right value of foo');
is($foo->goo, 'FooClass::goo', '... got the right value of goo');
is($foo->bar, $foo2, '... got the right value for bar now');
+is($foo->boo, 'FooRole::boo -> BarClass::boo', '... got the right value from ->boo');
+is($foo->blau, 'FooRole::blau -> FooClass::blau', '... got the right value from ->blau');