release
[gitmo/MooseX-Types.git] / t / 21_coerce_parameterized_types.t
index dbbd5d2..31e4c8c 100644 (file)
@@ -7,32 +7,40 @@ use Test::More tests => 2;
 
 BEGIN {
     package TypeLib;
-    use MooseX::Types -declare => [qw/MyType ArrayRefOfMyType/];
-    use MooseX::Types::Moose qw/ArrayRef Str/;
+    use MooseX::Types -declare => [qw/
+       MyChar MyDigit ArrayRefOfMyCharOrDigit
+    /];
+    use MooseX::Types::Moose qw/ArrayRef Str Int/;
 
-    subtype MyType, as Str, where {
+    subtype MyChar, as Str, where {
        length == 1
     };
 
-    coerce ArrayRef[MyType], from Str, via {
+    subtype MyDigit, as Int, where {
+       length == 1
+    };
+
+    coerce ArrayRef[MyChar|MyDigit], from Str, via {
        [split //]
     };
 
 # same thing with an explicit subtype
-    subtype ArrayRefOfMyType, as ArrayRef[MyType];
+    subtype ArrayRefOfMyCharOrDigit, as ArrayRef[MyChar|MyDigit];
 
-    coerce ArrayRefOfMyType, from Str, via {
+    coerce ArrayRefOfMyCharOrDigit, from Str, via {
        [split //]
     };
 }
 {
     package AClass;
     use Moose;
-    BEGIN { TypeLib->import(qw/MyType ArrayRefOfMyType/) };
+    BEGIN { TypeLib->import(qw/
+       MyChar MyDigit ArrayRefOfMyCharOrDigit/
+    ) };
     use MooseX::Types::Moose 'ArrayRef';
 
-    has parameterized => (is => 'rw', isa => ArrayRef[MyType], coerce => 1);
-    has subtype => (is => 'rw', isa => ArrayRefOfMyType, coerce => 1);
+    has parameterized => (is => 'rw', isa => ArrayRef[MyChar|MyDigit], coerce => 1);
+    has subtype_parameterized => (is => 'rw', isa => ArrayRefOfMyCharOrDigit, coerce => 1);
 }
 
 my $instance = AClass->new;
@@ -40,4 +48,5 @@ my $instance = AClass->new;
 lives_ok { $instance->parameterized('foo') }
     'coercion applied to parameterized type';
 
-lives_ok { $instance->subtype('foo') } 'coercion applied to subtype';
+lives_ok { $instance->subtype_parameterized('foo') }
+    'coercion applied to subtype';