Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl6: implicit and explicit import

Tags:

import

raku

Is it possible to write a module in a way that when the module is used with no explicit import all subroutines are imported and when it is used with explicit import only theses explicit imported subroutines are available?

#!/usr/bin/env perl6
use v6;
use Bar::Foo;

# all subroutines are imported
sub-one();
sub-two();
sub-three();

#!/usr/bin/env perl6
use v6;
use Bar::Foo :sub-one, :sub-two;

sub-one();
sub-two();
# sub-three not imported
like image 553
sid_com Avatar asked May 03 '16 08:05

sid_com


1 Answers

Give your subs both the special label :DEFAULT as well as a dedicated one when exporting, eg

unit module Bar;
sub one is export(:DEFAULT, :one) { say "one" }
sub two is export(:DEFAULT, :two) { say "two" }

Now, you can import all of them with a plain use Bar, or can select specific ones via use Bar :one;

like image 135
Christoph Avatar answered Sep 24 '22 23:09

Christoph