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