Perl 如何动态获取模块的路径?
如果我有这样的东西: 在一些script.pl中:Perl 如何动态获取模块的路径?,perl,module,Perl,Module,如果我有这样的东西: 在一些script.pl中: #code here my $result = $class->foo(); # extra code here 在该类的模块中: package Test::A::Foo; use parent Test::A; sub foo { # code here } 在模块内执行代码时,如何获得Test::A::Foo驻留的确切文件路径?它不是工作目录,因为我正在运行script.pl,它调用$clas
#code here
my $result = $class->foo();
# extra code here
在该类的模块中:
package Test::A::Foo;
use parent Test::A;
sub foo {
# code here
}
在模块内执行代码时,如何获得
Test::A::Foo
驻留的确切文件路径?它不是工作目录,因为我正在运行script.pl
,它调用$class->foo
,因此如何获取实际路径?内置哈希%INC
包含使用require
或do
加载的模块文件的解析路径
Test::A::Foo
的pm
文件的位置在$INC{'Test/A/Foo.pm'}
差不多
$INC{ (__PACKAGE__ =~ s|::|/|gr) . '.pm' }
你应该做你需要的但是我怎么才能得到
Test::A::Foo
?通过\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu?因为我想为任何模块制作