如果我要使用 Perl 进行纯 OO,我需要 Exporter 吗?

发布于 2024-07-12 07:58:54 字数 474 浏览 8 评论 0原文

文档(Exporter 和 perlmodlib)说:

作为一般规则,如果模块是 然后尝试面向对象 不导出任何内容。

但 perlmodlib 还说:

标准、捆绑模块全部 期望以明确定义的方式表现 相对于命名空间的方式 污染是因为他们使用 导出器模块。

所以我想知道,如果你采用 OO 并且不导出任何内容,你真的需要 Exporter 吗? 如果你不这样做,这是否意味着没有一个标准模块在这个意义上是严格的面向对象的,或者是否意味着它们EXPORT_OK某些事情,因为如果有人想继承你的模块,你需要这样做模块? (这是真的吗?)或者您是否需要 Exporter 只是为了能够使用 MyModule; ... = 新的 MyModule?

The docs (Exporter and perlmodlib) say:

As a general rule, if the module is
trying to be object oriented then
export nothing.

But then perlmodlib also says:

Standard, bundled modules are all
expected to behave in a well-defined
manner with respect to namespace
pollution because they use the
Exporter module.

So I wonder, if you go OO and export nothing, do you really need Exporter? If you don't, does that mean that none of the standard modules are strictly OO in this sense, or does it mean they EXPORT_OK some things because you need to do that if someone wants to inherit from your module? (Is that true?) Or do you need Exporter just to be able to use MyModule; ... = new MyModule?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-07-19 07:58:54

你是对的。 如果所有内容都被称为 OBJECT::sub() 或 $obj->sub(),那么应该没问题。

对于继承,您将需要使用@ISA,为此,您不应该需要导出器。

另外,您给出的第二个引用是关于导出到模块中的数据。

如果您对使用导出器导出的库使用:use libname ();,则保证不会导出任何内容。 这就是它可以用来防止名称空间污染的方式。 如果您按函数名称显式导出,则这些是您获得的唯一函数。

You are correct. If everything will be called OBJECT::sub() or $obj->sub(), you should be fine.

For inheritance, you're going to want to use @ISA, and for that, you shouldn't need exporter.

Also, the second quote you gave is in regards to exported data pouring into a module.

If you use: use libname (); against a lib that exports using the Exporter, you are guaranteed to export nothing. That's how it can be used to prevent namespace pollution. If you explicitly export by function name, those are the only functions you get.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文