b81f64b5196a0443e1796a1987832c04f785e0ef
[gitmo/Moose.git] / t / 037_attribute_type_unions.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');           
11 }
12
13 {
14     package Foo;
15     use strict;
16     use warnings;
17     use Moose;
18     
19     has 'bar' => (is => 'rw', isa => 'ArrayRef | HashRef');
20 }
21
22 my $foo = Foo->new;
23 isa_ok($foo, 'Foo');
24
25 lives_ok {
26     $foo->bar([])
27 } '... set bar successfully with an ARRAY ref';
28
29 lives_ok {
30     $foo->bar({})
31 } '... set bar successfully with a HASH ref';
32
33 dies_ok {
34     $foo->bar(100)
35 } '... couldnt set bar successfully with a number';
36
37 dies_ok {
38     $foo->bar(sub {})
39 } '... couldnt set bar successfully with a CODE ref';
40
41 # check the constructor
42
43 lives_ok {
44     Foo->new(bar => [])
45 } '... created new Foo with bar successfully set with an ARRAY ref';
46
47 lives_ok {
48     Foo->new(bar => {})
49 } '... created new Foo with bar successfully set with a HASH ref';
50
51 dies_ok {
52     Foo->new(bar => 50)
53 } '... didnt create a new Foo with bar as a number';
54
55 dies_ok {
56     Foo->new(bar => sub {})
57 } '... didnt create a new Foo with bar as a number';
58
59