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; |
10 | use MooseX::Types -declare => [qw/MyType ArrayRefOfMyType/]; |
11 | use MooseX::Types::Moose qw/ArrayRef Str/; |
12 | |
13 | subtype MyType, as Str, where { |
14 | length == 1 |
15 | }; |
16 | |
17 | coerce ArrayRef[MyType], from Str, via { |
18 | [split //] |
19 | }; |
20 | |
21 | # same thing with an explicit subtype |
22 | subtype ArrayRefOfMyType, as ArrayRef[MyType]; |
23 | |
24 | coerce ArrayRefOfMyType, from Str, via { |
25 | [split //] |
26 | }; |
27 | } |
28 | { |
29 | package AClass; |
30 | use Moose; |
31 | BEGIN { TypeLib->import(qw/MyType ArrayRefOfMyType/) }; |
32 | use MooseX::Types::Moose 'ArrayRef'; |
33 | |
34 | has parameterized => (is => 'rw', isa => ArrayRef[MyType], coerce => 1); |
35 | has subtype => (is => 'rw', isa => ArrayRefOfMyType, coerce => 1); |
36 | } |
37 | |
38 | my $instance = AClass->new; |
39 | |
40 | lives_ok { $instance->parameterized('foo') } |
41 | 'coercion applied to parameterized type'; |
42 | |
43 | lives_ok { $instance->subtype('foo') } 'coercion applied to subtype'; |