1 package Object::Remote::ModuleSender;
3 use Object::Remote::Logging qw( :log :dlog );
6 use List::Util qw(first);
9 has dir_list => (is => 'lazy');
12 my %core = map +($_ => 1), grep $_, @Config{
13 qw(privlibexp archlibexp vendorarchexp sitearchexp)
15 DlogS_trace { "dir list built in ModuleSender: $_" } [ grep !$core{$_}, @INC ];
19 my ($self, $module) = @_;
20 log_debug { "locating source for module '$module'" };
21 if (my $find = Object::Remote::FromData->can('find_module')) {
22 if (my $source = $find->($module)) {
23 Dlog_trace { "source of '$module' was found by Object::Remote::FromData" };
27 log_trace { "Searching for module in library directories" };
28 my ($found) = first { -f $_ }
29 map File::Spec->catfile($_, $module),
31 die "Couldn't find ${module} in remote \@INC. dir_list contains:\n"
32 .join("\n", @{$self->dir_list})
34 log_debug { "found '$module' at '$found'" };
35 open my $fh, '<', $found or die "Couldn't open ${found} for ${module}: $!";
36 return do { local $/; <$fh> };