1Export::Attrs(3pm) User Contributed Perl Documentation Export::Attrs(3pm)
2
3
4
6 Export::Attrs - The Perl 6 'is export(...)' trait as a Perl 5 attribute
7
9 This document describes Export::Attrs version v0.1.0
10
12 package Some::Module;
13 use Export::Attrs;
14
15 # Export &foo by default, when explicitly requested,
16 # or when the ':ALL' export set is requested...
17
18 sub foo :Export(:DEFAULT) {
19 print "phooo!";
20 }
21
22
23 # Export &var by default, when explicitly requested,
24 # or when the ':bees', ':pubs', or ':ALL' export set is requested...
25 # the parens after 'is export' are like the parens of a qw(...)
26
27 sub bar :Export(:DEFAULT :bees :pubs) {
28 print "baaa!";
29 }
30
31
32 # Export &baz when explicitly requested
33 # or when the ':bees' or ':ALL' export set is requested...
34
35 sub baz :Export(:bees) {
36 print "baassss!";
37 }
38
39
40 # Always export &qux
41 # (no matter what else is explicitly or implicitly requested)
42
43 sub qux :Export(:MANDATORY) {
44 print "quuuuuuuuux!";
45 }
46
47
48 # Allow the constant $PI to be exported when requested...
49
50 use Readonly;
51 Readonly our $PI :Export => 355/113;
52
53
54 # Allow the variable $EPSILON to be always exported...
55
56 our $EPSILON :Export( :MANDATORY ) = 0.00001;
57
58
59 sub IMPORT {
60 # This subroutine is called when the module is used (as usual),
61 # but it is called after any export requests have been handled.
62 };
63
65 NOTE: This module is a fork of Perl6::Export::Attrs created to restore
66 compatibility with Perl6::Export::Attrs version 0.0.3.
67
68 Implements a Perl 5 native version of what the Perl 6 symbol export
69 mechanism will look like (with some unavoidable restrictions).
70
71 It's very straightforward:
72
73 · If you want a subroutine or package variable to be capable of being
74 exported (when explicitly requested in the "use" arguments), you
75 mark it with the ":Export" attribute.
76
77 · If you want a subroutine or package variable to be automatically
78 exported when the module is used (without specific overriding
79 arguments), you mark it with the ":Export(:DEFAULT)" attribute.
80
81 · If you want a subroutine or package variable to be automatically
82 exported when the module is used (even if the user specifies
83 overriding arguments), you mark it with the ":Export(:MANDATORY)"
84 attribute.
85
86 · If the subroutine or package variable should also be exported when
87 particular export groups are requested, you add the names of those
88 export groups to the attribute's argument list.
89
90 That's it.
91
92 "IMPORT" blocks
93 Perl 6 replaces the "import" subroutine with an "IMPORT" block. It's
94 analogous to a "BEGIN" or "END" block, except that it's executed every
95 time the corresponding module is "use"'d.
96
97 The "IMPORT" block is passed the argument list that was specified on
98 the "use" line that loaded the corresponding module, minus the
99 arguments that were used to specify exports.
100
101 Note that, due to limitations in Perl 5, the "IMPORT" block provided by
102 this module must be terminated by a semi-colon, unless it is the last
103 statement in the file.
104
106 %s does not export: %s\nuse %s failed
107 You tried to import the specified subroutine or package variable,
108 but the module didn't export it. Often caused by a misspelling, or
109 forgetting to add an ":Export" attribute to the definition of the
110 subroutine or variable in question.
111
112 Bad tagset in :Export attribute at %s line %s: [%s]
113 You tried to import a collection of items via a tagset, but the
114 module didn't export any subroutines under that tagset. Is the
115 tagset name misspelled (maybe you forgot the colon?).
116
117 Can't export lexical %s variable at %s
118 The module can only export package variables. You applied the
119 ":Export" marker to a non-package variable (almost certainly to a
120 lexical). Change the variable's "my" declarator to an "our".
121
122 Can't export anonymous subroutine at %s
123 Although you can apply the ":Export" marker to an anonymous
124 subroutine, it rarely makes any sense to do so, since that
125 subroutine can't be exported without a name to export it as. Either
126 give the subroutine a name, or make sure it's aliased to a named
127 typeglob at compile-time (or, at least, before it's exported).
128
130 Export::Attrs requires no configuration files or environment variables.
131
133 This module requires the Attribute::Handlers module to handle the
134 attributes.
135
137 This module cannot be used with the Memoize CPAN module, because
138 memoization replaces the original subroutine with a wrapper. Because
139 the ":Export" attribute is applied to the original (not the wrapper),
140 the memoized wrapper is not found by the exporter mechanism.
141
143 Note that the module does not support exporting lexical variables,
144 since there is no way for the exporter mechanism to determine the name
145 of a lexical and hence to export it.
146
147 Nor does this module support the numerous addition export modes that
148 Perl 6 offers, such as export-as-lexical or export-as-state.
149
151 Bugs / Feature Requests
152 Please report any bugs or feature requests through the issue tracker at
153 <https://github.com/powerman/perl-Export-Attrs/issues>. You will be
154 notified automatically of any progress on your issue.
155
156 Source Code
157 This is open source software. The code repository is available for
158 public review and contribution under the terms of the license. Feel
159 free to fork the repository and submit pull requests.
160
161 <https://github.com/powerman/perl-Export-Attrs>
162
163 git clone https://github.com/powerman/perl-Export-Attrs.git
164
165 Resources
166 · MetaCPAN Search
167
168 <https://metacpan.org/search?q=Export-Attrs>
169
170 · CPAN Ratings
171
172 <http://cpanratings.perl.org/dist/Export-Attrs>
173
174 · AnnoCPAN: Annotated CPAN documentation
175
176 <http://annocpan.org/dist/Export-Attrs>
177
178 · CPAN Testers Matrix
179
180 <http://matrix.cpantesters.org/?dist=Export-Attrs>
181
182 · CPANTS: A CPAN Testing Service (Kwalitee)
183
184 <http://cpants.cpanauthors.org/dist/Export-Attrs>
185
187 Alex Efros <powerman@cpan.org>
188
189 Damian Conway <DCONWAY@cpan.org>
190
192 This software is Copyright (c) 2016 by Alex Efros <powerman@cpan.org>.
193
194 Copyright (c) 2005,2015 Damian Conway <DCONWAY@cpan.org>. All rights
195 reserved.
196
197 This module is free software; you can redistribute it and/or modify it
198 under the same terms as Perl itself.
199
200
201
202perl v5.32.0 2020-07-28 Export::Attrs(3pm)