Perl/mod_perl:将使用的模块映射到带有特殊字符的路径

发布于 2024-11-01 05:35:18 字数 752 浏览 2 评论 0原文


也许我的问题很简单,但我在文档中找不到答案,我希望有人可以提供帮助。

问:将文件名和文件系统路径映射到use'd / require'd模块以及用于的名称的规则是什么>package 声明,特别是当使用点或逗号等非标准符号时?如果能找到与这些场景相关的 mod_perl 的 PerlModulePerlRequire Apache 指令的类似答案,那就太好了。

作为一个具体的例子,我有一个 mod_perl 项目,位于带有点和逗号的路径中,例如

/var/www/projects/my.awesome.project,with,comma/code
and I have to load in Apache's conf file the code of a module:

PerlModule my.awesome.project,with,comma::code::MyModule

我还必须声明我的包

package my.awesome.project,with,comma::code::MyModule;

(我的自定义路径之一从 @INC 指向 /var/www/projects)

当然这是行不通的。这些路径必须映射到其他路径。或者根本不可能,每个人都必须使用仅包含字母数字符号和下划线的路径?

预先感谢您的任何帮助/回答。

Probably my question is a simple one, but I can't find an answer in docs and I hope someone could help.

Q.: Which are the rules of mapping filenames and filesystem paths to use'd / require'd modules and the names used for package declarations, especially when there are used non-standard symbols like dots or commas? It also would be nice to find out the similar answer for mod_perl's PerlModule and PerlRequire Apache directives related to these scenarios.

As a concrete examle, I have a mod_perl project located in a path with dots and commas like

/var/www/projects/my.awesome.project,with,comma/code

and I have to load in Apache's conf file the code of a module:

PerlModule my.awesome.project,with,comma::code::MyModule

I also have to declare my package like

package my.awesome.project,with,comma::code::MyModule;

(one of my custom paths from @INC points to /var/www/projects)

Of course this doesn't work. These paths must be mapped to something else. Or isn't it possible at all and everyone have to use paths containg only alphanumeric symbols and underscores?

Thank you in advance for any help/answer.

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

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

发布评论

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

评论(1

影子的影子 2024-11-08 05:35:18

Perl 包名称是标识符,这意味着它们必须以字母或下划线开头,并且仅包含字母、数字和下划线。它们也可以是由 :: 分隔的多个标识符。唯一的文件名映射是 :: 转换为 / (或任何系统目录分隔符)。包名称中不允许使用逗号和句点。

@INC 没有这个限制,所以你可以将 /var/www/projects/my.awesome.project,with,comma 添加到其中,然后将包命名为 code::MyModule。但您可能最好只使用字母数字和下划线作为目录名称。

Perl package names are identifiers, which means they must start with a letter or underscore, and contain only letters, numbers, and underscore. They can also be multiple identifiers separated by ::. The only filename mapping is that :: gets converted to / (or whatever the system directory separator is). Commas and periods are not allowed in package names.

@INC doesn't have that restriction, so you could add /var/www/projects/my.awesome.project,with,comma to it and then name the package code::MyModule. But you're probably better off just sticking with alphanumerics and underscores for your directory names.

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