| 1 |
Exporter::Tidy |
| 2 |
|
| 3 |
INSTALLATION |
| 4 |
|
| 5 |
To install this module type the following: |
| 6 |
|
| 7 |
perl Makefile.PL |
| 8 |
make |
| 9 |
make test |
| 10 |
make install |
| 11 |
|
| 12 |
Or use CPANPLUS to automate the process. |
| 13 |
|
| 14 |
Module documentation: |
| 15 |
NAME |
| 16 |
Exporter::Tidy - Another way of exporting symbols |
| 17 |
|
| 18 |
SYNOPSIS |
| 19 |
package MyModule::HTTP; |
| 20 |
use Exporter::Tidy |
| 21 |
default => [ qw(get) ], |
| 22 |
other => [ qw(post head) ]; |
| 23 |
|
| 24 |
use MyModule::HTTP qw(:all); |
| 25 |
use MyModule::HTTP qw(:default post); |
| 26 |
use MyModule::HTTP qw(post); |
| 27 |
use MyModule::HTTP _prefix => 'http_', qw(get post); |
| 28 |
use MyModule::HTTP qw(get post), _prefix => 'http_', qw(head); |
| 29 |
use MyModule::HTTP |
| 30 |
_prefix => 'foo', qw(get post), |
| 31 |
_prefix => 'bar', qw(get head); |
| 32 |
|
| 33 |
package MyModule::Foo; |
| 34 |
use Exporter::Tidy |
| 35 |
default => [ qw($foo $bar quux) ], |
| 36 |
_map => { |
| 37 |
'$foo' => \$my_foo, |
| 38 |
'$bar' => \$my_bar, |
| 39 |
quux => sub { print "Hello, world!\n" } |
| 40 |
}; |
| 41 |
|
| 42 |
package MyModule::Constants; |
| 43 |
use Exporter::Tidy |
| 44 |
default => [ qw(:all) ], |
| 45 |
_map => { |
| 46 |
FOO => sub () { 1 }, |
| 47 |
BAR => sub () { 2 }, |
| 48 |
OK => sub () { 1 }, |
| 49 |
FAILURE => sub () { 0 } |
| 50 |
}; |
| 51 |
|
| 52 |
DESCRIPTION |
| 53 |
This module serves as an easy, clean alternative to Exporter. Unlike |
| 54 |
Exporter, it is not subclassed, but it simply exports a custom import() |
| 55 |
into your namespace. |
| 56 |
|
| 57 |
With Exporter::Tidy, you don't need to use any package global in your |
| 58 |
module. Even the subs you export can be lexically scoped. |
| 59 |
|
| 60 |
use Exporter::Tidy LIST |
| 61 |
The list supplied to "use Exporter::Tidy" should be a key-value list. |
| 62 |
Each key serves as a tag, used to group exportable symbols. The values |
| 63 |
in this key-value list should be array references. There are a few |
| 64 |
special tags: |
| 65 |
|
| 66 |
all If you don't provide an "all" tag yourself, Tidy::Exporter |
| 67 |
will generate one for you. It will contain all exportable |
| 68 |
symbols. |
| 69 |
|
| 70 |
default The "default" tag will be used if the user supplies no list to |
| 71 |
the "use" statement. |
| 72 |
|
| 73 |
_map With _map you should not use an array reference, but a hash |
| 74 |
reference. Here, you can rewrite symbols to other names or |
| 75 |
even define one on the spot by using a reference. You can "foo |
| 76 |
=> 'bar'" to export "bar" if "foo" is requested. |
| 77 |
|
| 78 |
Exportable symbols |
| 79 |
Every symbol specified in a tag's array, or used as a key in _map's hash |
| 80 |
is exportable. |
| 81 |
|
| 82 |
Symbol types |
| 83 |
You can export subs, scalars, arrays, hashes and typeglobs. Do not use |
| 84 |
an ampersand ("&") for subs. All other types must have the proper sigil. |
| 85 |
|
| 86 |
Importing from a module that uses Exporter::Tidy |
| 87 |
You can use either a symbol name (without the sigil if it is a sub, or |
| 88 |
with the appropriate sigil if it is not), or a tag name prefixed with a |
| 89 |
colon. It is possible to import a symbol twice, but a symbol is never |
| 90 |
exported twice under the same name, so you can use tags that overlap. If |
| 91 |
you supply any list to the "use" statement, ":default" is no longer used |
| 92 |
if not specified explicitly. |
| 93 |
|
| 94 |
To avoid name clashes, it is possible to have symbols prefixed. Supply |
| 95 |
"_prefix" followed by the prefix that you want. Multiple can be used. |
| 96 |
|
| 97 |
use Some::Module qw(foo bar), _prefix => 'some_', qw(quux); |
| 98 |
|
| 99 |
imports Some::Module::foo as foo, Some::Module::bar as bar, and |
| 100 |
Some::Module::quux as some_quux. See the SYNOPSIS for more examples. |
| 101 |
|
| 102 |
COMPARISON |
| 103 |
Exporter::Tidy "versus" Exporter |
| 104 |
|
| 105 |
These numbers are valid for my Linux system with Perl 5.8.0. Your |
| 106 |
mileage may vary. |
| 107 |
|
| 108 |
Speed |
| 109 |
Exporting two symbols using no import list (@EXPORT and :default) is |
| 110 |
approximately 10% faster with Exporter. But if you use any tag |
| 111 |
explicitly, Exporter::Tidy is more than twice as fast (!) as Exporter. |
| 112 |
|
| 113 |
Memory usage |
| 114 |
perl -le'require X; print((split " ", `cat /proc/$$/stat`)[22])' |
| 115 |
|
| 116 |
No module 3022848 |
| 117 |
Exporter::Tidy 3067904 |
| 118 |
Exporter 3084288 |
| 119 |
Exporter::Heavy 3174400 |
| 120 |
|
| 121 |
Exporter loads Exporter::Heavy automatically when needed. It is needed |
| 122 |
to support exporter tags, amongst other things. Exporter::Tidy has all |
| 123 |
functionality built into one module. |
| 124 |
|
| 125 |
Both Exporter(::Heavy) and Exporter::Tidy delay loading Carp until it is |
| 126 |
needed. |
| 127 |
|
| 128 |
Usage |
| 129 |
Exporter is subclassed and gets its information from package global |
| 130 |
variables like @EXPORT, @EXPORT_OK and %EXPORT_TAGS. |
| 131 |
|
| 132 |
Exporter::Tidy exports an "import" method and gets its information from |
| 133 |
the "use" statement. |
| 134 |
|
| 135 |
LICENSE |
| 136 |
This software may be redistributed under the terms of the GPL, LGPL, |
| 137 |
modified BSD, or Artistic license, or any of the other OSI approved |
| 138 |
licenses listed at http://www.opensource.org/licenses/alphabetical. |
| 139 |
Distribution is allowed under all of these licenses, or any smaller |
| 140 |
subset of multiple or just one of these licenses. |
| 141 |
|
| 142 |
When using a packaged version, please refer to the package metadata to see |
| 143 |
under which license terms it was distributed. Alternatively, a distributor |
| 144 |
may choose to replace the LICENSE section of the documentation and/or |
| 145 |
include a LICENSE file to reflect the license(s) they chose to redistribute |
| 146 |
under. |
| 147 |
|
| 148 |
AUTHOR |
| 149 |
Juerd Waalboer <[email protected]> <http://juerd.nl/> |
| 150 |
|