1=pod 2 3=encoding utf-8 4 5=head1 PURPOSE 6 7Test that tag expansion works sanely. 8 9=head1 AUTHOR 10 11Toby Inkster E<lt>tobyink@cpan.orgE<gt>. 12 13=head1 COPYRIGHT AND LICENCE 14 15This software is copyright (c) 2014, 2017 by Toby Inkster. 16 17This is free software; you can redistribute it and/or modify it under 18the same terms as the Perl 5 programming language system itself. 19 20 21=cut 22 23use strict; 24use warnings; 25use Test::More tests => 17; 26 27BEGIN { 28 package Local::Foo; 29 use Exporter::Shiny qw(foo bar); 30 our @EXPORT = qw(foo); 31 our %EXPORT_TAGS = ( 32 first => [ 'foo' => { xxx => 41 }, 'bar' ], 33 second => [ 'foo', 'bar' ], 34 upper => [ 35 'foo' => { -as => 'O', -prefix => 'F', -suffix => 'O' }, 36 'bar' => { -as => 'A', -prefix => 'B', -suffix => 'R' }, 37 ], 38 ); 39 sub _generate_foo { 40 my $me = shift; 41 my ($name, $args) = @_; 42 $args->{xxx} ||= 'foo'; 43 return sub () { $args->{xxx} }; 44 } 45 sub _generate_bar { 46 my $me = shift; 47 my ($name, $args) = @_; 48 $args->{xxx} ||= 'bar'; 49 return sub () { $args->{xxx} }; 50 } 51}; 52 53use Local::Foo 54 -first => { -prefix => 'first_' }, 55 -second => { -prefix => 'second_', xxx => 666 }, 56 -first => { -prefix => 'third_', xxx => 42 }; 57 58is(first_foo, 41); 59is(first_bar, 'bar'); 60 61is(second_foo, 666); 62is(second_bar, 666); 63 64is(third_foo, 42); 65is(third_bar, 42); 66 67use Local::Foo -upper => { -prefix => 'MY', xxx => 999 }; 68 69is(MYFOO, 999); 70 71{ 72 package Local::Bar; 73 use Local::Foo; 74} 75 76ok( Local::Bar->can('foo') ); 77ok( !Local::Bar->can('bar') ); 78is( Local::Bar::foo(), 'foo' ); 79 80{ 81 package Local::Baz; 82 # Workaround for people who have PERL5OPT set to load features 83 BEGIN { $INC{'feature.pm'} and 'feature'->unimport('switch') }; 84 use Local::Foo -default; 85} 86 87ok( Local::Baz->can('foo') ); 88ok( !Local::Baz->can('bar') ); 89is( Local::Baz::foo(), 'foo' ); 90 91{ 92 package Local::Xyzzy; 93 use Local::Foo -all; 94} 95 96ok( Local::Xyzzy->can('foo') ); 97ok( Local::Xyzzy->can('bar') ); 98is( Local::Xyzzy::foo(), 'foo' ); 99is( Local::Xyzzy::bar(), 'bar' ); 100