Hi Tom,

>   use Bar :DEFAULT;
> 
> but this does not:
> 
>   use Bar <foo>;
> 
> So is S11 in error!!

That might not necessarily be the case (however S11 certainly isn't clear
about exactly how to import selected routines while `use`-ing a module).
All subs/methods that are marked with `is export` are exported by default,
thus there's actually no need to import anything, hence:

    use Bar;

will ensure that the foo() routine is available within the scope of the
`doit.pl` script.

>From what I can gather from S11, is that if one wants to override the
default behaviour of importing into the current namespace everything which
is exported by the module, then an EXPORT sub needs to be defined.  AFAICT
this is what the error:

    no EXPORT sub, but you provided positional argument in the 'use' statement

is trying to tell you.

Nevertheless, I've not been able to work out how to create an EXPORT sub
which does the Right Thing(TM).  Reading 'Perl6/Grammar.nqp' in the Rakudo
sources shows that a sub by the name of `EXPORT` is expected which returns
an `EnumMap`, which I suspect contains the names of the subs/methods to be
exported.  I'm fairly sure this is getting much too low-level for the
current use-case.  Also, sharing this information might simply be muddying
the waters somewhat, so in order that you can get further with what you're
trying to do, your example will work with the following code:

============== Bar.pm ==============
module Bar;

use v6;

sub foo($a, $b, $c) is export {}

# vim: expandtab shiftwidth=4 ft=perl6
====================================

============= doit.pl ==============
use v6;

use lib <.>;
use Bar;
my @t = foo(1, 2, 3);

# vim: expandtab shiftwidth=4 ft=perl6
====================================

BTW: please don't use the shortcut 'v6;': AFAIU it's been deprecated in
favour of 'use v6;'

Hope this helps a bit.

Cheers,

Paul

Reply via email to