Perl Moose - 如何部署我的类 pm 文件?
我正在尝试学习 Moose,并且需要知道如何正确部署我的类 pm 文件。
我的意思是我创建了一个Person.pm。
如果它与执行 use Person 的 main.pl 脚本位于同一文件夹中,我可以在主包中调用它吗?或者我是否必须进行 make 并将其部署到我的 @INC perl 模块位置才能使用该文件?
我希望在本地文件夹中创建 pm 类文件,然后简单地使用该文件夹中的程序 main.pl 调用它们。
我该怎么做呢?
I am trying to look into learning Moose and need to know how to properly deploy my class pm file.
What I mean is I created a Person.pm.
Can I call this in my main package if it is in the same folder as my main.pl script doing a use Person; or do I have to do a make and deploy it to my @INC perl modules location before being able to use the file?
I am hoping to create pm class files in my local folder and then simply call them with my program main.pl in that folder.
How would I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Perl 默认将
.
作为@INC
中的第一项,因此并排可以工作。如果您想更复杂一点,可以使用FindBin
和use lib
:现在将您的模块放在同一目录中的
lib/
中作为您的脚本,您的脚本会看到它们。这使您的库模块和脚本保持分离。如果您正在编写测试,则可以拥有一个t/
库,测试脚本的开头如下:并且您的测试也会在正确的位置查找库模块。
您还可以使用
PERL5OPT=-I/path/to/some/library
将该路径添加到您的@INC
,然后您就不需要使用lib
根本就没有。Perl does default to having
.
as the first item in@INC
, so side-by-side will work. If you want to be a little more sophisticated, you can useFindBin
anduse lib
:Now put your modules in
lib/
in the same directory as your script, and your script will see them. This keeps your library modules and your script(s) separated. If you're writing tests, you can have at/
library with the test scripts starting like this:And your tests will look in the right place for the library modules as well.
You can also use
PERL5OPT=-I/path/to/some/library
to add that path to your@INC
, and you then don't needuse lib
at all.