6 use Test::More tests => 38;
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' );
40 # This makes sure that Moose->init_meta() happens properly
41 isa_ok( WantsMoose->meta(), 'Moose::Meta::Class' );
42 isa_ok( WantsMoose->new(), 'Moose::Object' );
47 package MooseX::Sugar;
53 return $caller . ' called wrapped1';
57 Moose::Exporter->build_import_methods(
58 with_caller => ['wrapped1'],
67 BEGIN { MooseX::Sugar->import() }
72 ::can_ok( 'WantsSugar', 'has' );
73 ::can_ok( 'WantsSugar', 'with' );
74 ::can_ok( 'WantsSugar', 'wrapped1' );
75 ::can_ok( 'WantsSugar', 'foo' );
76 ::is( wrapped1(), 'WantsSugar called wrapped1',
77 'wrapped1 identifies the caller correctly' );
80 BEGIN{ MooseX::Sugar->unimport();}
84 ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
85 ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
86 ok( ! WantsSugar->can('wrapped1'), 'WantsSugar::wrapped1() has been cleaned' );
87 can_ok( 'WantsSugar', 'foo' );
91 package MooseX::MoreSugar;
97 return $caller . ' called wrapped2';
105 Moose::Exporter->build_import_methods(
106 with_caller => ['wrapped2'],
108 also => 'MooseX::Sugar',
114 package WantsMoreSugar;
116 BEGIN { MooseX::MoreSugar->import() }
121 ::can_ok( 'WantsMoreSugar', 'has' );
122 ::can_ok( 'WantsMoreSugar', 'with' );
123 ::can_ok( 'WantsMoreSugar', 'wrapped1' );
124 ::can_ok( 'WantsMoreSugar', 'wrapped2' );
125 ::can_ok( 'WantsMoreSugar', 'as_is1' );
126 ::can_ok( 'WantsMoreSugar', 'foo' );
127 ::is( wrapped1(), 'WantsMoreSugar called wrapped1',
128 'wrapped1 identifies the caller correctly' );
129 ::is( wrapped2(), 'WantsMoreSugar called wrapped2',
130 'wrapped2 identifies the caller correctly' );
131 ::is( as_is1(), 'as_is1',
132 'as_is1 works as expected' );
135 BEGIN{ MooseX::MoreSugar->unimport();}
139 ok( ! WantsMoreSugar->can('has'), 'WantsMoreSugar::has() has been cleaned' );
140 ok( ! WantsMoreSugar->can('with'), 'WantsMoreSugar::with() has been cleaned' );
141 ok( ! WantsMoreSugar->can('wrapped1'), 'WantsMoreSugar::wrapped1() has been cleaned' );
142 ok( ! WantsMoreSugar->can('wrapped2'), 'WantsMoreSugar::wrapped2() has been cleaned' );
143 ok( ! WantsMoreSugar->can('as_is1'), 'WantsMoreSugar::as_is1() has been cleaned' );
144 can_ok( 'WantsMoreSugar', 'foo' );
148 package My::Metaclass;
150 BEGIN { extends 'Moose::Meta::Class' }
154 BEGIN { extends 'Moose::Object' }
162 return Moose->init_meta( @_,
163 metaclass => 'My::Metaclass',
164 base_class => 'My::Object',
168 BEGIN { Moose::Exporter->build_import_methods( also => 'Moose' ); }
174 BEGIN { HasInitMeta->import() }
178 isa_ok( NewMeta->meta(), 'My::Metaclass' );
179 isa_ok( NewMeta->new(), 'My::Object' );
183 package MooseX::CircularAlso;
189 Moose::Exporter->build_import_methods(
190 also => [ 'Moose', 'MooseX::CircularAlso' ],
193 'a circular reference in also dies with an error'
198 qr/\QCircular reference in also parameter to MooseX::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/,
199 'got the expected error from circular reference in also'
204 package MooseX::CircularAlso;
210 Moose::Exporter->build_import_methods(
211 also => [ 'NoSuchThing' ],
214 'a package which does not use Moose::Exporter in also dies with an error'
219 qr/\QPackage in also (NoSuchThing) does not seem to use MooseX::Exporter/,
220 'got the expected error from a reference in also to a package which does not use Moose::Exporter'