{
sub
bar {
'Role::A::bar'
}
sub
xxy {
'Role::B::xxy'
}
::is( ::exception {
},
undef
,
"define role C"
);
sub
foo {
'Role::C::foo'
}
sub
zot {
'Role::C::zot'
}
::is( ::exception {
},
undef
,
"define class A"
);
sub
zot {
'Class::A::zot'
}
}
can_ok( Class::A->new,
qw(foo bar xxy zot)
);
is( Class::A->new->foo,
"Role::C::foo"
,
"... got the right foo method"
);
is( Class::A->new->zot,
"Class::A::zot"
,
"... got the right zot method"
);
is( Class::A->new->bar,
"Role::A::bar"
,
"... got the right bar method"
);
is( Class::A->new->xxy,
"Role::B::xxy"
,
"... got the right xxy method"
);
{
sub
bar {
'Role::A::Shadow::bar'
}
::is( ::exception {
},
undef
,
'... did fufill the requirement of &bar method'
);
}
can_ok( Class::A::Shadow->new,
qw(bar)
);
is( Class::A::Shadow->new->bar,
'Role::A::Shadow::bar'
,
"... got the right bar method"
);
{
sub
foo {
'Role::D::foo'
}
sub
bar {
'Role::D::bar'
}
sub
foo {
'Role::E::foo'
}
sub
xxy {
'Role::E::xxy'
}
::is( ::exception {
},
undef
,
"define role Role::F"
);
sub
foo {
'Role::F::foo'
}
sub
zot {
'Role::F::zot'
}
::is( ::exception {
},
undef
,
"define class Class::B"
);
sub
zot {
'Class::B::zot'
}
}
can_ok( Class::B->new,
qw(foo bar xxy zot)
);
is( Class::B->new->foo,
"Role::F::foo"
,
"... got the &foo method okay"
);
is( Class::B->new->zot,
"Class::B::zot"
,
"... got the &zot method okay"
);
is( Class::B->new->bar,
"Role::D::bar"
,
"... got the &bar method okay"
);
is( Class::B->new->xxy,
"Role::E::xxy"
,
"... got the &xxy method okay"
);
ok(!Role::F->meta->requires_method(
'foo'
),
'... Role::F fufilled the &foo requirement'
);
{
::is( ::exception {
},
undef
,
"... define role Role::D::And::E::NoConflict"
);
sub
foo {
'Role::D::And::E::NoConflict::foo'
}
sub
xxy {
'Role::D::And::E::NoConflict::xxy'
}
sub
bar {
'Role::D::And::E::NoConflict::bar'
}
}
ok(!Role::D::And::E::NoConflict->meta->requires_method(
'foo'
),
'... Role::D::And::E::NoConflict fufilled the &foo requirement'
);
ok(!Role::D::And::E::NoConflict->meta->requires_method(
'xxy'
),
'... Role::D::And::E::NoConflict fulfilled the &xxy requirement'
);
ok(!Role::D::And::E::NoConflict->meta->requires_method(
'bar'
),
'... Role::D::And::E::NoConflict fulfilled the &bar requirement'
);
{
sub
foo {
'Role::H::foo'
}
sub
bar {
'Role::H::bar'
}
sub
foo {
'Role::J::foo'
}
sub
xxy {
'Role::J::xxy'
}
::is( ::exception {
},
undef
,
"define role Role::I"
);
sub
zot {
'Role::I::zot'
}
sub
zzy {
'Role::I::zzy'
}
::like( ::exception {
},
qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/
,
"defining class Class::C fails"
);
sub
zot {
'Class::C::zot'
}
::is( ::exception {
},
undef
,
"resolved with method"
);
sub
foo {
'Class::E::foo'
}
sub
zot {
'Class::E::zot'
}
}
can_ok( Class::E->new,
qw(foo bar xxy zot)
);
is( Class::E->new->foo,
"Class::E::foo"
,
"... got the right &foo method"
);
is( Class::E->new->zot,
"Class::E::zot"
,
"... got the right &zot method"
);
is( Class::E->new->bar,
"Role::H::bar"
,
"... got the right &bar method"
);
is( Class::E->new->xxy,
"Role::J::xxy"
,
"... got the right &xxy method"
);
ok(Role::I->meta->requires_method(
'foo'
),
'... Role::I still have the &foo requirement'
);
{
is( exception {
has
foo
=> (
default
=> __PACKAGE__ .
"::foo"
,
is
=>
"rw"
);
sub
zot {
'Class::D::zot'
}
},
undef
,
"resolved with attr"
);
can_ok( Class::D->new,
qw(foo bar xxy zot)
);
is(
eval
{ Class::D->new->bar },
"Role::H::bar"
,
"bar"
);
is(
eval
{ Class::D->new->zzy },
"Role::I::zzy"
,
"zzy"
);
is(
eval
{ Class::D->new->foo },
"Class::D::foo"
,
"foo"
);
is(
eval
{ Class::D->new->zot },
"Class::D::zot"
,
"zot"
);
}
done_testing;