Exclude vendorarch and sitearch from FatNode and ModuleSender
[scpubgit/Object-Remote.git] / lib / Object / Remote / ModuleSender.pm
CommitLineData
542d5b5c 1package Object::Remote::ModuleSender;
2
3use Config;
4use File::Spec;
5use List::Util qw(first);
6use Moo;
7
8has dir_list => (is => 'lazy');
9
10sub _build_dir_list {
df8e0ca6 11 my %core = map +($_ => 1), grep $_, @Config{
12 qw(privlibexp archlibexp vendorarchexp sitearchexp)
13 };
14 [ grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, grep !$core{$_}, @INC ];
542d5b5c 15}
16
17sub source_for {
18 my ($self, $module) = @_;
7462160e 19 if (my $find = Object::Remote::FromData->can('find_module')) {
20 if (my $source = $find->($module)) {
21 return $source;
22 }
23 }
542d5b5c 24 my ($found) = first { -f $_ }
25 map File::Spec->catfile($_, $module),
26 @{$self->dir_list};
27 die "Couldn't find ${module} in remote \@INC. dir_list contains:\n"
28 .join("\n", @{$self->dir_list})
29 unless $found;
30 open my $fh, '<', $found or die "Couldn't open ${found} for ${module}: $!";
31 return do { local $/; <$fh> };
32}
33
341;