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