Commit | Line | Data |
1a52f2db |
1 | #!perl |
2 | use strict; |
3 | use warnings FATAL => 'all'; |
4 | use Test::More |
5 | eval { require Moose; require MooseX::Types } |
6 | ? (tests => 4) |
7 | : (skip_all => "Moose, MooseX::Types required for testing types") |
8 | ; |
9 | use Test::Fatal; |
10 | |
11 | { |
12 | package MyTypes; |
13 | use MooseX::Types::Moose qw/Str/; |
14 | use Moose::Util::TypeConstraints; |
15 | use MooseX::Types -declare => [qw/CustomType/]; |
16 | |
17 | BEGIN { |
18 | subtype CustomType, |
19 | as Str, |
20 | where { length($_) == 2 }; |
21 | } |
22 | } |
23 | |
24 | { |
25 | package TestClass; |
26 | use Function::Parameters qw(:strict); |
27 | BEGIN { MyTypes->import('CustomType') }; |
28 | use MooseX::Types::Moose qw/ArrayRef/; |
29 | #use namespace::clean; |
30 | |
31 | method foo ((CustomType) $bar) { } |
32 | |
33 | method bar ((ArrayRef[CustomType]) $baz) { } |
34 | } |
35 | |
36 | my $o = bless {} => 'TestClass'; |
37 | |
38 | is(exception { $o->foo('42') }, undef); |
39 | ok(exception { $o->foo('bar') }); |
40 | |
41 | is(exception { $o->bar(['42', '23']) }, undef); |
42 | ok(exception { $o->bar(['foo', 'bar']) }); |