1Exporter::Easy(3) User Contributed Perl Documentation Exporter::Easy(3)
2
3
4
6 Exporter::Easy - Takes the drudgery out of Exporting symbols
7
9 In module YourModule.pm:
10
11 package YourModule;
12 use Exporter::Easy (
13 OK => [ '$munge', 'frobnicate' ] # symbols to export on request
14 );
15
16 In other files which wish to use YourModule:
17
18 use ModuleName qw(frobnicate); # import listed symbols
19 frobnicate ($left, $right) # calls YourModule::frobnicate
20
22 Exporter::Easy makes using Exporter easy. In its simplest case, it
23 allows you to drop the boilerplate code that comes with using Exporter,
24 so
25
26 require Exporter;
27 use base qw( Exporter );
28 use vars qw( @EXPORT );
29 @EXPORT = ( 'init' );
30
31 becomes
32
33 use Exporter::Easy ( EXPORT => [ 'init' ] );
34
35 and more complicated situations where you use tags to build lists and
36 more tags become easy, like this
37
38 use Exporter::Easy (
39 EXPORT => [qw( init :base )],
40 TAGS => [
41 base => [qw( open close )],
42 read => [qw( read sysread readline )],
43 write => [qw( print write writeline )],
44 misc => [qw( select flush )],
45 all => [qw( :base :read :write :misc)],
46 no_misc => [qw( :all !:misc )],
47 ],
48 OK => [qw( some other stuff )],
49 );
50
51 This will set @EXPORT, @EXPORT_OK, @EXPORT_FAIL and %EXPORT_TAGS in the
52 current package, add Exporter to that package's @ISA and do a "use
53 vars" on all the variables mentioned. The rest is handled as normal by
54 Exporter.
55
57 Put
58
59 use Exporter::Easy ( KEY => value, ...);
60
61 in your package. Arguments are passes as key-value pairs, the following
62 keys are available
63
64 TAGS
65 The value should be a reference to a list that goes like (TAG_NAME,
66 TAG_VALUE, TAG_NAME, TAG_VALUE, ...), where TAG_NAME is a string
67 and TAG_VALUE is a reference to an array of symbols and tags. For
68 example
69
70 TAGS => [
71 file => [ 'open', 'close', 'read', 'write'],
72 string => [ 'length', 'substr', 'chomp' ],
73 hash => [ 'keys', 'values', 'each' ],
74 all => [ ':file', ':string', ':hash' ],
75 some => [':all', '!open', ':hash'],
76 ]
77
78 This is used to fill the %EXPORT_TAGS in your package. You can
79 build tags from other tags - in the example above the tag "all"
80 will contain all the symbols from "file", "string" and "hash". You
81 can also subtract symbols and tags - in the example above, "some"
82 contains the symbols from all but with "open" removed and all the
83 symbols from "hash" removed.
84
85 The rule is that any symbol starting with a ':' is taken to be a
86 tag which has been defined previously (if it's not defined you'll
87 get an error). If a symbol is preceded by a '!' it will be
88 subtracted from the list, otherwise it is added.
89
90 If you try to redefine a tag you will also get an error.
91
92 All the symbols which occur while building the tags are
93 automatically added your package's @EXPORT_OK array.
94
95 OK The value should be a reference to a list of symbols and tags
96 (which will be exapanded). These symbols will be added to the
97 @EXPORT_OK array in your package. Using OK and and OK_ONLY together
98 will give an error.
99
100 OK_ONLY
101 The value should be a reference to a list of symbols and tags
102 (which will be exapanded). The @EXPORT_OK array in your package
103 will contains only these symbols.. This totally overrides the
104 automatic population of this array. If you just want to add some
105 symbols to the list that Exporter::Easy has automatically built
106 then you should use OK instead. Using OK_ONLY and OK together will
107 give an error.
108
109 EXPORT
110 The value should be a reference to a list of symbol names and tags.
111 Any tags will be expanded and the resulting list of symbol names
112 will be placed in the @EXPORT array in your package. The tag
113 created by the ALL key is not available at this stage.
114
115 FAIL
116 The value should be a reference to a list of symbol names and tags.
117 The tags will be expanded and the resulting list of symbol names
118 will be placed in the @EXPORT_FAIL array in your package. They will
119 also be added to the @EXPORT_OK list.
120
121 ALL The value should be the name of tag that doesn't yet exist. This
122 tag will contain a list of all symbols which can be exported.
123
124 ISA If you set this to 0 then Exporter will not be added to your @ISA
125 list.
126
127 VARS
128 If this is set to 1 or not provided then all $, @ and % variables
129 mentioned previously will be available to use in your package as if
130 you had done a "use vars" on them. If it's set to a reference to a
131 list of symbols and tags then only those symbols will be available.
132 If it's set to 0 then you'll have to do your own "use vars" in your
133 package.
134
136 We need take the information provided and build @EXPORT, @EXPORT_OK,
137 @EXPORT_FAIL and %EXPORT_TAGS in the calling package. We may also need
138 to build a tag with all of the symbols and to make all the variables
139 useable under strict.
140
141 The arguments are processed in the following order: TAGS, EXPORT, OK,
142 OK_ONLY and FAIL, ALL, VARS and finally ISA. This means you cannot use
143 the tag created by ALL anywhere except in VARS (although vars defaults
144 to using all symbols anyway).
145
147 Exporter is the grandaddy of all Exporter modules, and bundled with
148 Perl itself, unlike the rest of the modules listed here. Look at the
149 documentation for this module to see more explanation of the OK, EXPORT
150 and other variables.
151
152 Attribute::Exporter defines attributes which you use to mark which subs
153 and variables you want to export, and how.
154
155 Exporter::Simple also uses attributes to control the export of
156 functions and variables from your module.
157
158 Const::Exporter makes it easy to create a module that exports
159 constants.
160
161 Constant::Exporter is another module that makes it easy to create
162 modules that define and export constants.
163
164 Sub::Exporter is a "sophisticated exporter for custom-built routines";
165 it lets you provide generators that can be used to customise what gets
166 imported when someone uses your module.
167
168 Exporter::Tiny provides the same features as Sub::Exporter, but relying
169 only on core dependencies.
170
171 Exporter::Shiny is a shortcut for Exporter::Tiny that provides a more
172 concise notation for providing optional exports.
173
174 Exporter::Declare provides syntactic sugar to make the export status of
175 your functions part of their declaration. Kind of.
176
177 AppConfig::Exporter lets you export part of an AppConfig-based
178 configuration.
179
180 Exporter::Lexical lets you export lexical subs from your module.
181
182 Constant::Exporter::Lazy lets you write a module that exports function-
183 style constants, which are instantiated lazily.
184
185 Exporter::Auto will export everything from your module that it thinks
186 is a public function (name doesn't start with an underscore).
187
188 Class::Exporter lets you export class methods as regular subroutines.
189
190 Xporter is like Exporter, but with persistent defaults and auto-ISA.
191
193 <https://github.com/neilb/Exporter-Easy>
194
196 Written by Fergal Daly <fergal@esatclear.ie>.
197
199 Under the same license as Perl itself
200
201
202
203perl v5.32.1 2021-01-27 Exporter::Easy(3)