Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / roles / more_alias_and_exclude.t
CommitLineData
28412c0b 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
28412c0b 8
7ff56534 9
28412c0b 10{
11 package Foo;
12 use Moose::Role;
d03bd989 13
28412c0b 14 sub foo { 'Foo::foo' }
15 sub bar { 'Foo::bar' }
16 sub baz { 'Foo::baz' }
d03bd989 17 sub gorch { 'Foo::gorch' }
18
28412c0b 19 package Bar;
20 use Moose::Role;
21
22 sub foo { 'Bar::foo' }
23 sub bar { 'Bar::bar' }
24 sub baz { 'Bar::baz' }
d03bd989 25 sub gorch { 'Bar::gorch' }
28412c0b 26
27 package Baz;
28 use Moose::Role;
d03bd989 29
28412c0b 30 sub foo { 'Baz::foo' }
31 sub bar { 'Baz::bar' }
32 sub baz { 'Baz::baz' }
d03bd989 33 sub gorch { 'Baz::gorch' }
34
28412c0b 35 package Gorch;
36 use Moose::Role;
d03bd989 37
28412c0b 38 sub foo { 'Gorch::foo' }
39 sub bar { 'Gorch::bar' }
40 sub baz { 'Gorch::baz' }
d03bd989 41 sub gorch { 'Gorch::gorch' }
28412c0b 42}
43
44{
45 package My::Class;
46 use Moose;
d03bd989 47
b10dde3a 48 ::is( ::exception {
c8b8d92f 49 with 'Foo' => { -excludes => [qw/bar baz gorch/], -alias => { gorch => 'foo_gorch' } },
50 'Bar' => { -excludes => [qw/foo baz gorch/] },
51 'Baz' => { -excludes => [qw/foo bar gorch/], -alias => { foo => 'baz_foo', bar => 'baz_bar' } },
52 'Gorch' => { -excludes => [qw/foo bar baz/] };
b10dde3a 53 }, undef, '... everything works out all right' );
28412c0b 54}
55
56my $c = My::Class->new;
57isa_ok($c, 'My::Class');
58
59is($c->foo, 'Foo::foo', '... got the right method');
60is($c->bar, 'Bar::bar', '... got the right method');
61is($c->baz, 'Baz::baz', '... got the right method');
62is($c->gorch, 'Gorch::gorch', '... got the right method');
63
64is($c->foo_gorch, 'Foo::gorch', '... got the right method');
65is($c->baz_foo, 'Baz::foo', '... got the right method');
66is($c->baz_bar, 'Baz::bar', '... got the right method');
67
2afe5289 68{
69 package Splunk;
70
71 use Moose::Role;
72
73 sub baz { 'Splunk::baz' }
74 sub gorch { 'Splunk::gorch' }
75
76 ::is(::exception { with 'Foo' }, undef, 'role to role application works');
77
78 package My::Class2;
79
80 use Moose;
81
82 ::is(::exception { with 'Splunk' }, undef, 'and the role can be consumed');
83}
84
85is(My::Class2->foo, 'Foo::foo', '... got the right method');
86is(My::Class2->bar, 'Foo::bar', '... got the right method');
87is(My::Class2->baz, 'Splunk::baz', '... got the right method');
88is(My::Class2->gorch, 'Splunk::gorch', '... got the right method');
89
a28e50e4 90done_testing;