在某些地方`require`不起作用的原因可能是什么?

编程入门 行业动态 更新时间:2024-10-19 21:31:14
本文介绍了在某些地方`require`不起作用的原因可能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用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)

从文档:

require加载compunit并在运行时导入确定的符号.

require loads a compunit and imports definite symbols at runtime.

您正在执行模块的运行时加载,同时还希望该模块的符号在编译时存在.相反,您应该使用间接名称查找(如先前链接的文档页面底部所示):

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`不起作用的原因可能是什么?

本文发布于:2023-11-28 07:02:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   原因   地方   在某些   require

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!