only weaken when required
[scpubgit/Tak.git] / lib / Tak / ModuleSender.pm
index e565a26..210d402 100644 (file)
@@ -1,16 +1,27 @@
 package Tak::ModuleSender;
 
 use IO::All;
+use List::Util qw(first);
+use Config;
 use Moo;
 
+with 'Tak::Role::Service';
+
+has dir_list => (is => 'lazy');
+
+sub _build_dir_list {
+  my %core = map +($_ => 1), @Config{qw(privlibexp archlibexp)};
+  [ map io->dir($_), grep !/$Config{archname}$/, grep !$core{$_}, @INC ];
+}
+
 sub handle_source_for {
   my ($self, $module) = @_;
-  my $io = io->dir("$ENV{HOME}/perl5/lib/perl5")->catfile($module);
-  unless ($io->exists) {
-    return FAILURE => undef;
+  my $io = first { $_->exists } map $_->catfile($module), @{$self->dir_list};
+  unless ($io) {
+    die [ 'failure' ];
   }
   my $code = $io->all;
-  return RESULT => $code;
+  return $code;
 }
 
 1;