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