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   203 use Object::Remote::Logging qw( :log :dlog );
  14         17  
  14         72  
4 14     14   72 use Config;
  14         19  
  14         513  
5 14     14   53 use File::Spec;
  14         17  
  14         348  
6 14     14   48 use List::Util qw(first);
  14         19  
  14         1198  
7 14     14   54 use Moo;
  14         15  
  14         113  
8              
9             has dir_list => (is => 'lazy');
10              
11             sub _build_dir_list {
12             my %core = map +($_ => 1), grep $_, @Config{
13 7     7   2217 qw(privlibexp archlibexp vendorarchexp sitearchexp)
14             };
15 7     0   146 DlogS_trace { "dir list built in ModuleSender: $_" } [ grep !$core{$_}, @INC ];
  0         0  
16             }
17              
18             sub source_for {
19 15     15 0 38 my ($self, $module) = @_;
20 15     0   133 log_debug { "locating source for module '$module'" };
  0         0  
21 15 100       341 if (my $find = Object::Remote::FromData->can('find_module')) {
22 7 100       32 if (my $source = $find->($module)) {
23 6     0   45 Dlog_trace { "source of '$module' was found by Object::Remote::FromData" };
  0         0  
24 6         127 return $source;
25             }
26             }
27 9     0   74 log_trace { "Searching for module in library directories" };
  0         0  
28 16     16   1445 my ($found) = first { -f $_ }
29             map File::Spec->catfile($_, $module),
30 9         112 @{$self->dir_list};
  9         270  
31             die "Can't locate ${module} in \@INC. (on remote host) dir_list contains:\n"
32 9 100       62 .join("\n", @{$self->dir_list})
  1         20  
33             unless $found;
34 8     0   59 log_debug { "found '$module' at '$found'" };
  0         0  
35 8 50       531 open my $fh, '<', $found or die "Couldn't open ${found} for ${module}: $!";
36 8         16 return do { local $/; <$fh> };
  8         48  
  8         389  
37             }
38              
39             1;