Commit | Line | Data |
6cfbfdbc |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::Exception; |
5 | |
6 | use Test::More tests => 2; |
7 | |
8 | BEGIN { |
9 | package TypeLib; |
86a2a6b8 |
10 | use MooseX::Types -declare => [qw/ |
11 | MyChar MyDigit ArrayRefOfMyCharOrDigit |
12 | /]; |
d46ddd3c |
13 | use MooseX::Types::Moose qw/ArrayRef Str Int/; |
6cfbfdbc |
14 | |
d46ddd3c |
15 | subtype MyChar, as Str, where { |
6cfbfdbc |
16 | length == 1 |
17 | }; |
18 | |
d46ddd3c |
19 | subtype MyDigit, as Int, where { |
20 | length == 1 |
21 | }; |
22 | |
23 | coerce ArrayRef[MyChar|MyDigit], from Str, via { |
6cfbfdbc |
24 | [split //] |
25 | }; |
26 | |
27 | # same thing with an explicit subtype |
d46ddd3c |
28 | subtype ArrayRefOfMyCharOrDigit, as ArrayRef[MyChar|MyDigit]; |
6cfbfdbc |
29 | |
d46ddd3c |
30 | coerce ArrayRefOfMyCharOrDigit, from Str, via { |
6cfbfdbc |
31 | [split //] |
32 | }; |
33 | } |
9f6c7824 |
34 | |
6cfbfdbc |
35 | { |
86a2a6b8 |
36 | BEGIN { TypeLib->import(qw/ |
37 | MyChar MyDigit ArrayRefOfMyCharOrDigit/ |
38 | ) }; |
6cfbfdbc |
39 | use MooseX::Types::Moose 'ArrayRef'; |
40 | |
9f6c7824 |
41 | my $parameterized = ArrayRef[MyChar|MyDigit]; |
42 | { local $::TODO = "see comments in MooseX::Types->create_arged_..."; |
43 | ::ok( $parameterized->has_coercion, 'coercion applied to parameterized type' ); |
44 | } |
6cfbfdbc |
45 | |
9f6c7824 |
46 | my $subtype = ArrayRefOfMyCharOrDigit; |
47 | ::ok( $subtype->has_coercion, 'coercion applied to subtype' ); |
64f42303 |
48 | } |
6cfbfdbc |
49 | |