|
Packit |
73b376 |
use strict;
|
|
Packit |
73b376 |
use warnings;
|
|
Packit |
73b376 |
use Test::More;
|
|
Packit |
73b376 |
|
|
Packit |
73b376 |
use Class::Method::Modifiers 1.05 ();
|
|
Packit |
73b376 |
|
|
Packit |
73b376 |
{
|
|
Packit |
73b376 |
package One; use Role::Tiny;
|
|
Packit |
73b376 |
around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
|
|
Packit |
73b376 |
package Two; use Role::Tiny;
|
|
Packit |
73b376 |
around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
|
|
Packit |
73b376 |
package Three; use Role::Tiny;
|
|
Packit |
73b376 |
around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
|
|
Packit |
73b376 |
package Four; use Role::Tiny;
|
|
Packit |
73b376 |
around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
|
|
Packit |
73b376 |
package BaseClass; sub foo { __PACKAGE__ }
|
|
Packit |
73b376 |
}
|
|
Packit |
73b376 |
|
|
Packit |
73b376 |
foreach my $combo (
|
|
Packit |
73b376 |
[ qw(One Two Three Four) ],
|
|
Packit |
73b376 |
[ qw(Two Four Three) ],
|
|
Packit |
73b376 |
[ qw(One Two) ]
|
|
Packit |
73b376 |
) {
|
|
Packit |
73b376 |
my $combined = Role::Tiny->create_class_with_roles('BaseClass', @$combo);
|
|
Packit |
73b376 |
is_deeply(
|
|
Packit |
73b376 |
[ $combined->foo ], [ reverse(@$combo), 'BaseClass' ],
|
|
Packit |
73b376 |
"${combined} ok"
|
|
Packit |
73b376 |
);
|
|
Packit |
73b376 |
my $object = bless({}, 'BaseClass');
|
|
Packit |
73b376 |
Role::Tiny->apply_roles_to_object($object, @$combo);
|
|
Packit |
73b376 |
is(ref($object), $combined, 'Object reblessed into correct class');
|
|
Packit |
73b376 |
}
|
|
Packit |
73b376 |
|
|
Packit |
73b376 |
{
|
|
Packit |
73b376 |
package Five; use Role::Tiny;
|
|
Packit |
73b376 |
requires 'bar';
|
|
Packit |
73b376 |
around bar => sub { my $orig = shift; $orig->(@_) };
|
|
Packit |
73b376 |
}
|
|
Packit |
73b376 |
{
|
|
Packit |
73b376 |
is eval {
|
|
Packit |
73b376 |
package WithFive;
|
|
Packit |
73b376 |
use Role::Tiny::With;
|
|
Packit |
73b376 |
use base 'BaseClass';
|
|
Packit |
73b376 |
with 'Five';
|
|
Packit |
73b376 |
}, undef,
|
|
Packit |
73b376 |
"composing an around modifier fails when method doesn't exist";
|
|
Packit |
73b376 |
like $@, qr/Can't apply Five to WithFive - missing bar/,
|
|
Packit |
73b376 |
' ... with correct error message';
|
|
Packit |
73b376 |
}
|
|
Packit |
73b376 |
{
|
|
Packit |
73b376 |
is eval {
|
|
Packit |
73b376 |
Role::Tiny->create_class_with_roles('BaseClass', 'Five');
|
|
Packit |
73b376 |
}, undef,
|
|
Packit |
73b376 |
"composing an around modifier fails when method doesn't exist";
|
|
Packit |
73b376 |
like $@, qr/Can't apply Five to .* - missing bar/,
|
|
Packit |
73b376 |
' ... with correct error message';
|
|
Packit |
73b376 |
}
|
|
Packit |
73b376 |
|
|
Packit |
73b376 |
done_testing;
|