File Coverage

blib/lib/Object/Remote/ModuleSender.pm
Criterion Covered Total %
statement 34 39 87.1
branch 7 8 87.5
condition n/a
subroutine 8 13 61.5
pod 0 1 0.0
total 49 61 80.3


line stmt bran cond sub pod time code
1             package Object::Remote::ModuleSender;
2              
3 14     14   85 use Object::Remote::Logging qw( :log :dlog );
  14         26  
  14         81  
4 14     14   118 use Config;
  14         37  
  14         607  
5 14     14   74 use File::Spec;
  14         41  
  14         423  
6 14     14   93 use List::Util qw(first);
  14         28  
  14         1183  
7 14     14   80 use Moo;
  14         25  
  14         78  
8              
9             has dir_list => (is => 'lazy');
10              
11             sub _build_dir_list {
12             my %core = map +($_ => 1), grep $_, @Config{
13 7     7   423 qw(privlibexp archlibexp vendorarchexp sitearchexp)
14             };
15 7     0   231 DlogS_trace { "dir list built in ModuleSender: $_" } [ grep !$core{$_}, @INC ];
  0         0  
16             }
17              
18             sub source_for {
19 15     15 0 56 my ($self, $module) = @_;
20 15     0   270 log_debug { "locating source for module '$module'" };
  0         0  
21 15 100       385 if (my $find = Object::Remote::FromData->can('find_module')) {
22 7 100       46 if (my $source = $find->($module)) {
23 6     0   81 Dlog_trace { "source of '$module' was found by Object::Remote::FromData" };
  0         0  
24 6         121 return $source;
25             }
26             }
27 9     0   149 log_trace { "Searching for module in library directories" };
  0         0  
28 16     16   894 my ($found) = first { -f $_ }
29             map File::Spec->catfile($_, $module),
30 9         104 @{$self->dir_list};
  9         221  
31             die "Can't locate ${module} in \@INC. (on remote host) dir_list contains:\n"
32 9 100       57 .join("\n", @{$self->dir_list})
  1         21  
33             unless $found;
34 8     0   66 log_debug { "found '$module' at '$found'" };
  0         0  
35 8 50       499 open my $fh, '<', $found or die "Couldn't open ${found} for ${module}: $!";
36 8         21 return do { local $/; <$fh> };
  8         49  
  8         428  
37             }
38              
39             1;