bf2bfb45e32ad0e5c4c3404a53429d3d085b1bbf
[gitmo/Moose.git] / t / 300_immutable / 010_constructor_is_not_moose.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::Output;
8
9 {
10     package NotMoose;
11
12     sub new {
13         my $class = shift;
14
15         return bless { not_moose => 1 }, $class;
16     }
17 }
18
19 {
20     package Foo;
21     use Moose;
22
23     extends 'NotMoose';
24
25     ::stderr_is(
26         sub { Foo->meta->make_immutable },
27         "Not inlining 'new' for Foo since it is not inheriting the default Moose::Object::new\nIf you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to Foo->meta->make_immutable\n",
28         'got a warning that Foo may not have an inlined constructor'
29     );
30 }
31
32 is(
33     Foo->meta->find_method_by_name('new')->body,
34     NotMoose->can('new'),
35     'Foo->new is inherited from NotMoose'
36 );
37
38 {
39     package Bar;
40     use Moose;
41
42     extends 'NotMoose';
43
44     ::stderr_is(
45         sub { Bar->meta->make_immutable( replace_constructor => 1 ) },
46         q{},
47         'no warning when replace_constructor is true'
48     );
49 }
50
51 is(
52     Bar->meta->find_method_by_name('new')->package_name,
53    'Bar',
54     'Bar->new is inlined, and not inherited from NotMoose'
55 );
56
57 {
58     package Baz;
59     use Moose;
60
61     Baz->meta->make_immutable;
62 }
63
64 {
65     package Quux;
66     use Moose;
67
68     extends 'Baz';
69
70     ::stderr_is(
71         sub { Quux->meta->make_immutable },
72         q{},
73         'no warning when inheriting from a class that has already made itself immutable'
74     );
75 }
76
77 {
78     package My::Constructor;
79     use base 'Moose::Meta::Method::Constructor';
80 }
81
82 {
83     package CustomCons;
84     use Moose;
85
86     CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' );
87 }
88
89 {
90     package Subclass;
91     use Moose;
92
93     extends 'CustomCons';
94
95     ::stderr_is(
96         sub { Subclass->meta->make_immutable },
97         q{},
98         'no warning when inheriting from a class that has already made itself immutable'
99     );
100 }