Skip to content

Commit 50c6fd1

Browse files
committed
Document EXPORT behaviour with precompilation
- Toss example of evil hack as it won't work right with precomp - Document the precompilation caveat and how to deal with it per rakudo/rakudo#1371 (comment)
1 parent 2eda02e commit 50c6fd1

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

doc/Language/modules.pod6

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -356,24 +356,18 @@ passing C<:DEFAULT> to C<use> along with your positional parameters.
356356
shy(); # FAIL - won't be imported
357357
=end code
358358
359-
You can combine `EXPORT` with type captures for interesting
360-
effect. This example creates a `?` postfix which will only work on
361-
L<Cool>s.
359+
Sub C<EXPORT> is B<NOT> called each time a module a C<use> is done. The results
360+
of import are precompiled and serialized along with the module, so it will
361+
be executed once per compilation.
362362
363-
=begin code :skip-test
364-
# lib/MakeQuestionable.pm
365-
sub EXPORT(::Questionable) {
366-
my multi postfix:<?>(Questionable $_) { .so };
367-
%(
368-
'&postfix:<?>' => &postfix:<?>,
369-
)
363+
sub EXPORT ($thing) {
364+
# WRONG! $thing will only be taken once during pre-compilation
365+
%( '&thing' => &say.assuming($thing) )
370366
}
371-
=end code
372367
373-
=begin code :skip-test
374-
use MakeQuestionable Cool;
375-
say ( 0?, 1?, {}?, %( a => "b" )? ).join(' '); # OUTPUT: «False True False True␤»
376-
=end code
368+
If your code requires C<EXPORT> to be called for each C<use>, you can disable
369+
your module's precompilation with
370+
L«C<no precompilation> pragma|/language/pragmas#index-entry-precompilation-precompilation»
377371
378372
=head2 Introspection
379373

0 commit comments

Comments
 (0)