Exporter-Tidy-0.09/0000755000175000017500000000000014672111122013162 5ustar juerdjuerdExporter-Tidy-0.09/Makefile.PL0000644000175000017500000000074614672107124015152 0ustar juerdjuerduse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Exporter::Tidy', 'VERSION_FROM' => 'Tidy.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Tidy.pm', # retrieve abstract from module AUTHOR => 'Juerd ') : ()), ); Exporter-Tidy-0.09/MANIFEST0000644000175000017500000000027014672107223014321 0ustar juerdjuerd.gitignore Changes Makefile.PL MANIFEST MANIFEST.SKIP META.json Module JSON meta-data (added by MakeMaker) META.yml Module YAML meta-data (added by MakeMaker) README t/1.t Tidy.pm Exporter-Tidy-0.09/Changes0000644000175000017500000000113014672110424014454 0ustar juerdjuerdRevision history for Perl extension Exporter::Tidy. 0.09 Mon Sep 16 22:02 2024 - Remove bundled test modules (RT #154930), provided by JKEENAN - Add more tests, provided by JKEENAN - Update any-OSI license text to Debian-approved version 0.08 Thu Jan 6 12:23 2014 - README updated to reflect license change. 0.07 Fri Sep 14 13:02 2007 - Now any-OSI licensed. 0.06 Sat Apr 19 14:32 2003 - Added unit tests for _prefix 0.05 Released immediately after 0.04 - Fixed some mistakes 0.04 Sat Mar 29 22:53 2003 - First CPAN release Exporter-Tidy-0.09/t/0000755000175000017500000000000014672111122013425 5ustar juerdjuerdExporter-Tidy-0.09/t/1.t0000644000175000017500000001005114672107223013756 0ustar juerdjuerduse Test::More tests => 44; BEGIN { require_ok('Exporter::Tidy') }; can_ok 'Exporter::Tidy', 'import'; ok(!defined(&import), 'We are clean'); Exporter::Tidy->import(); ok(defined(&import), 'We got an &import'); BEGIN { package ET_Test1; $INC{'ET_Test1.pm'} = 'dummy'; use Exporter::Tidy default => [ qw(foo1 $foo1 %foo1 @foo1 *bar1) ]; *foo1 = sub { 42 }; *foo1 = \ 'forty-two'; *foo1 = [ 1 .. 42 ]; *foo1 = { 42 => 'forty-two' }; *bar1 = sub { 'foo' }; *bar1 = \ 'foo'; *bar1 = [ 'foo' ]; *bar1 = { foo => 1 }; } use ET_Test1; ok(foo1() == 42, ':default CODE'); ok($foo1 eq 'forty-two', ':default SCALAR'); ok(@foo1 == 42, ':default ARRAY'); ok($foo1{42} eq 'forty-two', ':default HASH'); ok(bar1() eq 'foo', ':default GLOB/CODE'); ok($bar1 eq 'foo', ':default GLOB/SCALAR'); ok($bar1[0] eq 'foo', ':default GLOB/ARRAY'); ok($bar1{foo}, ':default GLOB/HASH'); BEGIN { package ET_Test2; $INC{'ET_Test2.pm'} = 'dummy'; use Exporter::Tidy tag => [ qw(foo2 $foo2 %foo2 @foo2 *bar2) ]; *foo2 = sub { 42 }; *foo2 = \ 'forty-two'; *foo2 = [ 1 .. 42 ]; *foo2 = { 42 => 'forty-two' }; *bar2 = sub { 'foo' }; *bar2 = \ 'foo'; *bar2 = [ 'foo' ]; *bar2 = { foo => 1 }; } use ET_Test2 qw(:tag); ok(foo2() == 42, ':tag CODE'); ok($foo2 eq 'forty-two', ':tag SCALAR'); ok(@foo2 == 42, ':tag ARRAY'); ok($foo2{42} eq 'forty-two', ':tag HASH'); ok(bar2() eq 'foo', ':tag GLOB/CODE'); ok($bar2 eq 'foo', ':tag GLOB/SCALAR'); ok($bar2[0] eq 'foo', ':tag GLOB/ARRAY'); ok($bar2{foo}, ':tag GLOB/HASH'); BEGIN { package ET_Test3; $INC{'ET_Test3.pm'} = 'dummy'; use Exporter::Tidy _map => { 'foo3' => sub { 42 }, '$foo3' => \ 'forty-two', '@foo3' => [ 1 .. 42 ], '%foo3' => { 42 => 'forty-two' }, '*bar3' => \*bar3 }; *bar3 = sub { 'foo' }; *bar3 = \ 'foo'; *bar3 = [ 'foo' ]; *bar3 = { foo => 1 }; } use ET_Test3 qw(foo3 $foo3 @foo3 %foo3 *bar3); ok(foo3() == 42, '_map CODE'); ok($foo3 eq 'forty-two', '_map SCALAR'); ok(@foo3 == 42, '_map ARRAY'); ok($foo3{42} eq 'forty-two', '_map HASH'); ok(bar3() eq 'foo', '_map GLOB/CODE'); ok($bar3 eq 'foo', '_map GLOB/SCALAR'); ok($bar3[0] eq 'foo', '_map GLOB/ARRAY'); ok($bar3{foo}, '_map GLOB/HASH'); BEGIN { package ET_Test4; $INC{'ET_Test4.pm'} = 'dummy'; use Exporter::Tidy moo => [ qw(foo $foo %foo @foo *bar) ]; *foo = sub { 42 }; *foo = \ 'forty-two'; *foo = [ 1 .. 42 ]; *foo = { 42 => 'forty-two' }; *bar = sub { 'foo' }; *bar = \ 'foo'; *bar = [ 'foo' ]; *bar = { foo => 1 }; } use ET_Test4 _prefix => 'foo_', qw(foo $foo %foo @foo), _prefix => 'bar_', qw(*bar); ok(foo_foo() == 42, '_prefix CODE'); ok($foo_foo eq 'forty-two', '_prefix SCALAR'); ok(@foo_foo == 42, '_prefix ARRAY'); ok($foo_foo{42} eq 'forty-two', '_prefix HASH'); ok(bar_bar() eq 'foo', '_prefix GLOB/CODE'); ok($bar_bar eq 'foo', '_prefix GLOB/SCALAR'); ok($bar_bar[0] eq 'foo', '_prefix GLOB/ARRAY'); ok($bar_bar{foo}, '_prefix GLOB/HASH'); BEGIN { package ET_Test5; $INC{'ET_Test5.pm'} = 'dummy'; use Exporter::Tidy all => [ qw(foo1 $foo1 %foo1 @foo1 *bar1) ]; *foo1 = sub { 42 }; *foo1 = \ 'forty-two'; *foo1 = [ 1 .. 42 ]; *foo1 = { 42 => 'forty-two' }; *bar1 = sub { 'foo' }; *bar1 = \ 'foo'; *bar1 = [ 'foo' ]; *bar1 = { foo => 1 }; } use ET_Test5; ok(foo1() == 42, ':default CODE'); ok($foo1 eq 'forty-two', ':default SCALAR'); ok(@foo1 == 42, ':default ARRAY'); ok($foo1{42} eq 'forty-two', ':default HASH'); ok(bar1() eq 'foo', ':default GLOB/CODE'); ok($bar1 eq 'foo', ':default GLOB/SCALAR'); ok($bar1[0] eq 'foo', ':default GLOB/ARRAY'); ok($bar1{foo}, ':default GLOB/HASH'); Exporter-Tidy-0.09/.gitignore0000644000175000017500000000033614672107223015163 0ustar juerdjuerd/blib/ /.build/ _build/ cover_db/ inc/ Build !Build/ Build.bat .last_cover_stats /Makefile /Makefile.old /MANIFEST.bak /META.yml /META.json /MYMETA.* nytprof.out /pm_to_blib *.o *.bs Exporter-Tidy-*.tar.gz /nytprof/ *.swp Exporter-Tidy-0.09/META.yml0000664000175000017500000000104014672111122014430 0ustar juerdjuerd--- abstract: 'Another way of exporting symbols' author: - 'Juerd ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Exporter-Tidy no_index: directory: - t - inc requires: {} version: '0.09' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Exporter-Tidy-0.09/META.json0000664000175000017500000000157214672111122014612 0ustar juerdjuerd{ "abstract" : "Another way of exporting symbols", "author" : [ "Juerd " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Exporter-Tidy", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "version" : "0.09", "x_serialization_backend" : "JSON::PP version 4.16" } Exporter-Tidy-0.09/README0000644000175000017500000001250714672107613014061 0ustar juerdjuerdExporter::Tidy INSTALLATION To install this module type the following: perl Makefile.PL make make test make install Or use CPANPLUS to automate the process. Module documentation: NAME Exporter::Tidy - Another way of exporting symbols SYNOPSIS package MyModule::HTTP; use Exporter::Tidy default => [ qw(get) ], other => [ qw(post head) ]; use MyModule::HTTP qw(:all); use MyModule::HTTP qw(:default post); use MyModule::HTTP qw(post); use MyModule::HTTP _prefix => 'http_', qw(get post); use MyModule::HTTP qw(get post), _prefix => 'http_', qw(head); use MyModule::HTTP _prefix => 'foo', qw(get post), _prefix => 'bar', qw(get head); package MyModule::Foo; use Exporter::Tidy default => [ qw($foo $bar quux) ], _map => { '$foo' => \$my_foo, '$bar' => \$my_bar, quux => sub { print "Hello, world!\n" } }; package MyModule::Constants; use Exporter::Tidy default => [ qw(:all) ], _map => { FOO => sub () { 1 }, BAR => sub () { 2 }, OK => sub () { 1 }, FAILURE => sub () { 0 } }; DESCRIPTION This module serves as an easy, clean alternative to Exporter. Unlike Exporter, it is not subclassed, but it simply exports a custom import() into your namespace. With Exporter::Tidy, you don't need to use any package global in your module. Even the subs you export can be lexically scoped. use Exporter::Tidy LIST The list supplied to "use Exporter::Tidy" should be a key-value list. Each key serves as a tag, used to group exportable symbols. The values in this key-value list should be array references. There are a few special tags: all If you don't provide an "all" tag yourself, Tidy::Exporter will generate one for you. It will contain all exportable symbols. default The "default" tag will be used if the user supplies no list to the "use" statement. _map With _map you should not use an array reference, but a hash reference. Here, you can rewrite symbols to other names or even define one on the spot by using a reference. You can "foo => 'bar'" to export "bar" if "foo" is requested. Exportable symbols Every symbol specified in a tag's array, or used as a key in _map's hash is exportable. Symbol types You can export subs, scalars, arrays, hashes and typeglobs. Do not use an ampersand ("&") for subs. All other types must have the proper sigil. Importing from a module that uses Exporter::Tidy You can use either a symbol name (without the sigil if it is a sub, or with the appropriate sigil if it is not), or a tag name prefixed with a colon. It is possible to import a symbol twice, but a symbol is never exported twice under the same name, so you can use tags that overlap. If you supply any list to the "use" statement, ":default" is no longer used if not specified explicitly. To avoid name clashes, it is possible to have symbols prefixed. Supply "_prefix" followed by the prefix that you want. Multiple can be used. use Some::Module qw(foo bar), _prefix => 'some_', qw(quux); imports Some::Module::foo as foo, Some::Module::bar as bar, and Some::Module::quux as some_quux. See the SYNOPSIS for more examples. COMPARISON Exporter::Tidy "versus" Exporter These numbers are valid for my Linux system with Perl 5.8.0. Your mileage may vary. Speed Exporting two symbols using no import list (@EXPORT and :default) is approximately 10% faster with Exporter. But if you use any tag explicitly, Exporter::Tidy is more than twice as fast (!) as Exporter. Memory usage perl -le'require X; print((split " ", `cat /proc/$$/stat`)[22])' No module 3022848 Exporter::Tidy 3067904 Exporter 3084288 Exporter::Heavy 3174400 Exporter loads Exporter::Heavy automatically when needed. It is needed to support exporter tags, amongst other things. Exporter::Tidy has all functionality built into one module. Both Exporter(::Heavy) and Exporter::Tidy delay loading Carp until it is needed. Usage Exporter is subclassed and gets its information from package global variables like @EXPORT, @EXPORT_OK and %EXPORT_TAGS. Exporter::Tidy exports an "import" method and gets its information from the "use" statement. LICENSE This software may be redistributed under the terms of the GPL, LGPL, modified BSD, or Artistic license, or any of the other OSI approved licenses listed at http://www.opensource.org/licenses/alphabetical. Distribution is allowed under all of these licenses, or any smaller subset of multiple or just one of these licenses. When using a packaged version, please refer to the package metadata to see under which license terms it was distributed. Alternatively, a distributor may choose to replace the LICENSE section of the documentation and/or include a LICENSE file to reflect the license(s) they chose to redistribute under. AUTHOR Juerd Waalboer Exporter-Tidy-0.09/MANIFEST.SKIP0000644000175000017500000000057014672107223015071 0ustar juerdjuerd^blib/ ^Makefile$ ^Makefile\.[a-z]+$ ^pm_to_blib$ CVS/.* ,v$ ^tmp/ \.old$ \.bak$ \.tmp$ \.swp$ ~$ ^# \.shar$ \.tar$ \.tgz$ \.tar\.gz$ \.zip$ \.DS_Store$ _uu$ \.svn cover_db/ coverage/ html/ learn/ research/ superseded/ svndiff/ ^Todo ^.cvsignore ^init ^results ^htmlify .git/ ^MYMETA.* nytprof/ nytprof.out \.travis.yml ^README.md ^.README.pod \.appveyor.yml .version_info.pl Exporter-Tidy-0.09/Tidy.pm0000644000175000017500000001546014672107717014456 0ustar juerdjuerdpackage Exporter::Tidy; # use strict; # no strict 'refs'; # our $VERSION = '0.09'; sub import { my (undef, %tags) = @_; my $caller = caller; my $map = delete($tags{_map}); my %available; @available{ grep !ref, keys %$map } = () if $map; @available{ grep !/^:/, map @$_, values %tags } = (); $tags{all} ||= [ keys %available ]; *{"$caller\::import"} = sub { my ($me, @symbols) = @_; my $caller = caller; @symbols = @{ $tags{default} } if @symbols == 0 and exists $tags{default}; my %exported; my $prefix = ''; while (my $symbol = shift @symbols) { $symbol eq '_prefix' and ($prefix = shift @symbols, next); my $real = $map && exists $map->{$symbol} ? $map->{$symbol} : $symbol; next if exists $exported{"$prefix$real"}; undef $exported{"$prefix$symbol"}; $i++; $real =~ /^:(.*)/ and ( (exists $tags{$1} or (require Carp, Carp::croak("Unknown tag: $1"))), push(@symbols, @{ $tags{$1} }), next ); ref $real and ( $symbol =~ s/^[\@\$%*]//, *{"$caller\::$prefix$symbol"} = $real, next ); exists $available{$symbol} or (require Carp, Carp::croak("Unknown symbol: $real")); my ($sigil, $name) = $real =~ /^([\@\$%*]?)(.*)/; $symbol =~ s/^[\@\$%*]//; *{"$caller\::$prefix$symbol"} = $sigil eq '' ? \&{"$me\::$name"} : $sigil eq '$' ? \${"$me\::$name"} : $sigil eq '@' ? \@{"$me\::$name"} : $sigil eq '%' ? \%{"$me\::$name"} : $sigil eq '*' ? \*{"$me\::$name"} : (require Carp, Carp::croak("Strange symbol: $real")); } }; } 1; __END__ =head1 NAME Exporter::Tidy - Another way of exporting symbols =head1 SYNOPSIS package MyModule::HTTP; use Exporter::Tidy default => [ qw(get) ], other => [ qw(post head) ]; use MyModule::HTTP qw(:all); use MyModule::HTTP qw(:default post); use MyModule::HTTP qw(post); use MyModule::HTTP _prefix => 'http_', qw(get post); use MyModule::HTTP qw(get post), _prefix => 'http_', qw(head); use MyModule::HTTP _prefix => 'foo', qw(get post), _prefix => 'bar', qw(get head); package MyModule::Foo; use Exporter::Tidy default => [ qw($foo $bar quux) ], _map => { '$foo' => \$my_foo, '$bar' => \$my_bar, quux => sub { print "Hello, world!\n" } }; package MyModule::Constants; use Exporter::Tidy default => [ qw(:all) ], _map => { FOO => sub () { 1 }, BAR => sub () { 2 }, OK => sub () { 1 }, FAILURE => sub () { 0 } }; =head1 DESCRIPTION This module serves as an easy, clean alternative to Exporter. Unlike Exporter, it is not subclassed, but it simply exports a custom import() into your namespace. With Exporter::Tidy, you don't need to use any package global in your module. Even the subs you export can be lexically scoped. =head2 use Exporter::Tidy LIST The list supplied to C should be a key-value list. Each key serves as a tag, used to group exportable symbols. The values in this key-value list should be array references. There are a few special tags: =over 10 =item all If you don't provide an C tag yourself, Tidy::Exporter will generate one for you. It will contain all exportable symbols. =item default The C tag will be used if the user supplies no list to the C statement. =item _map With _map you should not use an array reference, but a hash reference. Here, you can rewrite symbols to other names or even define one on the spot by using a reference. You can C<< foo => 'bar' >> to export C if C is requested. =back =head2 Exportable symbols Every symbol specified in a tag's array, or used as a key in _map's hash is exportable. =head2 Symbol types You can export subs, scalars, arrays, hashes and typeglobs. Do not use an ampersand (C<&>) for subs. All other types must have the proper sigil. =head2 Importing from a module that uses Exporter::Tidy You can use either a symbol name (without the sigil if it is a sub, or with the appropriate sigil if it is not), or a tag name prefixed with a colon. It is possible to import a symbol twice, but a symbol is never exported twice under the same name, so you can use tags that overlap. If you supply any list to the C statement, C<:default> is no longer used if not specified explicitly. To avoid name clashes, it is possible to have symbols prefixed. Supply C<_prefix> followed by the prefix that you want. Multiple can be used. use Some::Module qw(foo bar), _prefix => 'some_', qw(quux); imports Some::Module::foo as foo, Some::Module::bar as bar, and Some::Module::quux as some_quux. See the SYNOPSIS for more examples. =head1 COMPARISON Exporter::Tidy "versus" Exporter These numbers are valid for my Linux system with Perl 5.8.0. Your mileage may vary. =head2 Speed Exporting two symbols using no import list (@EXPORT and :default) is approximately 10% faster with Exporter. But if you use any tag explicitly, Exporter::Tidy is more than twice as fast (!) as Exporter. =head2 Memory usage perl -le'require X; print((split " ", `cat /proc/$$/stat`)[22])' No module 3022848 Exporter::Tidy 3067904 Exporter 3084288 Exporter::Heavy 3174400 Exporter loads Exporter::Heavy automatically when needed. It is needed to support exporter tags, amongst other things. Exporter::Tidy has all functionality built into one module. Both Exporter(::Heavy) and Exporter::Tidy delay loading Carp until it is needed. =head2 Usage Exporter is subclassed and gets its information from package global variables like @EXPORT, @EXPORT_OK and %EXPORT_TAGS. Exporter::Tidy exports an C method and gets its information from the C statement. =head1 LICENSE This software may be redistributed under the terms of the GPL, LGPL, modified BSD, or Artistic license, or any of the other OSI approved licenses listed at http://www.opensource.org/licenses/alphabetical. Distribution is allowed under all of these licenses, or any smaller subset of multiple or just one of these licenses. When using a packaged version, please refer to the package metadata to see under which license terms it was distributed. Alternatively, a distributor may choose to replace the LICENSE section of the documentation and/or include a LICENSE file to reflect the license(s) they chose to redistribute under. =head1 ACKNOWLEDGEMENTS Thanks to Aristotle Pagaltzis for suggesting the name Exporter::Tidy. =head1 AUTHOR Juerd Waalboer =cut