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