Commit | Line | Data |
03aac1fa |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
0f33d97f |
6 | use Test::More tests => 17; |
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); |
ca168e89 |
28 | has 'bazes' => (isa => 'Str', is => 'ro', builder => '_build_bazes'); |
29 | sub _build_foos { "many foos" } |
30 | sub _build_bars { "many bars" } |
31 | sub _build_bazes { "many bazes" } |
ac2dc464 |
32 | } |
33 | |
34 | { |
35 | my $foo_role = Moose::Meta::Role->initialize('FooRole'); |
36 | my $meta = Foo->meta; |
7a5b07b3 |
37 | |
38 | lives_ok{ Foo->new } "lazy_build works"; |
ca168e89 |
39 | is(Foo->new->foos, 'many foos' , "correct value for 'foos' before inlining constructor"); |
40 | is(Foo->new->bars, 'many bars' , "correct value for 'bars' before inlining constructor"); |
41 | is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' before inlining constructor"); |
ac2dc464 |
42 | lives_ok{ $meta->make_immutable } "Foo is imutable"; |
0f33d97f |
43 | lives_ok{ $meta->identifier } "->identifier on metaclass lives"; |
ac2dc464 |
44 | dies_ok{ $meta->add_role($foo_role) } "Add Role is locked"; |
7a5b07b3 |
45 | lives_ok{ Foo->new } "Inlined constructor works with lazy_build"; |
ca168e89 |
46 | is(Foo->new->foos, 'many foos' , "correct value for 'foos' after inlining constructor"); |
47 | is(Foo->new->bars, 'many bars' , "correct value for 'bars' after inlining constructor"); |
48 | is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' after inlining constructor"); |
ac2dc464 |
49 | lives_ok{ $meta->make_mutable } "Foo is mutable"; |
50 | lives_ok{ $meta->add_role($foo_role) } "Add Role is unlocked"; |
7a5b07b3 |
51 | |
52 | |
39b3bc94 |
53 | } |
946289d1 |
54 | |
73b84d2e |
55 | { |
56 | package Bar; |
57 | |
58 | use Moose; |
59 | |
60 | sub BUILD { 'bar' } |
61 | } |
62 | |
63 | { |
64 | package Baz; |
65 | |
66 | use Moose; |
67 | |
68 | extends 'Bar'; |
69 | |
70 | sub BUILD { 'baz' } |
71 | } |
72 | |
73 | lives_ok { Bar->meta->make_immutable } |
74 | 'Immutable meta with single BUILD'; |
75 | |
76 | lives_ok { Baz->meta->make_immutable } |
77 | 'Immutable meta with multiple BUILDs'; |
78 | |
946289d1 |
79 | =pod |
80 | |
81 | Nothing here yet, but soon :) |
82 | |
83 | =cut |