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