问题描述
使用require
加载模块(ABC
)在发行版的一个模块中工作,而在发行版的另一个模块中失败.用require
加载ABC
一次失败的原因可能是什么?
Loading a module (ABC
) with require
works in one module of a distribution while it fails in another module of the distribution.What could be the reason that loading ABC
with require
fails in one place?
require Name::ABC;
my $new = Name::ABC.new(); # dies: You cannot create an instance of this type (ABC)
perl6 -v
This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.
所需的模块: App :: DBBrowser :: Subqueries
App :: DBBrowser: :Union ,第80行:确定*
App::DBBrowser::Union, line 80: OK *
App :: DBBrowser: :加入,第66和191行:确定*
App::DBBrowser::Join, lines 66 and 191: OK *
应用程序:: DBBrowser :: Table :: Extensions ,第49行:OK *
App::DBBrowser::Table::Extensions, line 49: OK *
App :: DBBrowser ,第690行:您无法创建此类型的实例(子查询)*
App::DBBrowser, line 690: You cannot create an instance of this type (Subqueries) *
App :: DBBrowser: :CreateTable ,第112行:您无法创建这种类型的实例(子查询)*
App::DBBrowser::CreateTable, line 112: You cannot create an instance of this type (Subqueries) *
*版本0.0.1
推荐答案
$ cat XXX.pm6
unit class XXX;
$ cat ZZZ.pm6
module ZZZ {
require XXX;
XXX.new;
say "OK";
}
$ perl6 -I. -e 'use ZZZ;'
===SORRY!===
You cannot create an instance of this type (XXX)
从文档:
您正在执行模块的运行时加载,同时还希望该模块的符号在编译时存在.相反,您应该使用间接名称查找(如先前链接的文档页面底部所示):
You are doing a runtime load of a module while also expecting the symbols for that module to exist at compile time. Instead you should use indirect name lookup (as shown at the bottom of the documentation page linked earlier):
$ cat XXX.pm6
unit class XXX;
$ cat ZZZ.pm6
module ZZZ {
require XXX;
::("XXX").new;
say "OK";
}
$ perl6 -I. -e 'use ZZZ;'
OK
这篇关于在某些地方`require`不起作用的原因可能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!