1use strict;
2
3use Test::More tests => 51;
4
5use lib 't';
6use Run;
7
8require_ok('Exporter::Easy');
9
10package Start::Testing::Use::Functions;
11
12{
13	no strict 'refs';
14
15	*{add_tags} = \&Exporter::Easy::add_tags;
16	*{expand_tags} = \&Exporter::Easy::expand_tags;
17}
18
19::ok(
20	::eq_set( [ expand_tags([qw( a b c)], {}) ], [ qw( a b c) ] ),
21	"simple _expand_tags"
22);
23
24::ok(
25	::eq_set( [ expand_tags([qw( a b c !b)], {}) ], [ qw( a c ) ] ),
26	"simple _expand_tags with remove"
27);
28
29::ok(
30	::eq_set(
31		[
32			expand_tags([ qw( a b c :tag2 ) ], { tag2 => [ qw( d e ) ] }),
33		],
34		[qw( a b c d e )],
35	),
36	"_expand_tags with tag"
37);
38
39::ok(
40	::eq_set(
41		[
42			expand_tags( [ qw( a b c d f !:tag2 ) ],{ tag2 => [ qw( d e ) ] })
43		],
44		[qw( a b c f )]
45	),
46	"_expand_tags with remove tag"
47);
48
49my $tags = add_tags(
50	[
51		tag1 => [qw( a b c d )],
52		tag2 => [qw( c d e )],
53		tag3 => [qw( :tag1 !:tag2 d !a )],
54	]
55);
56
57::ok(::eq_set( $tags->{tag1}, [qw( a b c d )] ), "_build_all_tags tag1");
58::ok(::eq_set( $tags->{tag2}, [qw( c d e )] ), "_build_all_tags tag2");
59::ok(::eq_set( $tags->{tag3}, [qw( b d )] ), "_build_all_tags tag3");
60::ok(keys(%$tags) == 3, "use TAGS count");
61
62package Use::OK;
63
64use Exporter::Easy (
65	OK => [qw( o_1 o_2) ],
66);
67
68use vars qw( @EXPORT_OK );
69
70::ok(::eq_set(\@EXPORT_OK, [qw( o_1 o_2 )]), "simple use OK");
71
72package Use::OK_ONLY;
73
74use Exporter::Easy (
75	OK_ONLY => [qw( o_1 o_2 ) ],
76);
77
78use vars qw( @EXPORT_OK );
79
80::ok(::eq_set(\@EXPORT_OK, [qw( o_1 o_2 )]), "simple use OK_ONLY");
81
82package Use::More;
83
84use Exporter::Easy (
85	EXPORT => [ qw( e_1 e_2 ) ],
86	FAIL => [qw( f_1 f_2) ],
87	OK_ONLY => [qw( o_1 o_2) ],
88);
89
90use vars qw( @EXPORT @EXPORT_FAIL @EXPORT_OK %EXPORT_TAGS );
91
92::ok(::eq_set( \@EXPORT, [qw( e_1 e_2)] ), "use EXPORT");
93::ok(::eq_set( \@EXPORT_FAIL, [qw( f_1 f_2)] ), "use FAIL");
94::ok(::eq_set( \@EXPORT_OK, [qw( o_1 o_2 )] ), "use OK_ONLY with EXPORT");
95::is_deeply(\%EXPORT_TAGS, {}, "use without TAGS");
96
97package Use::TAGS::And::OK_ONLY;
98
99use Exporter::Easy (
100	EXPORT => [ qw( e_1 e_2 ) ],
101	TAGS => [
102		tag1 => [qw( a b c d e f )],
103		tag2 => [qw( b d f )],
104		tag3 => [qw( :tag1 !:tag2 )],
105	],
106	OK_ONLY => [qw( o_1 o_2) ],
107);
108
109use vars qw( @EXPORT @EXPORT_OK %EXPORT_TAGS );
110
111::ok(::eq_set( \@EXPORT, [ qw( e_1 e_2)] ), "use EXPORT and TAGS");
112::ok(::eq_set( \@EXPORT_OK ,[qw( o_1 o_2 )] ), "use OK_ONLY with EXPORT and TAGS"
113);
114
115{
116	my %e = %EXPORT_TAGS;
117
118	::ok(::eq_set( $e{tag1}, [qw( a b c d e f )] ), "use TAGS tag1");
119	::ok(::eq_set( $e{tag2}, [qw( b d f )] ), "use TAGS tag2");
120	::ok(::eq_set( $e{tag3}, [qw( a c e )] ), "use TAGS tag3");
121	::ok(keys(%e) == 3, "use TAGS count");
122}
123
124package Test::The::Use3;
125
126use Exporter::Easy (
127	EXPORT => [ qw( e_1 e_2 ) ],
128	TAGS => [
129		tag1 => [qw( a b c d e f )],
130		tag2 => [qw( b d f )],
131		tag3 => [qw( :tag1 !:tag2 )],
132	],
133	OK => [qw( o_1 o_2) ],
134);
135
136use vars qw( @EXPORT @EXPORT_OK %EXPORT_TAGS );
137
138::ok(::eq_set( \@EXPORT, [ qw( e_1 e_2)] ), "use EXPORT and TAGS");
139::ok(::eq_set( \@EXPORT_OK ,[qw( a b c d e f o_1 o_2 )] ), "use OK with EXPORT and TAGS"
140);
141
142{
143	my %e = %EXPORT_TAGS;
144
145	::ok(::eq_set( $e{tag1}, [qw( a b c d e f )] ), "use TAGS tag1");
146	::ok(::eq_set( $e{tag2}, [qw( b d f )] ), "use TAGS tag2");
147	::ok(::eq_set( $e{tag3}, [qw( a c e )] ), "use TAGS tag3");
148	::ok(keys(%e) == 3, "use TAGS count");
149}
150
151package Test::The::Use4;
152
153use Exporter::Easy (
154	EXPORT => [qw( open close :rw )],
155	FAIL => [qw( hello :fail )],
156	TAGS => [
157		fail => [qw (f_1 f_2 )],
158		rw => [qw( read write )],
159		sys => [qw( sysopen sysclose )],
160	],
161	ALL => 'all',
162);
163
164use vars qw( @EXPORT @EXPORT_OK @EXPORT_FAIL %EXPORT_TAGS );
165
166::ok(::eq_set( \@EXPORT, [qw( open close read write)] ), "use tags in EXPORT");
167::ok(::eq_set( \@EXPORT_OK, [qw( hello f_1 f_2 sysopen sysclose read write )]) , "use FAIL in EXPORT_OK");
168::ok(::eq_set( \@EXPORT_FAIL, [qw( hello f_1 f_2 )] ), "use tags in EXPORT");
169::ok(::eq_set( $EXPORT_TAGS{all}, [qw( hello f_1 f_2 read write sysopen sysclose open close )] ), "use ALL with FAIL");
170
171package Test::The::Use5;
172
173eval <<EOM;
174use Exporter::Easy (
175	EXPORT => [qw( :tag )],
176);
177EOM
178
179::ok($@, "die for unknown tag");
180
181package Test::ISA::Default;
182
183use base 'base';
184use vars '@ISA';
185
186use Exporter::Easy(ALL => 'all');
187
188::is_deeply(\@ISA, ['base','Exporter'], '@ISA default');
189
190package Test::ISA::Explicit;
191
192use base 'base';
193use vars '@ISA';
194
195use Exporter::Easy(
196	ISA => 1,
197);
198
199::is_deeply(\@ISA, ['base','Exporter'], '@ISA explicit');
200
201package Test::ISA::No;
202
203use base 'base';
204use vars '@ISA';
205
206use Exporter::Easy(
207	ISA => 0,
208);
209
210::is_deeply(\@ISA, ['base'], 'no @ISA explicit');
211
212package Test::Vars;
213
214use Exporter::Easy(
215	TAGS => [
216		var => [qw( $hello @hello %hello a )],
217		not => [qw( $goodbye @goodbye %goodbye b )],
218	],
219);
220
221foreach my $type (qw( $ @ % ))
222{
223	::runs_ok("${type}\{hello}", "tag vars can use var ${type}hello");
224
225	::runs_ok("${type}\{goodbye}", "tag vars can't use var ${type}goodbye");
226}
227
228package Test::Vars::List;
229
230use Exporter::Easy(
231	TAGS => [
232		var => [qw( $hello @hello %hello a )],
233		not => [qw( $goodbye @goodbye %goodbye a )],
234	],
235	VARS => [':var', '$cat'],
236);
237
238foreach my $type (qw( $ @ % ))
239{
240	::runs_ok("${type}\{hello}", "list vars can use var ${type}hello");
241
242	::dies_ok("${type}\{goodbye}", "list vars can't use var ${type}goodbye");
243}
244
245::runs_ok('$cat', 'list vars can use var $cat');
246
247package Test::Vars::Fail;
248
249use Exporter::Easy(
250	TAGS => [
251		not => [qw( $goodbye @goodbye %goodbye )],
252	],
253	VARS => 0,
254);
255
256foreach my $type (qw( $ @ % ))
257{
258	::dies_ok("${type}\{goodbye}", "no vars can't use var ${type}goodbye");
259}
260