views:

25

answers:

1

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.

+2  A: 

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));
Ether
That's great, thanks. One other question: I'm using Module::Build, and none of the `scripts` or `t` directories show up there. I suppose I need to configure `Build.pl` to install those as well? Or are they installed to another location, other than the source directory?
Pedro Silva
@Pedro: I can't say for certain; I haven't used that lib for quite a while. I think a similar question may have been asked here, though (or you can ask it yourself as a new one).
Ether