Commit | Line | Data |
308e04fa |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
3d659f7f |
6 | use Test::More; |
4d438a84 |
7 | |
8 | use Test::Requires { |
9 | 'Test::Output' => '0.01', # skip all if not installed |
10 | }; |
308e04fa |
11 | |
12 | { |
13 | package NotMoose; |
14 | |
15 | sub new { |
16 | my $class = shift; |
17 | |
18 | return bless { not_moose => 1 }, $class; |
19 | } |
20 | } |
21 | |
22 | { |
23 | package Foo; |
24 | use Moose; |
25 | |
26 | extends 'NotMoose'; |
27 | |
6c3d0d07 |
28 | ::stderr_like( |
308e04fa |
29 | sub { Foo->meta->make_immutable }, |
6c3d0d07 |
30 | 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 |
31 | 'got a warning that Foo may not have an inlined constructor' |
32 | ); |
33 | } |
34 | |
35 | is( |
36 | Foo->meta->find_method_by_name('new')->body, |
37 | NotMoose->can('new'), |
38 | 'Foo->new is inherited from NotMoose' |
39 | ); |
40 | |
41 | { |
42 | package Bar; |
43 | use Moose; |
44 | |
45 | extends 'NotMoose'; |
46 | |
47 | ::stderr_is( |
2cb19e35 |
48 | sub { Bar->meta->make_immutable( replace_constructor => 1 ) }, |
308e04fa |
49 | q{}, |
50 | 'no warning when replace_constructor is true' |
51 | ); |
52 | } |
53 | |
2cb19e35 |
54 | is( |
55 | Bar->meta->find_method_by_name('new')->package_name, |
56 | 'Bar', |
57 | 'Bar->new is inlined, and not inherited from NotMoose' |
308e04fa |
58 | ); |
12875d6e |
59 | |
60 | { |
61 | package Baz; |
62 | use Moose; |
63 | |
64 | Baz->meta->make_immutable; |
65 | } |
66 | |
67 | { |
68 | package Quux; |
69 | use Moose; |
70 | |
71 | extends 'Baz'; |
72 | |
73 | ::stderr_is( |
74 | sub { Quux->meta->make_immutable }, |
75 | q{}, |
76 | 'no warning when inheriting from a class that has already made itself immutable' |
77 | ); |
78 | } |
db058da6 |
79 | |
80 | { |
81 | package My::Constructor; |
82 | use base 'Moose::Meta::Method::Constructor'; |
83 | } |
84 | |
85 | { |
86 | package CustomCons; |
87 | use Moose; |
88 | |
89 | CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' ); |
90 | } |
91 | |
92 | { |
93 | package Subclass; |
94 | use Moose; |
95 | |
96 | extends 'CustomCons'; |
97 | |
98 | ::stderr_is( |
99 | sub { Subclass->meta->make_immutable }, |
e4c7477b |
100 | q{}, |
db058da6 |
101 | 'no warning when inheriting from a class that has already made itself immutable' |
102 | ); |
103 | } |
a28e50e4 |
104 | |
105 | done_testing; |