1Perl6::Export::Attrs(3)User Contributed Perl DocumentatioPnerl6::Export::Attrs(3)
2
3
4
6 Perl6::Export::Attrs - The Perl 6 'is export(...)' trait as a Perl 5
7 attribute
8
10 This document describes Perl6::Export::Attrs version 0.000006
11
13 package Some::Module;
14 use Perl6::Export::Attrs;
15
16 # Export &foo by default, when explicitly requested,
17 # or when the ':ALL' export set is requested...
18
19 sub foo :Export(:DEFAULT) {
20 print "phooo!";
21 }
22
23
24 # Export &var by default, when explicitly requested,
25 # or when the ':bees', ':pubs', or ':ALL' export set is requested...
26 # the parens after 'is export' are like the parens of a qw(...)
27
28 sub bar :Export(:DEFAULT :bees :pubs) {
29 print "baaa!";
30 }
31
32
33 # Export &baz when explicitly requested
34 # or when the ':bees' or ':ALL' export set is requested...
35
36 sub baz :Export(:bees) {
37 print "baassss!";
38 }
39
40
41 # Always export &qux
42 # (no matter what else is explicitly or implicitly requested)
43
44 sub qux :Export(:MANDATORY) {
45 print "quuuuuuuuux!";
46 }
47
48
49 # Allow the constant $PI to be exported when requested...
50
51 use Readonly;
52 Readonly our $PI :Export => 355/113;
53
54
55 # Allow the variable $EPSILON to be always exported...
56
57 our $EPSILON :Export( :MANDATORY ) = 0.00001;
58
59
60 sub IMPORT {
61 # This subroutine is called when the module is used (as usual),
62 # but it is called after any export requests have been handled.
63 };
64
66 Implements a Perl 5 native version of what the Perl 6 symbol export
67 mechanism will look like (with some unavoidable restrictions).
68
69 It's very straightforward:
70
71 • If you want a subroutine or package variable to be capable of being
72 exported (when explicitly requested in the "use" arguments), you
73 mark it with the ":Export" attribute.
74
75 • If you want a subroutine or package variable to be automatically
76 exported when the module is used (without specific overriding
77 arguments), you mark it with the ":Export(:DEFAULT)" attribute.
78
79 • If you want a subroutine or package variable to be automatically
80 exported when the module is used (even if the user specifies
81 overriding arguments), you mark it with the ":Export(:MANDATORY)"
82 attribute.
83
84 • If the subroutine or package variable should also be exported when
85 particular export groups are requested, you add the names of those
86 export groups to the attribute's argument list.
87
88 That's it.
89
90 "IMPORT" blocks
91 Perl 6 replaces the "import" subroutine with an "IMPORT" block. It's
92 analogous to a "BEGIN" or "END" block, except that it's executed every
93 time the corresponding module is "use"'d.
94
95 The "IMPORT" block is passed the argument list that was specified on
96 the "use" line that loaded the corresponding module, minus the
97 arguments that were used to specify exports.
98
99 Note that, due to limitations in Perl 5, the "IMPORT" block provided by
100 this module must be terminated by a semi-colon, unless it is the last
101 statement in the file.
102
104 %s does not export: %s\nuse %s failed
105 You tried to import the specified subroutine or package variable,
106 but the module didn't export it. Often caused by a misspelling, or
107 forgetting to add an ":Export" attribute to the definition of the
108 subroutine or variable in question.
109
110 Bad tagset in :Export attribute at %s line %s: [%s]
111 You tried to import a collection of items via a tagset, but the
112 module didn't export any subroutines under that tagset. Is the
113 tagset name misspelled (maybe you forgot the colon?).
114
115 Can't export lexical %s variable at %s
116 The module can only export package variables. You applied the
117 ":Export" marker to a non-package variable (almost certainly to a
118 lexical). Change the variable's "my" declarator to an "our".
119
120 Can't export anonymous subroutine at %s
121 Although you can apply the ":Export" marker to an anonymous
122 subroutine, it rarely makes any sense to do so, since that
123 subroutine can't be exported without a name to export it as. Either
124 give the subroutine a name, or make sure it's aliased to a named
125 typeglob at compile-time (or, at least, before it's exported).
126
128 Perl6::Export::Attrs requires no configuration files or environment
129 variables.
130
132 This module requires the Attribute::Handlers module to handle the
133 attributes.
134
136 This module cannot be used with the Memoize CPAN module, because
137 memoization replaces the original subroutine with a wrapper. Because
138 the ":Export" attribute is applied to the original (not the wrapper),
139 the memoized wrapper is not found by the exporter mechanism.
140
142 No bugs have been reported.
143
144 Note that the module does not support exporting lexical variables,
145 since there is no way for the exporter mechanism to determine the name
146 of a lexical and hence to export it.
147
148 Nor does this module support the numerous addition export modes that
149 Perl 6 offers, such as export-as-lexical or export-as-state.
150
151 Please report any bugs or feature requests to
152 "bug-perl6-export-attrs@rt.cpan.org", or through the web interface at
153 <http://rt.cpan.org>.
154
156 Damian Conway "<DCONWAY@cpan.org>"
157
159 Copyright (c) 2005, Damian Conway "<DCONWAY@cpan.org>". All rights
160 reserved.
161
162 This module is free software; you can redistribute it and/or modify it
163 under the same terms as Perl itself.
164
166 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
167 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
168 WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
169 PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
170 EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
171 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
172 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
173 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
174 NECESSARY SERVICING, REPAIR, OR CORRECTION.
175
176 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
177 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
178 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
179 TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
180 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
181 SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
182 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
183 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
184 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
185 DAMAGES.
186
187
188
189perl v5.34.0 2021-07-22 Perl6::Export::Attrs(3)