inlined constructor correction for lazy_build and new test
[gitmo/Moose.git] / t / 300_immutable / 001_immutable_moose.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');
11     use_ok('Moose::Meta::Role');
12 }
13
14 {
15   package FooRole;
16   our $VERSION = '0.01';
17   sub foo { 'FooRole::foo' }
18 }
19
20 {
21   package Foo;
22   use Moose;
23
24   has 'foos' => (is => 'ro', lazy_build => 1);
25   sub _build_foos{ "many foos" }
26
27 }
28
29 {
30   my $foo_role = Moose::Meta::Role->initialize('FooRole');
31   my $meta = Foo->meta;
32
33   lives_ok{ Foo->new                    } "lazy_build works";
34   is(Foo->new->foos, 'many foos'        , "correct value for 'foos'");
35   lives_ok{ $meta->make_immutable       } "Foo is imutable";
36   dies_ok{  $meta->add_role($foo_role)  } "Add Role is locked";
37   lives_ok{ Foo->new                    } "Inlined constructor works with lazy_build";
38   is(Foo->new->foos, 'many foos'        , "correct value for 'foos'");
39   lives_ok{ $meta->make_mutable         } "Foo is mutable";
40   lives_ok{ $meta->add_role($foo_role)  } "Add Role is unlocked";
41
42
43
44 }
45
46 {
47   package Bar;
48
49   use Moose;
50
51   sub BUILD { 'bar' }
52 }
53
54 {
55   package Baz;
56
57   use Moose;
58
59   extends 'Bar';
60
61   sub BUILD { 'baz' }
62 }
63
64 lives_ok { Bar->meta->make_immutable }
65   'Immutable meta with single BUILD';
66
67 lives_ok { Baz->meta->make_immutable }
68   'Immutable meta with multiple BUILDs';
69
70 =pod
71
72 Nothing here yet, but soon :)
73
74 =cut