@@ -1541,10 +1541,10 @@ module like so:
1541
1541
= for code :lang<perl5>
1542
1542
use ModuleName qw{foo bar baz};
1543
1543
1544
- In Perl 6 one specifies the functions which are to be exported by using the
1545
- C < is export > role on the relevant subs and I < all > subs with this role are
1546
- then exported. Hence, the following module C < Bar > exports the subs C < foo >
1547
- and C < bar > but not C < baz > :
1544
+ In Perl 6 one specifies the functions which are to be exported by using
1545
+ the C < is export > role on the relevant subs; I < all > subs with this role
1546
+ are then exported. Hence, the following module C < Bar > exports the subs
1547
+ C < foo > and C < bar > but not C < baz > :
1548
1548
1549
1549
= begin code :solo
1550
1550
unit module Bar;
@@ -1566,11 +1566,11 @@ If one tries to use C<baz> an "Undeclared routine" error is raised at
1566
1566
compile time.
1567
1567
1568
1568
So, how does one recreate the Perl 5 behaviour of being able to
1569
- selectively import functions? For this one needs to define an C < EXPORT >
1570
- sub inside the module which specifies the functions to be exported and
1571
- remove the C < module Bar > statement.
1569
+ selectively import functions? By defining an C < EXPORT > sub inside the
1570
+ module which specifies the functions to be exported and removing the
1571
+ C < module Bar > statement.
1572
1572
1573
- The module C < Bar > now is merely a file called C < Bar.pm6 > with the
1573
+ The former module C < Bar > now is merely a file called C < Bar.pm6 > with the
1574
1574
following contents:
1575
1575
1576
1576
= begin code :preamble<no strict;>
@@ -1594,8 +1594,8 @@ sub baz($z) { say "baz, $z" }
1594
1594
= end code
1595
1595
1596
1596
Note that the subs are no longer explicitly exported via the C < is
1597
- export > role. We are defining an C < EXPORT > sub which specifies the subs
1598
- in the module we want to be available for export and then we are
1597
+ export > role, but by an C < EXPORT > sub which specifies the subs
1598
+ in the module we want to make available for export and then we are
1599
1599
populating a hash containing the subs which will actually be exported.
1600
1600
The C < @import-list > is set by the C < use > statement in the calling code
1601
1601
thus allowing us to selectively import the subs made available by the
@@ -1608,7 +1608,7 @@ calling code:
1608
1608
use Bar <foo>;
1609
1609
foo(1); #=> "foo 1"
1610
1610
1611
- Here we see that even though C < bar > is able to be exported , if we don't
1611
+ Here we see that even though C < bar > is exportable , if we don't
1612
1612
explicitly import it, it's not available for use. Hence this causes an
1613
1613
"Undeclared routine" error at compile time:
1614
1614
@@ -1617,33 +1617,34 @@ use Bar <foo>;
1617
1617
foo(1);
1618
1618
bar(5); #!> "Undeclared routine: bar used at line 3"
1619
1619
1620
- however , this will work
1620
+ However , this will work
1621
1621
1622
1622
= for code :skip-test
1623
1623
use Bar <foo bar>;
1624
1624
foo(1); #=> "foo 1"
1625
1625
bar(5); #=> "bar 5"
1626
1626
1627
- Note also that C < baz > remains unimportable even if specified in the C < use >
1628
- statement:
1627
+ Note also that C < baz > remains unimportable even if specified in the
1628
+ C < use > statement:
1629
1629
1630
1630
= for code :skip-test
1631
1631
use Bar <foo bar baz>;
1632
1632
baz(3); #!> "Undeclared routine: baz used at line 2"
1633
1633
1634
- In order to get this to work, one obviously has to jump through many hoops.
1635
- In the standard use-case where one specifies the functions to be exported
1636
- via the C < is export > role, Perl 6 automatically creates the C < EXPORT > sub in
1637
- the correct manner for you, so one should consider very carefully whether or
1638
- not writing one's own C < EXPORT > routine is worthwhile.
1634
+ In order to get this to work, one obviously has to jump through many
1635
+ hoops. In the standard use-case where one specifies the functions to be
1636
+ exported via the C < is export > role, Perl 6 automatically creates the
1637
+ C < EXPORT > sub in the correct manner for you, so one should consider very
1638
+ carefully whether or not writing one's own C < EXPORT > routine is
1639
+ worthwhile.
1639
1640
1640
1641
= head2 Importing groups of specific functions from a module
1641
1642
1642
1643
If you would like to export groups of functions from a module, you just
1643
- need to assign names to the groups, and the rest will work automagically.
1644
- When you specify C < is export > in a sub declaration, you are in fact adding
1645
- this subroutine to the C < :DEFAULT > export group. But you can add a subroutine
1646
- to another group, or to multiple groups:
1644
+ need to assign names to the groups, and the rest will work
1645
+ automagically. When you specify C < is export > in a sub declaration, you
1646
+ are in fact adding this subroutine to the C < :DEFAULT > export group. But
1647
+ you can add a subroutine to another group, or to multiple groups:
1647
1648
1648
1649
= for code :solo
1649
1650
unit module Bar;
0 commit comments