#!perl -T
BEGIN { use_ok(
'Sub::Exporter'
); }
our
$exporting_class
=
'Test::SubExporter::DashSetup'
;
for
my
$iteration
(1..2) {
{
sub
X {
return
"desired"
}
Test::SubExporter::SETUP->
import
(
':all'
);
main::is(X(),
"desired"
,
"constructed importer (via -setup [LIST]) worked"
);
}
{
eval
{ Test::SubExporter::EXPORT_MISSING->
import
(
':all'
) };
main::like(
$@,
qr/can't locate export/
,
"croak if we're configured to export something that can't be found"
,
);
}
{
eval
{ Sub::Exporter->
import
(
-setup
=>
sub
{ 1 }) };
main::like($@,
qr/-setup failed validation/
,
"only [],{} ok for -setup"
);
}
main::use_ok(
$exporting_class
);
use
subs
qw(xyzzy hello_sailor)
;
main::is(
xyzzy,
"Nothing happens."
,
"DEFAULT: default export xyzzy works as expected"
);
main::is(
hello_sailor,
"Nothing happens yet."
,
"DEFAULT: default export hello_sailor works as expected"
);
main::use_ok(
$exporting_class
,
xyzzy
=> {
-as
=>
'plugh'
});
main::is(
plugh,
"Nothing happens."
,
"RENAME: default export xyzzy=>plugh works as expected"
);
main::use_ok(
$exporting_class
,
':sailor'
);;
use
subs
qw(xyzzy hs_works hs_fails)
;
main::is(
xyzzy,
"Nothing happens."
,
"SAILOR: default export xyzzy works as expected"
);
main::is(
hs_works,
"Something happens!"
,
"SAILOR: hs_works export works as expected"
);
main::is(
hs_fails,
"Nothing happens yet."
,
"SAILOR: hs_fails export works as expected"
);
main::use_ok(
$exporting_class
,
hello_sailor
=> {
game
=>
'zork3'
});
use
subs
qw(hello_sailor)
;
main::is(
hello_sailor,
"Something happens!"
,
"Z3: custom hello_sailor works as expected"
);
main::use_ok(
$exporting_class
,
-sailor
=> {
-prefix
=>
'frotz_'
});
use
subs
map
{
"frotz_$_"
}
qw(xyzzy hs_works hs_fails)
;
main::is(
frotz_xyzzy,
"Nothing happens."
,
"FROTZ_SAILOR: default export xyzzy works as expected"
);
main::is(
frotz_hs_works,
"Something happens!"
,
"FROTZ_SAILOR: hs_works export works as expected"
);
main::is(
frotz_hs_fails,
"Nothing happens yet."
,
"FROTZ_SAILOR: hs_fails export works as expected"
);
}
{
{
our
%EXPORT_TAGS
= (
"all"
=> [] );
-as
=>
'alternimport'
,
exports
=> [
qw(Y)
],
};
sub
X {
return
"desired"
}
sub
Y {
return
"other"
}
}
{
Test::SubExporter::SETUPALT->
import
(
':all'
);
eval
{ X() };
main::like($@,
qr/undefined subroutine/
i,
"X didn't get imported"
);
eval
{ Y() };
main::like($@,
qr/undefined subroutine/
i,
"Y didn't get imported"
);
Test::SubExporter::SETUPALT->alternimport(
':all'
);
main::is(Y(),
"other"
,
"other importer (via -setup { -as ...}) worked"
);
}
}