Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 300_immutable / 001_immutable_moose.t
CommitLineData
fc1d8369 1#!/usr/bin/perl
16504b15 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
fc1d8369 5
6use strict;
7use warnings;
8
16504b15 9use Test::More;
fc1d8369 10use Test::Exception;
11
12use Mouse::Meta::Role;
13
14
15{
16 package FooRole;
17 our $VERSION = '0.01';
18 sub foo {'FooRole::foo'}
19}
20
21{
22 package Foo;
23 use Mouse;
24
25 #two checks because the inlined methods are different when
26 #there is a TC present.
27 has 'foos' => ( is => 'ro', lazy_build => 1 );
28 has 'bars' => ( isa => 'Str', is => 'ro', lazy_build => 1 );
29 has 'bazes' => ( isa => 'Str', is => 'ro', builder => '_build_bazes' );
30 sub _build_foos {"many foos"}
31 sub _build_bars {"many bars"}
32 sub _build_bazes {"many bazes"}
33}
34
35{
36 my $foo_role = Mouse::Meta::Role->initialize('FooRole');
37 my $meta = Foo->meta;
38
39 lives_ok { Foo->new } "lazy_build works";
40 is( Foo->new->foos, 'many foos',
41 "correct value for 'foos' before inlining constructor" );
42 is( Foo->new->bars, 'many bars',
43 "correct value for 'bars' before inlining constructor" );
44 is( Foo->new->bazes, 'many bazes',
45 "correct value for 'bazes' before inlining constructor" );
46 lives_ok { $meta->make_immutable } "Foo is imutable";
7ca5c5fb 47 lives_ok { $meta->identifier } "->identifier on metaclass lives";
16504b15 48 #dies_ok { $meta->add_role($foo_role) } "Add Role is locked";
fc1d8369 49 lives_ok { Foo->new } "Inlined constructor works with lazy_build";
50 is( Foo->new->foos, 'many foos',
51 "correct value for 'foos' after inlining constructor" );
52 is( Foo->new->bars, 'many bars',
53 "correct value for 'bars' after inlining constructor" );
54 is( Foo->new->bazes, 'many bazes',
55 "correct value for 'bazes' after inlining constructor" );
16504b15 56 lives_ok { $meta->make_mutable } "Foo is mutable";
57 #lives_ok { $meta->add_role($foo_role) } "Add Role is unlocked";
fc1d8369 58
59}
60
61{
62 package Bar;
63
64 use Mouse;
65
66 sub BUILD { 'bar' }
67}
68
69{
70 package Baz;
71
72 use Mouse;
73
74 extends 'Bar';
75
76 sub BUILD { 'baz' }
77}
78
79lives_ok { Bar->meta->make_immutable }
80 'Immutable meta with single BUILD';
81
82lives_ok { Baz->meta->make_immutable }
83 'Immutable meta with multiple BUILDs';
84
85=pod
86
87Nothing here yet, but soon :)
88
89=cut
16504b15 90
91done_testing;