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 | |
13005566 |
8 | unless (eval { require MooseX::Role::Parameterized }) { |
9 | plan skip_all => 'This test needs MooseX::Role::Parameterized'; |
a193e05d |
10 | } |
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 | |
a193e05d |
38 | package Foo; |
39 | use Moose; |
40 | with 'Role'; |
13005566 |
41 | EOF |
42 | |
43 | if ($@) { |
44 | plan skip_all => |
45 | 'MooseX::ClassAttribute is currently incompatible with MooseX::Role::Parameterized'; |
a193e05d |
46 | } |
47 | |
13005566 |
48 | plan tests => 8; |
49 | |
50 | eval 'use Test::NoWarnings'; |
a193e05d |
51 | |
52 | ok( (my $instance = MyClass->new), 'instance' ); |
53 | |
0a64dac6 |
54 | { |
55 | local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support'; |
56 | |
57 | lives_ok { $instance->foo('bar') } 'attribute coercion ran'; |
58 | } |
a193e05d |
59 | |
60 | lives_ok { $instance->bar('baz') } 'class attribute coercion ran'; |
61 | |
62 | dies_ok { $instance->baz('quux') } |
63 | 'class attribute coercion did not run with coerce => 0'; |
64 | |
65 | dies_ok { $instance->quux('mtfnpy') } |
66 | 'attribute coercion did not run with coerce => 0'; |
67 | |
68 | lives_ok { $instance->uncoerced_attr(10) } |
69 | 'set attribute having type with no coercion and no coerce=0'; |
70 | |
71 | lives_ok { $instance->uncoerced_class_attr(10) } |
72 | 'set class attribute having type with no coercion and no coerce=0'; |