3 use lib 'lib', 't/role-basic/lib';
5 require Role::Tiny::Restricted;
9 package My::Does::Basic1;
10 use Role::Tiny::Restricted;
11 requires 'turbo_charger';
14 return __PACKAGE__ . " method";
19 package My::Does::Basic2;
20 use Role::Tiny::Restricted;
21 requires 'turbo_charger';
24 return __PACKAGE__ . " method2";
30 use Role::Tiny::Restricted 'with';
37 ok !$@, 'We should be able to use two roles with the same requirements'
42 package My::Does::Basic3;
43 use Role::Tiny::Restricted;
44 with 'My::Does::Basic2';
47 return __PACKAGE__ . " method3";
53 use Role::Tiny::Restricted 'with';
57 sub new { bless {} => shift }
60 ok !$@, 'We should be able to use roles which consume roles'
62 can_ok 'My::Class2', 'method2';
63 is My::Class2->method2, 'My::Does::Basic2 method2',
64 '... and it should be the correct method';
65 can_ok 'My::Class2', 'method3';
66 is My::Class2->method3, 'My::Does::Basic3 method3',
67 '... and it should be the correct method';
69 ok My::Class2->Role::Tiny::does_role('My::Does::Basic3'), 'A class DOES roles which it consumes';
70 ok My::Class2->Role::Tiny::does_role('My::Does::Basic2'),
71 '... and should do roles which its roles consumes';
72 ok !My::Class2->Role::Tiny::does_role('My::Does::Basic1'),
73 '... but not roles which it never consumed';
75 my $object = My::Class2->new;
76 ok $object->Role::Tiny::does_role('My::Does::Basic3'), 'An instance DOES roles which its class consumes';
77 ok $object->Role::Tiny::does_role('My::Does::Basic2'),
78 '... and should do roles which its roles consumes';
79 ok !$object->Role::Tiny::does_role('My::Does::Basic1'),
80 '... but not roles which it never consumed';
84 package Role::Which::Imports;
85 use Role::Tiny::Restricted allow => 'TestMethods';
86 use TestMethods qw(this that);
89 package Class::With::ImportingRole;
90 use Role::Tiny::Restricted 'with';
91 with 'Role::Which::Imports';
92 sub new { bless {} => shift }
94 my $o = Class::With::ImportingRole->new;
96 foreach my $method (qw/this that/) {
98 ok $o->$method($method), '... and calling "allow"ed methods should succeed';
99 is $o->$method, $method, '... and it should function correctly';
105 package Role::WithImportsOnceRemoved;
106 use Role::Tiny::Restricted;
107 with 'Role::Which::Imports';
110 package Class::With::ImportingRole2;
111 use Role::Tiny::Restricted 'with';
113 with 'Role::WithImportsOnceRemoved';
114 sub new { bless {} => shift }
116 ok my $o = Class::With::ImportingRole2->new,
117 'We should be able to use roles which compose roles which import';
119 foreach my $method (qw/this that/) {
121 ok $o->$method($method), '... and calling "allow"ed methods should succeed';
122 is $o->$method, $method, '... and it should function correctly';