Module Foo::Barはのどこかにインストールされてい@INC
ます。
、then 、then、または@INC
を再帰的にチェックする以外に、モジュール自体からこれらのディレクトリにアクセスする方法はありますか?Foo
Bar
scripts
t
lib/scripts/findmeifyoucan.pl
たとえば、から特定のスクリプトを呼び出したいと思いますFoo/Bar.pm
。
Module Foo::Barはのどこかにインストールされてい@INC
ます。
、then 、then、または@INC
を再帰的にチェックする以外に、モジュール自体からこれらのディレクトリにアクセスする方法はありますか?Foo
Bar
scripts
t
lib/scripts/findmeifyoucan.pl
たとえば、から特定のスクリプトを呼び出したいと思いますFoo/Bar.pm
。
%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));