10 unless ( eval 'use Test::Warn; 1' ) {
11 plan skip_all => 'These tests require Test::Warn';
20 package HasOwnImmutable;
26 ::warning_is( sub { eval q[sub make_immutable { return 'foo' }] },
28 'no warning when defining our own make_immutable sub' );
32 is( HasOwnImmutable->make_immutable(), 'foo',
33 'HasOwnImmutable->make_immutable does not get overwritten' );
37 package MooseX::Empty;
40 Moose::Exporter->build_import_methods( also => 'Moose' );
46 MooseX::Empty->import();
50 ::can_ok( 'WantsMoose', 'has' );
51 ::can_ok( 'WantsMoose', 'with' );
52 ::can_ok( 'WantsMoose', 'foo' );
54 MooseX::Empty->unimport();
58 # Note: it's important that these methods be out of scope _now_,
59 # after unimport was called. We tried a
60 # namespace::clean(0.08)-based solution, but had to abandon it
61 # because it cleans the namespace _later_ (when the file scope
63 ok( ! WantsMoose->can('has'), 'WantsMoose::has() has been cleaned' );
64 ok( ! WantsMoose->can('with'), 'WantsMoose::with() has been cleaned' );
65 can_ok( 'WantsMoose', 'foo' );
67 # This makes sure that Moose->init_meta() happens properly
68 isa_ok( WantsMoose->meta(), 'Moose::Meta::Class' );
69 isa_ok( WantsMoose->new(), 'Moose::Object' );
74 package MooseX::Sugar;
80 return $caller . ' called wrapped1';
83 Moose::Exporter->build_import_methods(
84 with_caller => ['wrapped1'],
92 MooseX::Sugar->import();
96 ::can_ok( 'WantsSugar', 'has' );
97 ::can_ok( 'WantsSugar', 'with' );
98 ::can_ok( 'WantsSugar', 'wrapped1' );
99 ::can_ok( 'WantsSugar', 'foo' );
100 ::is( wrapped1(), 'WantsSugar called wrapped1',
101 'wrapped1 identifies the caller correctly' );
103 MooseX::Sugar->unimport();
107 ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
108 ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
109 ok( ! WantsSugar->can('wrapped1'), 'WantsSugar::wrapped1() has been cleaned' );
110 can_ok( 'WantsSugar', 'foo' );
114 package MooseX::MoreSugar;
120 return $caller . ' called wrapped2';
127 Moose::Exporter->build_import_methods(
128 with_caller => ['wrapped2'],
130 also => 'MooseX::Sugar',
135 package WantsMoreSugar;
137 MooseX::MoreSugar->import();
141 ::can_ok( 'WantsMoreSugar', 'has' );
142 ::can_ok( 'WantsMoreSugar', 'with' );
143 ::can_ok( 'WantsMoreSugar', 'wrapped1' );
144 ::can_ok( 'WantsMoreSugar', 'wrapped2' );
145 ::can_ok( 'WantsMoreSugar', 'as_is1' );
146 ::can_ok( 'WantsMoreSugar', 'foo' );
147 ::is( wrapped1(), 'WantsMoreSugar called wrapped1',
148 'wrapped1 identifies the caller correctly' );
149 ::is( wrapped2(), 'WantsMoreSugar called wrapped2',
150 'wrapped2 identifies the caller correctly' );
151 ::is( as_is1(), 'as_is1',
152 'as_is1 works as expected' );
154 MooseX::MoreSugar->unimport();
158 ok( ! WantsMoreSugar->can('has'), 'WantsMoreSugar::has() has been cleaned' );
159 ok( ! WantsMoreSugar->can('with'), 'WantsMoreSugar::with() has been cleaned' );
160 ok( ! WantsMoreSugar->can('wrapped1'), 'WantsMoreSugar::wrapped1() has been cleaned' );
161 ok( ! WantsMoreSugar->can('wrapped2'), 'WantsMoreSugar::wrapped2() has been cleaned' );
162 ok( ! WantsMoreSugar->can('as_is1'), 'WantsMoreSugar::as_is1() has been cleaned' );
163 can_ok( 'WantsMoreSugar', 'foo' );
167 package My::Metaclass;
169 BEGIN { extends 'Moose::Meta::Class' }
173 BEGIN { extends 'Moose::Object' }
181 return Moose->init_meta( @_,
182 metaclass => 'My::Metaclass',
183 base_class => 'My::Object',
187 Moose::Exporter->build_import_methods( also => 'Moose' );
193 HasInitMeta->import();
197 isa_ok( NewMeta->meta(), 'My::Metaclass' );
198 isa_ok( NewMeta->new(), 'My::Object' );
202 package MooseX::CircularAlso;
208 Moose::Exporter->build_import_methods(
209 also => [ 'Moose', 'MooseX::CircularAlso' ],
212 'a circular reference in also dies with an error'
217 qr/\QCircular reference in also parameter to MooseX::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/,
218 'got the expected error from circular reference in also'
223 package MooseX::CircularAlso;
229 Moose::Exporter->build_import_methods(
230 also => [ 'NoSuchThing' ],
233 'a package which does not use Moose::Exporter in also dies with an error'
238 qr/\QPackage in also (NoSuchThing) does not seem to use MooseX::Exporter/,
239 'got the expected error from a reference in also to a package which does not use Moose::Exporter'