Commit | Line | Data |
b2a6a381 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | |
5 | BEGIN { |
6 | package MyTypes; |
7 | |
8 | use MooseX::Types -declare => [ 'ClassyType' ]; |
9 | |
cabfc8ed |
10 | class_type 'ClassyClass'; |
11 | |
12 | subtype ClassyType, as 'ClassyClass'; |
13 | |
14 | #class_type ClassyType, { class => 'ClassyClass' }; |
b2a6a381 |
15 | } |
16 | |
17 | BEGIN { |
18 | |
19 | package ClassyClass; |
20 | |
21 | use Moose; |
22 | |
23 | package ClassyClassConsumer; |
24 | |
25 | BEGIN { MyTypes->import('ClassyType') } |
26 | use Moose; |
27 | |
28 | has om_nom => ( |
29 | is => 'ro', isa => ClassyType, default => sub { ClassyType->new } |
30 | ); |
31 | |
32 | } |
33 | |
34 | ok(my $o = ClassyClassConsumer->new, "Constructor happy"); |
35 | |
36 | is(ref($o->om_nom), 'ClassyClass', 'Attribute happy'); |
37 | |
195d6241 |
38 | ok(ClassyClassConsumer->new(om_nom => ClassyClass->new), 'Constructor happy'); |
39 | |
cabfc8ed |
40 | ok(!eval { ClassyClassConsumer->new(om_nom => 3) }, 'Type checked'); |
41 | |
b2a6a381 |
42 | done_testing; |