Tidy
[gitmo/Mouse.git] / t / 300_immutable / 001_immutable_moose.t
CommitLineData
fc1d8369 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 15;
7use Test::Exception;
8
9use Mouse::Meta::Role;
10
11
12{
13 package FooRole;
14 our $VERSION = '0.01';
15 sub foo {'FooRole::foo'}
16}
17
18{
19 package Foo;
20 use Mouse;
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"}
30}
31
32{
33 my $foo_role = Mouse::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";
7ca5c5fb 44
45 lives_ok { $meta->identifier } "->identifier on metaclass lives";
46 dies_ok { $meta->add_role($foo_role) } "Add Role is locked";
47
fc1d8369 48 lives_ok { Foo->new } "Inlined constructor works with lazy_build";
49 is( Foo->new->foos, 'many foos',
50 "correct value for 'foos' after inlining constructor" );
51 is( Foo->new->bars, 'many bars',
52 "correct value for 'bars' after inlining constructor" );
53 is( Foo->new->bazes, 'many bazes',
54 "correct value for 'bazes' after inlining constructor" );
55 SKIP: {
56 skip "Mouse doesn't supports make_mutable", 2;
57 lives_ok { $meta->make_mutable } "Foo is mutable";
58 lives_ok { $meta->add_role($foo_role) } "Add Role is unlocked";
59 };
60
61}
62
63{
64 package Bar;
65
66 use Mouse;
67
68 sub BUILD { 'bar' }
69}
70
71{
72 package Baz;
73
74 use Mouse;
75
76 extends 'Bar';
77
78 sub BUILD { 'baz' }
79}
80
81lives_ok { Bar->meta->make_immutable }
82 'Immutable meta with single BUILD';
83
84lives_ok { Baz->meta->make_immutable }
85 'Immutable meta with multiple BUILDs';
86
87=pod
88
89Nothing here yet, but soon :)
90
91=cut