Shut up deprecation warnings
[gitmo/MooseX-Types.git] / t / 21_coerce_parameterized_types.t
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;
10     use MooseX::Types -declare => [qw/
11         MyChar MyDigit ArrayRefOfMyCharOrDigit
12     /];
13     use MooseX::Types::Moose qw/ArrayRef Str Int/;
14
15     subtype MyChar, as Str, where {
16         length == 1
17     };
18
19     subtype MyDigit, as Int, where {
20         length == 1
21     };
22
23     coerce ArrayRef[MyChar|MyDigit], from Str, via {
24         [split //]
25     };
26
27 # same thing with an explicit subtype
28     subtype ArrayRefOfMyCharOrDigit, as ArrayRef[MyChar|MyDigit];
29
30     coerce ArrayRefOfMyCharOrDigit, from Str, via {
31         [split //]
32     };
33 }
34 {
35     package AClass;
36     use Moose;
37     BEGIN { TypeLib->import(qw/
38         MyChar MyDigit ArrayRefOfMyCharOrDigit/
39     ) };
40     use MooseX::Types::Moose 'ArrayRef';
41
42     local *Moose::Deprecated::deprecated = sub { };
43     has parameterized => (is => 'rw', isa => ArrayRef[MyChar|MyDigit], coerce => 1);
44     has subtype_parameterized => (is => 'rw', isa => ArrayRefOfMyCharOrDigit, coerce => 1);
45 }
46
47 my $instance = AClass->new;
48
49 { local $TODO = "see comments in MooseX::Types->create_arged_...";
50 lives_ok { $instance->parameterized('foo') }
51     'coercion applied to parameterized type';
52 }
53
54 lives_ok { $instance->subtype_parameterized('foo') }
55     'coercion applied to subtype';