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