6 use Test::More 'no_plan';
9 # All the BEGIN blocks are necessary to emulate the behavior of
10 # loading modules via use and the similar compile-time effect of "no
13 package MooseX::Empty;
16 BEGIN { Moose::Exporter->build_import_methods( also => 'Moose' ); }
22 BEGIN { MooseX::Empty->import(); }
27 ::can_ok( 'WantsMoose', 'has' );
28 ::can_ok( 'WantsMoose', 'with' );
29 ::can_ok( 'WantsMoose', 'foo' );
32 BEGIN{ MooseX::Empty->unimport();}
36 ok( ! WantsMoose->can('has'), 'WantsMoose::has() has been cleaned' );
37 ok( ! WantsMoose->can('with'), 'WantsMoose::with() has been cleaned' );
38 can_ok( 'WantsMoose', 'foo' );
42 package MooseX::Sugar;
48 return $caller . ' called wrapped1';
52 Moose::Exporter->build_import_methods(
53 with_caller => ['wrapped1'],
62 BEGIN { MooseX::Sugar->import() }
67 ::can_ok( 'WantsSugar', 'has' );
68 ::can_ok( 'WantsSugar', 'with' );
69 ::can_ok( 'WantsSugar', 'wrapped1' );
70 ::can_ok( 'WantsSugar', 'foo' );
71 ::is( wrapped1(), 'WantsSugar called wrapped1',
72 'wrapped1 identifies the caller correctly' );
75 BEGIN{ MooseX::Sugar->unimport();}
79 ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
80 ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
81 ok( ! WantsSugar->can('wrapped1'), 'WantsSugar::wrapped1() has been cleaned' );
82 can_ok( 'WantsSugar', 'foo' );
86 package MooseX::MoreSugar;
92 return $caller . ' called wrapped2';
100 Moose::Exporter->build_import_methods(
101 with_caller => ['wrapped2'],
103 also => 'MooseX::Sugar',
109 package WantsMoreSugar;
111 BEGIN { MooseX::MoreSugar->import() }
116 ::can_ok( 'WantsMoreSugar', 'has' );
117 ::can_ok( 'WantsMoreSugar', 'with' );
118 ::can_ok( 'WantsMoreSugar', 'wrapped1' );
119 ::can_ok( 'WantsMoreSugar', 'wrapped2' );
120 ::can_ok( 'WantsMoreSugar', 'as_is1' );
121 ::can_ok( 'WantsMoreSugar', 'foo' );
122 ::is( wrapped1(), 'WantsMoreSugar called wrapped1',
123 'wrapped1 identifies the caller correctly' );
124 ::is( wrapped2(), 'WantsMoreSugar called wrapped2',
125 'wrapped2 identifies the caller correctly' );
126 ::is( as_is1(), 'as_is1',
127 'as_is1 works as expected' );
130 BEGIN{ MooseX::MoreSugar->unimport();}
134 ok( ! WantsMoreSugar->can('has'), 'WantsMoreSugar::has() has been cleaned' );
135 ok( ! WantsMoreSugar->can('with'), 'WantsMoreSugar::with() has been cleaned' );
136 ok( ! WantsMoreSugar->can('wrapped1'), 'WantsMoreSugar::wrapped1() has been cleaned' );
137 ok( ! WantsMoreSugar->can('wrapped2'), 'WantsMoreSugar::wrapped2() has been cleaned' );
138 ok( ! WantsMoreSugar->can('as_is1'), 'WantsMoreSugar::as_is1() has been cleaned' );
139 can_ok( 'WantsMoreSugar', 'foo' );
143 package MooseX::CircularAlso;
149 Moose::Exporter->build_import_methods(
150 also => [ 'Moose', 'MooseX::CircularAlso' ],
153 'a circular reference in also dies with an error'
158 qr/\QCircular reference in also parameter to MooseX::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/,
159 'got the expected error from circular reference in also'
164 package MooseX::CircularAlso;
170 Moose::Exporter->build_import_methods(
171 also => [ 'NoSuchThing' ],
174 'a package which does not use Moose::Exporter in also dies with an error'
179 qr/\QPackage in also (NoSuchThing) does not seem to use MooseX::Exporter/,
180 'got the expected error from a reference in also to a package which does not use Moose::Exporter'