sketch for slave node
[scpubgit/Object-Remote.git] / lib / Object / Remote / FatNode.pm
CommitLineData
eee9a548 1package Object::Remote::FatNode;
2
3use strictures 1;
4use Config;
5use B qw(perlstring);
6
7sub stripspace {
8 my ($text) = @_;
9 $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
10 $text;
11}
12
13my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
14
15my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
16
17my $extra_libs = join '', map " -I$_\n", @extra_libs;
18
19my $command = qq(
20 $^X
21 $extra_libs
22 -mObject::Remote
23 -mObject::Remote::Connector::STDIO
24 -mCPS::Future
25 -mClass::C3
26 -mObject::Remote::ModuleLoader
27 -mObject::Remote::Node
28 -mJSON::PP
29 -e 'print join "\\n", reverse \%INC'
30);
31
32$command =~ s/\n/ /g;
33
34chomp(my %mods = qx($command));
35
36my @non_core_non_arch = grep +(
37 not (/^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/)
38), grep !/\Q$Config{archname}/, grep !/\W$Config{myarchname}/, keys %mods;
39
40my $start = stripspace <<'END_START';
41 # This chunk of stuff was generated by Object::Remote::FatNode. To find
42 # the original file's code, look for the end of this BEGIN block or the
43 # string 'FATPACK'
44 BEGIN {
45 my %fatpacked;
46END_START
47my $end = stripspace <<'END_END';
48 s/^ //mg for values %fatpacked;
49
50 unshift @INC, sub {
51 if (my $fat = $fatpacked{$_[1]}) {
52 open my $fh, '<', \$fat;
53 return $fh;
54 }
55 return
56 };
57
58 } # END OF FATPACK CODE
59
60 use strictures 1;
61 use Object::Remote::Node;
62 Object::Remote::Node->run;
63END_END
64
65my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
66 @non_core_non_arch;
67
68my @segments = map {
69 (my $stub = $_) =~ s/\.pm$//;
70 my $name = uc join '_', split '/', $stub;
71 my $data = $files{$_}; $data =~ s/^/ /mg;
72 '$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
73 .qq!${data}${name}\n!;
74} sort keys %files;
75
76our $DATA = join "\n", $start, @segments, $end;
77
781;