6 use Test::More tests => 45;
15 Moose::Exporter->setup_import_methods(
17 with_meta => ['with_meta1'],
18 with_caller => ['default_export1'],
19 as_is => ['default_export2'],
21 all_group => [':all'],
22 just_one => ['default_export1']
26 sub default_export1 {1}
27 sub default_export2 {2}
30 my ( $meta, $code ) = @_;
39 ExGroups1->import(':all_group');
41 ::can_ok( __PACKAGE__, 'with_meta1' );
42 ::can_ok( __PACKAGE__, 'default_export1' );
43 ::can_ok( __PACKAGE__, 'default_export2' );
44 ::can_ok( __PACKAGE__, 'has' );
47 eval q/$meta = with_meta1 { return 'coderef'; }/;
48 ::is( $@, '', 'calling with_meta1 with prototype is not an error' );
49 ::isa_ok( $meta, 'Moose::Meta::Class', 'with_meta first argument' );
51 prototype( __PACKAGE__->can('with_meta1') ),
52 prototype( ExGroups1->can('with_meta1') ),
53 'using correct prototype on with_meta function'
56 ExGroups1->unimport();
58 ::ok( !__PACKAGE__->can('with_meta1'),
59 __PACKAGE__ . '::with_meta1() has been cleaned' );
60 ::ok( !__PACKAGE__->can('default_export1'),
61 __PACKAGE__ . '::default_export1() has been cleaned' );
62 ::ok( !__PACKAGE__->can('default_export2'),
63 __PACKAGE__ . '::default_export2() has been cleaned' );
64 ::ok( !__PACKAGE__->can('has'),
65 __PACKAGE__ . '::has() has been cleaned' );
72 ExGroups1->import(':just_one');
74 ::can_ok( __PACKAGE__, 'default_export1' );
75 ::ok( !__PACKAGE__->can('default_export2'),
76 __PACKAGE__ . '::default_export2() was not imported' );
77 ::ok( !__PACKAGE__->can('has'),
78 __PACKAGE__ . '::has() was not imported' );
80 ExGroups1->unimport();
82 ::ok( !__PACKAGE__->can('default_export1'),
83 __PACKAGE__ . '::default_export1() has been cleared' );
91 Moose::Exporter->setup_import_methods(
92 also => ['ExGroups1'],
93 as_is => ['exgroups2_as_is'],
94 with_caller => ['exgroups2_with_caller'],
96 default => ['exgroups2_as_is'],
97 code_group => \&generate_group,
98 parent1 => [qw(:ExGroups1 :code_group)],
103 sub exgroups2_as_is {3}
106 my ( $caller, $group_name, $args, $context ) = @_;
108 ::is( $group_name, 'code_group',
109 'original name is passed to group code' );
110 ::is( $args->{install_as}, $caller . '_code',
111 'group code arguments match caller' );
112 ::is( $context->{from}, __PACKAGE__,
113 'defined package name is passed to group code' );
115 return { $args->{install_as} => \&exported_by_group };
118 sub exported_by_group (&) {
119 my ( $caller, $coderef ) = @_;
130 ::can_ok( __PACKAGE__, 'exgroups2_as_is' );
131 ::ok( !__PACKAGE__->can('exgroups2_with_caller'),
132 '"default" group is no longer "all"' );
137 package UseCodeGroup;
139 ExGroups2->import( ':code_group',
140 { install_as => ( my $export_name = __PACKAGE__ . '_code' ) } );
142 ::can_ok( __PACKAGE__, $export_name );
143 ::ok( &UseCodeGroup_code() eq __PACKAGE__,
144 'code group exports act like "with_caller" subs' );
147 UseCodeCodeGroup_code { return 'code block'; };
149 'code group exports keep their prototypes'
152 ::ok( !__PACKAGE__->can('exgroups2_as_is'),
153 'code group will not automatically export any symbols' );
158 !__PACKAGE__->can($export_name),
161 . "::$export_name() has been cleared"
169 ExGroups2->import( ':parent1',
170 { install_as => ( my $export_name = __PACKAGE__ . '_code' ) } );
172 ::can_ok( __PACKAGE__, $export_name );
173 ::can_ok( __PACKAGE__, 'default_export1' );
174 ::can_ok( __PACKAGE__, 'default_export2' );
175 ::can_ok( __PACKAGE__, 'has' );
179 ::ok( !__PACKAGE__->can($export_name),
180 __PACKAGE__ . "::$export_name() has been cleared" );
181 ::ok( !__PACKAGE__->can('default_export1'),
182 __PACKAGE__ . '::default_export1() has been cleaned' );
183 ::ok( !__PACKAGE__->can('default_export2'),
184 __PACKAGE__ . '::default_export2() has been cleaned' );
185 ::ok( !__PACKAGE__->can('has'),
186 __PACKAGE__ . '::has() has been cleaned' );
193 ExGroups2->import( ':parent2',
194 { install_as => ( my $export_name = __PACKAGE__ . '_code' ) } );
196 ::ok( !__PACKAGE__->can($export_name),
197 '"all" group will not call code groups' );
198 ::can_ok( __PACKAGE__, 'exgroups2_as_is' );
199 ::can_ok( __PACKAGE__, 'exgroups2_with_caller' );
200 ::can_ok( __PACKAGE__, 'default_export1' );
201 ::can_ok( __PACKAGE__, 'has' );
205 ::ok( !__PACKAGE__->can('exgroups2_as_is'),
206 __PACKAGE__ . '::exgroups2_as_is() has been cleaned' );
207 ::ok( !__PACKAGE__->can('exgroups2_with_caller'),
208 __PACKAGE__ . '::exgroups2_with_caller() has been cleaned' );
209 ::ok( !__PACKAGE__->can('default_export1'),
210 __PACKAGE__ . '::default_export1() has been cleaned' );
211 ::ok( !__PACKAGE__->can('has'),
212 __PACKAGE__ . '::has() has been cleaned' );