如何访问模块根安装目录中的子目录(t、脚本)?

发布于 2024-09-06 08:50:27 字数 285 浏览 1 评论 0原文

模块 Foo::Bar 已安装在 @INC 中的某个位置。

除了递归地检查 @INC 中的 FooBarscriptst 之外>,有没有办法从模块本身访问这些目录

例如,我想从 Foo/Bar.pm 调用 lib/scripts/findmeifyoucan.pl 中的特定脚本。

Module Foo::Bar has been installed somewhere in @INC.

Other than recursively checking @INC for Foo, then Bar, then scripts or t, is there a way of accessing those directories from the module itself?

For example, I would like to call a particular script in lib/scripts/findmeifyoucan.pl from Foo/Bar.pm.

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

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

发布评论

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

评论(1

缱绻入梦 2024-09-13 08:50:27

您可以通过使用 %INC 来查找相关代码所在的位置,从而找到它相对于相关代码的位置:

package Foo::Bar;
# this code lives in ...something.../lib/Foo/Bar.pm

package Unrelated;

use File::Spec;
use Foo::Bar;

my $filename = 'Foo/Bar.pm';
(my $libpath = $INC{$filename}) =~ s#/\Q$filename\E$##g; ## strip / and filename
my $script = File::Spec->catfile($libpath, qw(scripts findmeifyoucan.pl));

You can find it relative to the related code, by using %INC to find where the related code lives:

package Foo::Bar;
# this code lives in ...something.../lib/Foo/Bar.pm

package Unrelated;

use File::Spec;
use Foo::Bar;

my $filename = 'Foo/Bar.pm';
(my $libpath = $INC{$filename}) =~ s#/\Q$filename\E$##g; ## strip / and filename
my $script = File::Spec->catfile($libpath, qw(scripts findmeifyoucan.pl));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文