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;
10 $TODO = q{Mouse is not yet completed};
14 'Test::Output' => '0.01', # skip all if not installed
18 package HasOwnImmutable;
24 ::stderr_is( sub { eval q[sub make_immutable { return 'foo' }] },
26 'no warning when defining our own make_immutable sub' );
30 is( HasOwnImmutable->make_immutable(), 'foo',
31 'HasOwnImmutable->make_immutable does not get overwritten' );
35 package MouseX::Empty;
38 Mouse::Exporter->setup_import_methods( also => 'Mouse' );
44 MouseX::Empty->import();
48 ::can_ok( 'WantsMouse', 'has' );
49 ::can_ok( 'WantsMouse', 'with' );
50 ::can_ok( 'WantsMouse', 'foo' );
52 MouseX::Empty->unimport();
56 # Note: it's important that these methods be out of scope _now_,
57 # after unimport was called. We tried a
58 # namespace::clean(0.08)-based solution, but had to abandon it
59 # because it cleans the namespace _later_ (when the file scope
61 ok( ! WantsMouse->can('has'), 'WantsMouse::has() has been cleaned' );
62 ok( ! WantsMouse->can('with'), 'WantsMouse::with() has been cleaned' );
63 can_ok( 'WantsMouse', 'foo' );
65 # This makes sure that Mouse->init_meta() happens properly
66 isa_ok( WantsMouse->meta(), 'Mouse::Meta::Class' );
67 isa_ok( WantsMouse->new(), 'Mouse::Object' );
72 package MouseX::Sugar;
78 return $meta->name . ' called wrapped1';
81 Mouse::Exporter->setup_import_methods(
82 with_meta => ['wrapped1'],
90 MouseX::Sugar->import();
94 ::can_ok( 'WantsSugar', 'has' );
95 ::can_ok( 'WantsSugar', 'with' );
96 ::can_ok( 'WantsSugar', 'wrapped1' );
97 ::can_ok( 'WantsSugar', 'foo' );
98 ::is( wrapped1(), 'WantsSugar called wrapped1',
99 'wrapped1 identifies the caller correctly' );
101 MouseX::Sugar->unimport();
105 ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
106 ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
107 ok( ! WantsSugar->can('wrapped1'), 'WantsSugar::wrapped1() has been cleaned' );
108 can_ok( 'WantsSugar', 'foo' );
112 package MouseX::MoreSugar;
117 my $caller = shift->name;
118 return $caller . ' called wrapped2';
125 Mouse::Exporter->setup_import_methods(
126 with_meta => ['wrapped2'],
128 also => 'MouseX::Sugar',
133 package WantsMoreSugar;
135 MouseX::MoreSugar->import();
139 ::can_ok( 'WantsMoreSugar', 'has' );
140 ::can_ok( 'WantsMoreSugar', 'with' );
141 ::can_ok( 'WantsMoreSugar', 'wrapped1' );
142 ::can_ok( 'WantsMoreSugar', 'wrapped2' );
143 ::can_ok( 'WantsMoreSugar', 'as_is1' );
144 ::can_ok( 'WantsMoreSugar', 'foo' );
145 ::is( wrapped1(), 'WantsMoreSugar called wrapped1',
146 'wrapped1 identifies the caller correctly' );
147 ::is( wrapped2(), 'WantsMoreSugar called wrapped2',
148 'wrapped2 identifies the caller correctly' );
149 ::is( as_is1(), 'as_is1',
150 'as_is1 works as expected' );
152 MouseX::MoreSugar->unimport();
156 ok( ! WantsMoreSugar->can('has'), 'WantsMoreSugar::has() has been cleaned' );
157 ok( ! WantsMoreSugar->can('with'), 'WantsMoreSugar::with() has been cleaned' );
158 ok( ! WantsMoreSugar->can('wrapped1'), 'WantsMoreSugar::wrapped1() has been cleaned' );
159 ok( ! WantsMoreSugar->can('wrapped2'), 'WantsMoreSugar::wrapped2() has been cleaned' );
160 ok( ! WantsMoreSugar->can('as_is1'), 'WantsMoreSugar::as_is1() has been cleaned' );
161 can_ok( 'WantsMoreSugar', 'foo' );
165 package My::Metaclass;
167 BEGIN { extends 'Mouse::Meta::Class' }
171 BEGIN { extends 'Mouse::Object' }
179 return Mouse->init_meta( @_,
180 metaclass => 'My::Metaclass',
181 base_class => 'My::Object',
185 Mouse::Exporter->setup_import_methods( also => 'Mouse' );
191 HasInitMeta->import();
195 isa_ok( NewMeta->meta(), 'My::Metaclass' );
196 isa_ok( NewMeta->new(), 'My::Object' );
200 package MouseX::CircularAlso;
206 Mouse::Exporter->setup_import_methods(
207 also => [ 'Mouse', 'MouseX::CircularAlso' ],
210 'a circular reference in also dies with an error'
215 qr/\QCircular reference in 'also' parameter to Mouse::Exporter between MouseX::CircularAlso and MouseX::CircularAlso/,
216 'got the expected error from circular reference in also'
221 package MouseX::NoAlso;
227 Mouse::Exporter->setup_import_methods(
228 also => [ 'NoSuchThing' ],
231 'a package which does not use Mouse::Exporter in also dies with an error'
236 qr/\QPackage in also (NoSuchThing) does not seem to use Mouse::Exporter (is it loaded?) at /,
237 'got the expected error from a reference in also to a package which is not loaded'
242 package MouseX::NotExporter;
248 Mouse::Exporter->setup_import_methods(
249 also => [ 'Mouse::Meta::Method' ],
252 'a package which does not use Mouse::Exporter in also dies with an error'
257 qr/\QPackage in also (Mouse::Meta::Method) does not seem to use Mouse::Exporter at /,
258 'got the expected error from a reference in also to a package which does not use Mouse::Exporter'
263 package MouseX::OverridingSugar;
268 my $caller = shift->name;
269 return $caller . ' called has';
272 Mouse::Exporter->setup_import_methods(
273 with_meta => ['has'],
279 package WantsOverridingSugar;
281 MouseX::OverridingSugar->import();
283 ::can_ok( 'WantsOverridingSugar', 'has' );
284 ::can_ok( 'WantsOverridingSugar', 'with' );
285 ::is( has('foo'), 'WantsOverridingSugar called has',
286 'has from MouseX::OverridingSugar is called, not has from Mouse' );
288 MouseX::OverridingSugar->unimport();
292 ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
293 ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
297 package NonExistentExport;
302 Mouse::Exporter->setup_import_methods(
304 with_meta => ['does_not_exist'],
306 } qr/^Trying to export undefined sub NonExistentExport::does_not_exist/,
307 "warns when a non-existent method is requested to be exported";
311 package WantsNonExistentExport;
313 NonExistentExport->import;
315 ::ok(!__PACKAGE__->can('does_not_exist'),
316 "undefined subs do not get exported");
322 use Mouse::Deprecated -api_version => '0.88';
325 Mouse::Exporter->setup_import_methods(
327 with_meta => [ 'with_meta1', 'with_meta2' ],
328 with_caller => [ 'with_caller1', 'with_caller2' ],
336 sub with_caller2 (&) {
352 package UseAllOptions;
354 AllOptions->import();
358 can_ok( 'UseAllOptions', $_ )
359 for qw( with_meta1 with_meta2 with_caller1 with_caller2 as_is1 );
362 my ( $caller, $arg1 ) = UseAllOptions::with_caller1(42);
363 is( $caller, 'UseAllOptions', 'with_caller wrapped sub gets the right caller' );
364 is( $arg1, 42, 'with_caller wrapped sub returns argument it was passed' );
368 my ( $meta, $arg1 ) = UseAllOptions::with_meta1(42);
369 isa_ok( $meta, 'Mouse::Meta::Class', 'with_meta first argument' );
370 is( $arg1, 42, 'with_meta1 returns argument it was passed' );
374 prototype( UseAllOptions->can('with_caller2') ),
375 prototype( AllOptions->can('with_caller2') ),
376 'using correct prototype on with_meta function'
380 prototype( UseAllOptions->can('with_meta2') ),
381 prototype( AllOptions->can('with_meta2') ),
382 'using correct prototype on with_meta function'
387 package UseAllOptions;
388 AllOptions->unimport();
392 ok( ! UseAllOptions->can($_), "UseAllOptions::$_ has been unimported" )
393 for qw( with_meta1 with_meta2 with_caller1 with_caller2 as_is1 );