Commit | Line | Data |
bbd2fe69 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
ab859145 |
6 | use Test::More tests => 16; |
bbd2fe69 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
1ed0b94f |
10 | use_ok('Moose'); |
bbd2fe69 |
11 | } |
12 | |
13 | { |
14 | package Foo; |
bbd2fe69 |
15 | use Moose; |
1ed0b94f |
16 | |
bbd2fe69 |
17 | has 'bar' => (is => 'ro', required => 1); |
1ed0b94f |
18 | has 'baz' => (is => 'rw', default => 100, required => 1); |
19 | has 'boo' => (is => 'rw', lazy => 1, default => 50, required => 1); |
bbd2fe69 |
20 | } |
21 | |
22 | { |
23 | my $foo = Foo->new(bar => 10, baz => 20, boo => 100); |
24 | isa_ok($foo, 'Foo'); |
1ed0b94f |
25 | |
bbd2fe69 |
26 | is($foo->bar, 10, '... got the right bar'); |
1ed0b94f |
27 | is($foo->baz, 20, '... got the right baz'); |
28 | is($foo->boo, 100, '... got the right boo'); |
bbd2fe69 |
29 | } |
30 | |
31 | { |
32 | my $foo = Foo->new(bar => 10, boo => 5); |
33 | isa_ok($foo, 'Foo'); |
1ed0b94f |
34 | |
bbd2fe69 |
35 | is($foo->bar, 10, '... got the right bar'); |
1ed0b94f |
36 | is($foo->baz, 100, '... got the right baz'); |
37 | is($foo->boo, 5, '... got the right boo'); |
bbd2fe69 |
38 | } |
39 | |
40 | { |
41 | my $foo = Foo->new(bar => 10); |
42 | isa_ok($foo, 'Foo'); |
1ed0b94f |
43 | |
bbd2fe69 |
44 | is($foo->bar, 10, '... got the right bar'); |
1ed0b94f |
45 | is($foo->baz, 100, '... got the right baz'); |
46 | is($foo->boo, 50, '... got the right boo'); |
bbd2fe69 |
47 | } |
48 | |
1ed0b94f |
49 | #Yeah.. this doesn't work like this anymore, see below. (groditi) |
50 | #throws_ok { |
51 | # Foo->new(bar => 10, baz => undef); |
52 | #} qr/^Attribute \(baz\) is required and cannot be undef/, '... must supply all the required attribute'; |
53 | |
54 | #throws_ok { |
55 | # Foo->new(bar => 10, boo => undef); |
56 | #} qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute'; |
57 | |
58 | lives_ok { |
ab859145 |
59 | Foo->new(bar => 10, baz => undef); |
1ed0b94f |
60 | } '... undef is a valid attribute value'; |
ab859145 |
61 | |
1ed0b94f |
62 | lives_ok { |
ab859145 |
63 | Foo->new(bar => 10, boo => undef); |
1ed0b94f |
64 | } '... undef is a valid attribute value'; |
65 | |
ab859145 |
66 | |
67 | throws_ok { |
bbd2fe69 |
68 | Foo->new; |
69 | } qr/^Attribute \(bar\) is required/, '... must supply all the required attribute'; |
70 | |