Commit | Line | Data |
a193e05d |
1 | #!/usr/bin/env perl |
13005566 |
2 | |
a193e05d |
3 | use strict; |
4 | use warnings; |
a193e05d |
5 | use Test::More; |
13005566 |
6 | use Test::Exception; |
a193e05d |
7 | |
73760f48 |
8 | use Test::Requires { |
9 | 'MooseX::Role::Parameterized' => 0.01, |
10 | }; |
a193e05d |
11 | |
13005566 |
12 | eval <<'EOF'; |
a193e05d |
13 | package Role; |
14 | use MooseX::Role::Parameterized; |
15 | use MooseX::AlwaysCoerce; |
16 | use Moose::Util::TypeConstraints; |
17 | |
18 | # I do nothing! |
19 | role {}; |
a193e05d |
20 | |
21 | subtype 'MyType', as 'Int'; |
22 | coerce 'MyType', from 'Str', via { length $_ }; |
23 | |
24 | subtype 'Uncoerced', as 'Int'; |
25 | |
26 | has foo => (is => 'rw', isa => 'MyType'); |
27 | |
28 | class_has bar => (is => 'rw', isa => 'MyType'); |
29 | |
30 | class_has baz => (is => 'rw', isa => 'MyType', coerce => 0); |
31 | |
32 | has quux => (is => 'rw', isa => 'MyType', coerce => 0); |
33 | |
34 | has uncoerced_attr => (is => 'rw', isa => 'Uncoerced'); |
35 | |
36 | class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced'); |
a193e05d |
37 | |
bb7cca58 |
38 | has untyped_attr => (is => 'rw'); |
39 | |
40 | class_has untyped_class_attr => (is => 'rw'); |
41 | |
a193e05d |
42 | package Foo; |
43 | use Moose; |
44 | with 'Role'; |
13005566 |
45 | EOF |
46 | |
47 | if ($@) { |
48 | plan skip_all => |
49 | 'MooseX::ClassAttribute is currently incompatible with MooseX::Role::Parameterized'; |
a193e05d |
50 | } |
51 | |
bb7cca58 |
52 | plan tests => 10; |
13005566 |
53 | |
54 | eval 'use Test::NoWarnings'; |
a193e05d |
55 | |
56 | ok( (my $instance = MyClass->new), 'instance' ); |
57 | |
0a64dac6 |
58 | { |
59 | local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support'; |
60 | |
bb7cca58 |
61 | lives_and { |
62 | $instance->foo('bar'); |
63 | is $instance->foo, 3; |
64 | } 'attribute coercion ran'; |
0a64dac6 |
65 | } |
a193e05d |
66 | |
bb7cca58 |
67 | lives_and { |
68 | $instance->bar('baz'); |
69 | is $instance->bar, 3; |
70 | } 'class attribute coercion ran'; |
a193e05d |
71 | |
72 | dies_ok { $instance->baz('quux') } |
73 | 'class attribute coercion did not run with coerce => 0'; |
74 | |
75 | dies_ok { $instance->quux('mtfnpy') } |
76 | 'attribute coercion did not run with coerce => 0'; |
77 | |
bb7cca58 |
78 | lives_and { |
79 | $instance->uncoerced_attr(10); |
80 | is $instance->uncoerced_attr(10), 10; |
81 | } 'set attribute having type with no coercion and no coerce=0'; |
82 | |
83 | lives_and { |
84 | $instance->uncoerced_class_attr(10); |
85 | is $instance->uncoerced_class_attr(10), 10; |
86 | } 'set class attribute having type with no coercion and no coerce=0'; |
87 | |
88 | lives_and { |
89 | $instance->untyped_attr(10); |
90 | is $instance->untyped_attr, 10; |
91 | } 'set untyped attribute'; |
92 | |
93 | lives_and { |
94 | $instance->untyped_class_attr(10); |
95 | is $instance->untyped_class_attr, 10; |
96 | } 'set untyped class attribute'; |