Properly todoify these role-role tests
[gitmo/MooseX-Role-Parameterized.git] / t / 150-composite-role-application.t
CommitLineData
d41dc048 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
8dc27d7e 5use Test::More tests => 6;
a62f2975 6use Test::Exception;
d41dc048 7
8do {
9 package MyCompositeRoleA;
10 use MooseX::Role::Parameterized;
11
12 parameter attribute => (
13 isa => 'Str',
14 required => 1,
15 );
16
17 role {
18 my $p = shift;
19
20 has $p->attribute => (
21 is => 'Int',
22 );
23 };
24};
25
26do {
27 package MyCompositeRoleB;
28 use MooseX::Role::Parameterized;
29
30 parameter accessor => (
31 isa => 'Str',
32 required => 1,
33 );
34
35 role {
36 my $p = shift;
37
38 has $p->accessor => (
39 is => 'rw',
40 isa => 'Int',
41 );
42 };
43};
44
45do {
46 package MyDoubleConsumer;
47 use Moose;
48 with MyCompositeRoleA => { attribute => 'foo' },
49 MyCompositeRoleB => { accessor => 'bar' };
50};
51
8dc27d7e 52TODO: {
53 local $TODO = "role-role application for parameterized roles doesn't work yet";
d41dc048 54 ok(MyDoubleConsumer->can('foo'), 'first role in composite applied successfully');
55 ok(MyDoubleConsumer->can('bar'), 'second role in composite applied successfully');
8dc27d7e 56};
d41dc048 57
58do {
59 package MyExtendingRole;
60 use MooseX::Role::Parameterized;
61
62 parameter foo => (
63 isa => 'Int',
64 );
65
66 role {
67 my $p = shift;
68
69 with 'MyCompositeRoleA', { attribute => 'bar' };
70
71 has foo => (
72 is => 'rw',
73 default => sub { $p->foo },
74 );
75 };
76};
77
78do {
79 package MyExtendedConsumer;
80 use Moose;
81 with MyCompositeRoleA => { attribute => 'bar' },
82 MyExtendingRole => { foo => 23 };
83};
84
8dc27d7e 85TODO: {
86 local $TODO = "role-role application for parameterized roles doesn't work yet";
d41dc048 87 ok(MyExtendedConsumer->can('bar'), 'role composed through other role applied successfully');
8dc27d7e 88 is(eval { MyExtendedConsumer->new->foo }, 23, 'role composing other role applied successfully');
89};;
d41dc048 90
91do {
92 package MyRoleProxy;
93 use MooseX::Role::Parameterized;
94
95 parameter rolename => (isa => "Str");
96 parameter roleparams => (isa => "HashRef");
97
98 role {
99 my $p = shift;
100
101 with $p->rolename, $p->roleparams;
102 };
103};
104
105do {
106 package MyProxyConsumer;
107 use Moose;
108 with(
109 MyRoleProxy => {
110 rolename => 'MyCompositeRoleA',
111 roleparams => { attribute => 'baz' },
112 },
113 MyCompositeRoleB => {
114 accessor => 'qux',
115 },
116 );
117};
118
8dc27d7e 119TODO: {
120 local $TODO = "role-role application for parameterized roles doesn't work yet";
d41dc048 121 ok(MyProxyConsumer->can('baz'), 'proxied role got applied successfully');
122 ok(MyProxyConsumer->can('qux'), 'other role besides proxied one got applied successfully');
8dc27d7e 123};
d41dc048 124