package Tak::ModuleLoader;

use Moo;

has remote => (is => 'ro', required => 1);

sub inc_callback {
  sub { $self->maybe_load_module($_[1]) }
}

sub maybe_load_module {
  my ($self, $module) = @_;
  my $result = $self->remote->blocking_request(source_for => $module);
  if (my $code = $result->{code}) {
    open my $fh, '<', \$code;
    return $fh;
  }
  return;
}

1;
