5.8 also requires extra C3 bits
[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
8c81a0e5 25 -mMRO::Compat
eee9a548 26 -mClass::C3
8c81a0e5 27 -mClass::C3::next
28 -mAlgorithm::C3
eee9a548 29 -mObject::Remote::ModuleLoader
30 -mObject::Remote::Node
4c8c83d7 31 -mMethod::Generate::BuildAll
32 -mMethod::Generate::DemolishAll
eee9a548 33 -mJSON::PP
34 -e 'print join "\\n", reverse \%INC'
35);
36
37$command =~ s/\n/ /g;
38
39chomp(my %mods = qx($command));
40
41my @non_core_non_arch = grep +(
42 not (/^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/)
43), grep !/\Q$Config{archname}/, grep !/\W$Config{myarchname}/, keys %mods;
44
45my $start = stripspace <<'END_START';
46 # This chunk of stuff was generated by Object::Remote::FatNode. To find
47 # the original file's code, look for the end of this BEGIN block or the
48 # string 'FATPACK'
49 BEGIN {
50 my %fatpacked;
51END_START
52my $end = stripspace <<'END_END';
53 s/^ //mg for values %fatpacked;
54
55 unshift @INC, sub {
56 if (my $fat = $fatpacked{$_[1]}) {
57 open my $fh, '<', \$fat;
58 return $fh;
59 }
8c81a0e5 60 #Uncomment this to find brokenness
61 #warn "Missing $_[1]";
eee9a548 62 return
63 };
64
65 } # END OF FATPACK CODE
66
67 use strictures 1;
68 use Object::Remote::Node;
69 Object::Remote::Node->run;
70END_END
71
72my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
73 @non_core_non_arch;
74
75my @segments = map {
76 (my $stub = $_) =~ s/\.pm$//;
77 my $name = uc join '_', split '/', $stub;
78 my $data = $files{$_}; $data =~ s/^/ /mg;
79 '$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
80 .qq!${data}${name}\n!;
81} sort keys %files;
82
83our $DATA = join "\n", $start, @segments, $end;
84
851;