1 use lib 'lib', 't/role-basic/lib';
7 package My::Does::Basic1;
9 requires 'turbo_charger';
12 return __PACKAGE__ . " method";
17 package My::Does::Basic2;
19 requires 'turbo_charger';
22 return __PACKAGE__ . " method2";
28 use Role::Tiny 'with';
35 ok !$@, 'We should be able to use two roles with the same requirements'
40 package My::Does::Basic3;
42 with 'My::Does::Basic2';
45 return __PACKAGE__ . " method3";
51 use Role::Tiny 'with';
55 sub new { bless {} => shift }
58 ok !$@, 'We should be able to use roles which consume roles'
60 can_ok 'My::Class2', 'method2';
61 is My::Class2->method2, 'My::Does::Basic2 method2',
62 '... and it should be the correct method';
63 can_ok 'My::Class2', 'method3';
64 is My::Class2->method3, 'My::Does::Basic3 method3',
65 '... and it should be the correct method';
67 ok My::Class2->Role::Tiny::does_role('My::Does::Basic3'), 'A class DOES roles which it consumes';
68 ok My::Class2->Role::Tiny::does_role('My::Does::Basic2'),
69 '... and should do roles which its roles consumes';
70 ok !My::Class2->Role::Tiny::does_role('My::Does::Basic1'),
71 '... but not roles which it never consumed';
73 my $object = My::Class2->new;
74 ok $object->Role::Tiny::does_role('My::Does::Basic3'), 'An instance DOES roles which its class consumes';
75 ok $object->Role::Tiny::does_role('My::Does::Basic2'),
76 '... and should do roles which its roles consumes';
77 ok !$object->Role::Tiny::does_role('My::Does::Basic1'),
78 '... but not roles which it never consumed';
82 package Role::Which::Imports;
83 use Role::Tiny allow => 'TestMethods';
84 use TestMethods qw(this that);
87 package Class::With::ImportingRole;
88 use Role::Tiny 'with';
89 with 'Role::Which::Imports';
90 sub new { bless {} => shift }
92 my $o = Class::With::ImportingRole->new;
94 foreach my $method (qw/this that/) {
96 ok $o->$method($method), '... and calling "allow"ed methods should succeed';
97 is $o->$method, $method, '... and it should function correctly';
103 package Role::WithImportsOnceRemoved;
105 with 'Role::Which::Imports';
108 package Class::With::ImportingRole2;
109 use Role::Tiny 'with';
111 with 'Role::WithImportsOnceRemoved';
112 sub new { bless {} => shift }
114 ok my $o = Class::With::ImportingRole2->new,
115 'We should be able to use roles which compose roles which import';
117 foreach my $method (qw/this that/) {
119 ok $o->$method($method), '... and calling "allow"ed methods should succeed';
120 is $o->$method, $method, '... and it should function correctly';
126 package Method::Role1;
133 package Method::Role2;
138 my $success = eval q{
140 use Role::Tiny::With;
141 with 'Method::Role1', 'Method::Role2';
144 is $success, 1, 'composed mutually dependent methods successfully' or diag "Error: $@";
148 skip "Class::Method::Modifiers not installed or too old", 1
149 unless eval "use Class::Method::Modifiers 1.05; 1";
151 package Modifier::Role1;
155 before 'bar', sub {};
159 package Modifier::Role2;
163 before 'foo', sub {};
165 my $success = eval q{
167 use Role::Tiny::With;
168 with 'Modifier::Role1', 'Modifier::Role2';
171 is $success, 1, 'composed mutually dependent modifiers successfully' or diag "Error: $@";
178 requires qw/method1 method2/;
195 my $success = eval q{
196 package Diamant::Class;
197 use Role::Tiny::With;
198 with qw/Sub::Role1 Sub::Role2/;
201 is $success, 1, 'composed diamantly dependent roles successfully' or diag "Error: $@";