Larry wrote:

On Sat, Apr 24, 2004 at 09:52:12AM +1000, Damian Conway wrote:
: My proposal for that issue is just:
: : module Bar;
: : use Foo «foo»;
: : sub foo is export {...}


That's on the right track, but has some difficulties, insofar as it's
not clear that the intent is to redefine "foo" retroactively rather
than actively.

Err. It's just a declaration that Bar has a subroutine named &foo and that that subroutine is exportable. The fact that that subroutine exists in Bar because it's imported from Foo is utterly orthogonal, isn't it?



And it doesn't necessarily work for variables

True. Just quietly, I would consider that a *feature*! ;-) But see below for a possible solution.


does it tell the "use" whether you were intending to import «foo»
as a package name or a lexical name.

This is, IMO, the real issue. But, as you ponder below, it's an issue of how the "imporation" (;-) from Foo is specified, not how the "exporation" from Bar is handled.



The main reason for separate declarations in normal use is to specify
whether you want to import lexically or packagely.  So a more minimal
approach is to allow

use Foo my &foo, my $foocount, our &bar;

for the normal declarations (ignoring re-exportation issues), and
then resort to ::= for renamings.

If we make lexical importation the default, that reduces to

use Foo «foo $foocount», our &bar;


This seems to be by far the least annoying approach.


Of course, for re-export you'd have to say

    use Foo my &foo is export,
            my $foocount is export(:MANDATORY),
            our &bar;


I don't see why. Import to- and export from- a module could (and probably should) be entirely orthogonal. So perhaps exportation should be via mixin:

use Foo «foo $foocount», our &bar;

     &foo      does export;
     $foocount does export(:MANDATORY);

     sub localsub does export {...}
     my $localvar does export;

     sub AUTOLOAD {...}         # implements &baz and &qux
     sub baz does export {...}  # stub for autoloaded sub


That separates the two concerns (import vs export) very cleanly, doesn't require much extra typing,seems to handle all kinds of referents (not just subroutines), and also supports exporting things that are not locally defined in *other* ways besides having been imported (such as things implemented as AUTOWHATEVERS).



Damian

Reply via email to