Commit | Line | Data |
03aac1fa |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7f8a0bbe |
6 | use Test::More tests => 14; |
39b3bc94 |
7 | use Test::Exception; |
8 | |
ac2dc464 |
9 | BEGIN { |
39b3bc94 |
10 | use_ok('Moose'); |
ac2dc464 |
11 | use_ok('Moose::Meta::Role'); |
12 | } |
13 | |
14 | { |
a8878950 |
15 | package FooRole; |
16 | our $VERSION = '0.01'; |
17 | sub foo { 'FooRole::foo' } |
18 | } |
ac2dc464 |
19 | |
20 | { |
21 | package Foo; |
22 | use Moose; |
7a5b07b3 |
23 | |
7f8a0bbe |
24 | #two checks because the inlined methods are different when |
25 | #there is a TC present. |
7a5b07b3 |
26 | has 'foos' => (is => 'ro', lazy_build => 1); |
7f8a0bbe |
27 | has 'bars' => (isa => 'Str', is => 'ro', lazy_build => 1); |
7a5b07b3 |
28 | sub _build_foos{ "many foos" } |
7f8a0bbe |
29 | sub _build_bars{ "many bars" } |
ac2dc464 |
30 | } |
31 | |
32 | { |
33 | my $foo_role = Moose::Meta::Role->initialize('FooRole'); |
34 | my $meta = Foo->meta; |
7a5b07b3 |
35 | |
36 | lives_ok{ Foo->new } "lazy_build works"; |
37 | is(Foo->new->foos, 'many foos' , "correct value for 'foos'"); |
7f8a0bbe |
38 | is(Foo->new->bars, 'many bars' , "correct value for 'bars'"); |
ac2dc464 |
39 | lives_ok{ $meta->make_immutable } "Foo is imutable"; |
40 | dies_ok{ $meta->add_role($foo_role) } "Add Role is locked"; |
7a5b07b3 |
41 | lives_ok{ Foo->new } "Inlined constructor works with lazy_build"; |
42 | is(Foo->new->foos, 'many foos' , "correct value for 'foos'"); |
7f8a0bbe |
43 | is(Foo->new->bars, 'many bars' , "correct value for 'bars'"); |
ac2dc464 |
44 | lives_ok{ $meta->make_mutable } "Foo is mutable"; |
45 | lives_ok{ $meta->add_role($foo_role) } "Add Role is unlocked"; |
7a5b07b3 |
46 | |
47 | |
48 | |
39b3bc94 |
49 | } |
946289d1 |
50 | |
73b84d2e |
51 | { |
52 | package Bar; |
53 | |
54 | use Moose; |
55 | |
56 | sub BUILD { 'bar' } |
57 | } |
58 | |
59 | { |
60 | package Baz; |
61 | |
62 | use Moose; |
63 | |
64 | extends 'Bar'; |
65 | |
66 | sub BUILD { 'baz' } |
67 | } |
68 | |
69 | lives_ok { Bar->meta->make_immutable } |
70 | 'Immutable meta with single BUILD'; |
71 | |
72 | lives_ok { Baz->meta->make_immutable } |
73 | 'Immutable meta with multiple BUILDs'; |
74 | |
946289d1 |
75 | =pod |
76 | |
77 | Nothing here yet, but soon :) |
78 | |
79 | =cut |