Perl Moose - 如何部署我的类 pm 文件?

发布于 2024-11-24 00:30:12 字数 253 浏览 3 评论 0原文

我正在尝试学习 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 技术交流群。

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

发布评论

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

评论(1

℉服软 2024-12-01 00:30:12

Perl 默认将 . 作为 @INC 中的第一项,因此并排可以工作。如果您想更复杂一点,可以使用 FindBinuse lib

#!/usr/bin/env perl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";

# Main program continues...

现在将您的模块放在同一目录中的 lib/ 中作为您的脚本,您的脚本会看到它们。这使您的库模块和脚本保持分离。如果您正在编写测试,则可以拥有一个 t/ 库,测试脚本的开头如下:

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Test::More;
# other test modules, your plan, etc.

并且您的测试也会在正确的位置查找库模块。

您还可以使用 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 use FindBin and use lib:

#!/usr/bin/env perl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";

# Main program continues...

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 a t/ library with the test scripts starting like this:

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Test::More;
# other test modules, your plan, etc.

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 need use lib at all.

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