allow inlining if the type has been subsequently defined
[gitmo/MooseX-Types.git] / t / 21_coerce_parameterized_types.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Test::More;
6
7 BEGIN {
8     package TypeLib;
9     use MooseX::Types -declare => [qw/
10         MyChar MyDigit ArrayRefOfMyCharOrDigit
11     /];
12     use MooseX::Types::Moose qw/ArrayRef Str Int/;
13
14     subtype MyChar, as Str, where {
15         length == 1
16     };
17
18     subtype MyDigit, as Int, where {
19         length == 1
20     };
21
22     coerce ArrayRef[MyChar|MyDigit], from Str, via {
23         [split //]
24     };
25
26 # same thing with an explicit subtype
27     subtype ArrayRefOfMyCharOrDigit, as ArrayRef[MyChar|MyDigit];
28
29     coerce ArrayRefOfMyCharOrDigit, from Str, via {
30         [split //]
31     };
32 }
33
34 {
35     BEGIN { TypeLib->import(qw/
36         MyChar MyDigit ArrayRefOfMyCharOrDigit/
37     ) };
38     use MooseX::Types::Moose 'ArrayRef';
39
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     }
44
45     my $subtype = ArrayRefOfMyCharOrDigit;
46     ::ok( $subtype->has_coercion, 'coercion applied to subtype' );
47 }
48
49 done_testing();