use strict;
use warnings;
-use Test::More tests => 90;
+use Test::More tests => 67;
use Test::Exception;
BEGIN {
{
package Role::Foo;
- use strict;
- use warnings;
use Moose::Role;
requires 'foo';
sub bar { 'Role::Foo::bar' }
package Role::Bar;
- use strict;
- use warnings;
use Moose::Role;
requires 'bar';
{
package My::Test1;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... our mutually recursive roles combine okay';
package My::Test2;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Role::Bling;
- use strict;
- use warnings;
use Moose::Role;
sub bling { 'Role::Bling::bling' }
package Role::Bling::Bling;
- use strict;
- use warnings;
use Moose::Role;
sub bling { 'Role::Bling::Bling::bling' }
{
package My::Test3;
- use strict;
- use warnings;
use Moose;
::throws_ok {
} qr/requires the method \'bling\' to be implemented/, '... role methods conflicted and method was required';
package My::Test4;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role methods didnt conflict when manually combined';
package My::Test5;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role methods didnt conflict when manually combined (in opposite order)';
package My::Test6;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Role::Bling::Bling::Bling;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Bling::Bling';
{
package Role::Boo;
- use strict;
- use warnings;
use Moose::Role;
has 'ghost' => (is => 'ro', default => 'Role::Boo::ghost');
package Role::Boo::Hoo;
- use strict;
- use warnings;
use Moose::Role;
has 'ghost' => (is => 'ro', default => 'Role::Boo::Hoo::ghost');
{
package My::Test7;
- use strict;
- use warnings;
use Moose;
::throws_ok {
'... role attrs conflicted and method was required';
package My::Test8;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role attrs didnt conflict when manually combined';
package My::Test9;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role attrs didnt conflict when manually combined';
package My::Test10;
- use strict;
- use warnings;
use Moose;
has 'ghost' => (is => 'ro', default => 'My::Test10::ghost');
=cut
-{
- package Role::Plot;
- use strict;
- use warnings;
- use Moose::Role;
-
- override 'twist' => sub {
- super() . ' -> Role::Plot::twist';
- };
-
- package Role::Truth;
- use strict;
- use warnings;
- use Moose::Role;
-
- override 'twist' => sub {
- super() . ' -> Role::Truth::twist';
- };
-}
-
-{
- package My::Test::Base;
- use strict;
- use warnings;
- use Moose;
-
- sub twist { 'My::Test::Base::twist' }
-
- package My::Test11;
- use strict;
- use warnings;
- use Moose;
-
- extends 'My::Test::Base';
-
- ::lives_ok {
- with 'Role::Truth';
- } '... composed the role with override okay';
-
- package My::Test12;
- use strict;
- use warnings;
- use Moose;
-
- extends 'My::Test::Base';
-
- ::lives_ok {
- with 'Role::Plot';
- } '... composed the role with override okay';
-
- package My::Test13;
- use strict;
- use warnings;
- use Moose;
-
- ::dies_ok {
- with 'Role::Plot';
- } '... cannot compose it because we have no superclass';
-
- package My::Test14;
- use strict;
- use warnings;
- use Moose;
-
- extends 'My::Test::Base';
-
- ::throws_ok {
- with 'Role::Plot', 'Role::Truth';
- } qr/Two \'override\' methods of the same name encountered/,
- '... cannot compose it because we have no superclass';
-}
-
-ok(My::Test11->meta->has_method('twist'), '... the twist method has been added');
-ok(My::Test12->meta->has_method('twist'), '... the twist method has been added');
-ok(!My::Test13->meta->has_method('twist'), '... the twist method has not been added');
-ok(!My::Test14->meta->has_method('twist'), '... the twist method has not been added');
-
-ok(!My::Test11->does('Role::Plot'), '... our class does() the correct roles');
-ok(My::Test11->does('Role::Truth'), '... our class does() the correct roles');
-ok(!My::Test12->does('Role::Truth'), '... our class does() the correct roles');
-ok(My::Test12->does('Role::Plot'), '... our class does() the correct roles');
-ok(!My::Test13->does('Role::Plot'), '... our class does() the correct roles');
-ok(!My::Test14->does('Role::Truth'), '... our class does() the correct roles');
-ok(!My::Test14->does('Role::Plot'), '... our class does() the correct roles');
-
-is(My::Test11->twist(), 'My::Test::Base::twist -> Role::Truth::twist', '... got the right method return');
-is(My::Test12->twist(), 'My::Test::Base::twist -> Role::Plot::twist', '... got the right method return');
-ok(!My::Test13->can('twist'), '... no twist method here at all');
-is(My::Test14->twist(), 'My::Test::Base::twist', '... got the right method return (from superclass)');
-
-{
- package Role::Reality;
- use strict;
- use warnings;
- use Moose::Role;
-
- ::throws_ok {
- with 'Role::Plot';
- } qr/A local method of the same name as been found/,
- '... could not compose roles here, it dies';
-
- sub twist {
- 'Role::Reality::twist';
- }
-}
-
-ok(Role::Reality->meta->has_method('twist'), '... the twist method has not been added');
-ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles');
-is(Role::Reality->meta->get_method('twist')->(),
- 'Role::Reality::twist',
- '... the twist method returns the right value');