#!/usr/bin/env perl
use strictures 1;
-use Object::Remote::Connector::STDIO;
-use Object::Remote;
-use CPS::Future;
+use Object::Remote::Node;
-my $c = Object::Remote::Connector::STDIO->new->connect;
-
-$c->register_class_call_handler;
-
-$c->ready_future->done;
-
-my $loop = Object::Remote->current_loop;
-
-my $f = CPS::Future->new;
-
-$f->on_ready(sub { $loop->want_stop });
-
-$c->on_close($f);
-
-print { $c->send_to_fh } "Shere\n";
-
-$loop->want_run;
-$loop->run_while_wanted;
+Object::Remote::Node->run;
--- /dev/null
+package Object::Remote::FatNode;
+
+use strictures 1;
+use Config;
+use B qw(perlstring);
+
+sub stripspace {
+ my ($text) = @_;
+ $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
+ $text;
+}
+
+my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
+
+my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
+
+my $extra_libs = join '', map " -I$_\n", @extra_libs;
+
+my $command = qq(
+ $^X
+ $extra_libs
+ -mObject::Remote
+ -mObject::Remote::Connector::STDIO
+ -mCPS::Future
+ -mClass::C3
+ -mObject::Remote::ModuleLoader
+ -mObject::Remote::Node
+ -mJSON::PP
+ -e 'print join "\\n", reverse \%INC'
+);
+
+$command =~ s/\n/ /g;
+
+chomp(my %mods = qx($command));
+
+my @non_core_non_arch = grep +(
+ not (/^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/)
+), grep !/\Q$Config{archname}/, grep !/\W$Config{myarchname}/, keys %mods;
+
+my $start = stripspace <<'END_START';
+ # This chunk of stuff was generated by Object::Remote::FatNode. To find
+ # the original file's code, look for the end of this BEGIN block or the
+ # string 'FATPACK'
+ BEGIN {
+ my %fatpacked;
+END_START
+my $end = stripspace <<'END_END';
+ s/^ //mg for values %fatpacked;
+
+ unshift @INC, sub {
+ if (my $fat = $fatpacked{$_[1]}) {
+ open my $fh, '<', \$fat;
+ return $fh;
+ }
+ return
+ };
+
+ } # END OF FATPACK CODE
+
+ use strictures 1;
+ use Object::Remote::Node;
+ Object::Remote::Node->run;
+END_END
+
+my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
+ @non_core_non_arch;
+
+my @segments = map {
+ (my $stub = $_) =~ s/\.pm$//;
+ my $name = uc join '_', split '/', $stub;
+ my $data = $files{$_}; $data =~ s/^/ /mg;
+ '$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
+ .qq!${data}${name}\n!;
+} sort keys %files;
+
+our $DATA = join "\n", $start, @segments, $end;
+
+1;
--- /dev/null
+package Object::Remote::Node;
+
+use strictures 1;
+use Object::Remote::Connector::STDIO;
+use Object::Remote;
+use CPS::Future;
+
+sub run {
+
+ my $c = Object::Remote::Connector::STDIO->new->connect;
+
+ $c->register_class_call_handler;
+
+ $c->ready_future->done;
+
+ my $loop = Object::Remote->current_loop;
+
+ my $f = CPS::Future->new;
+
+ $f->on_ready(sub { $loop->want_stop });
+
+ $c->on_close($f);
+
+ print { $c->send_to_fh } "Shere\n";
+
+ $loop->want_run;
+ $loop->run_while_wanted;
+}
+
+1;
+++ /dev/null
-#!/bin/sh
-
-if [ -e fatlib ]; then rm -r fatlib; fi
-fatpack tree $(fatpack packlists-for strictures.pm Module/Runtime.pm Moo.pm JSON/PP.pm MRO/Compat.pm Class/C3.pm Algorithm/C3.pm Class/Method/Modifiers.pm Role/Tiny.pm CPS/Future.pm)
-rm lib/Object/Remote/FatNode.pm
-(
- echo 'package Object::Remote::FatNode;
-our $DATA = do { local $/; <DATA> };
-1;
-__DATA__
-';
- fatpack file;
- cat bin/object-remote-node
-)>FatNode.pm.new
-mv FatNode.pm.new lib/Object/Remote/FatNode.pm
-rm -r fatlib