Perl6:隐式和显式导入
Perl6: implicit and explicit import
是否有可能以这样一种方式编写模块:当模块是 use
d 且没有显式导入时,所有子例程都被导入,而当它是 use
d 且显式导入时,仅导入这些显式导入的子程序可用吗?
#!/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
在导出时为您的订阅者提供特殊标签 :DEFAULT
和专用标签,例如
unit module Bar;
sub one is export(:DEFAULT, :one) { say "one" }
sub two is export(:DEFAULT, :two) { say "two" }
现在,您可以使用普通 use Bar
导入所有这些,或者可以 select 通过 use Bar :one
;
导入特定的
是否有可能以这样一种方式编写模块:当模块是 use
d 且没有显式导入时,所有子例程都被导入,而当它是 use
d 且显式导入时,仅导入这些显式导入的子程序可用吗?
#!/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
在导出时为您的订阅者提供特殊标签 :DEFAULT
和专用标签,例如
unit module Bar;
sub one is export(:DEFAULT, :one) { say "one" }
sub two is export(:DEFAULT, :two) { say "two" }
现在,您可以使用普通 use Bar
导入所有这些,或者可以 select 通过 use Bar :one
;