Skip to content

Commit

Permalink
Add section on importing groups of subs
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jun 4, 2018
1 parent a91474a commit 0ac7f14
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/Language/5to6-nutshell.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,30 @@ via the C<is export> role, Perl 6 automatically creates the C<EXPORT> sub in
the correct manner for you, so one should consider very carefully whether or
not writing one's own C<EXPORT> routine is worthwhile.
=head2 Importing groups of specific functions from a module
If you would like to export groups of functions from a module, you just
need to assign names to the groups, and the rest will work automagically.
When you specify C<is export> in a sub declaration, you are in fact adding
this subroutine to the C<:DEFAULT> export group. But you can add a subroutine
to another group, or to multiple groups:
=for code :skip-test
unit module Bar;
sub foo() is export { } # added by default to :DEFAULT
sub bar() is export(:FNORBL) { } # added to the FNORBL export group
sub baz() is export(:DEFAULT:FNORBL) { } # added to both
So now you can use the C<Bar> module like this:
=for code :skip-test
use Bar; # imports foo / baz
use Bar :FNORBL; # imports bar / baz
use Bar :ALL; # imports foo / bar / baz
Note that C<:ALL> is an auto-generated group that encompasses B<all>
subroutines that have an C<is export> trait.
=head1 Core modules
=head3 C<Data::Dumper>
Expand Down

0 comments on commit 0ac7f14

Please sign in to comment.