Propagate errors from FatNode code
[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
df8e0ca6 34 -e 'print join "\\n", \%INC'
eee9a548 35);
36
37$command =~ s/\n/ /g;
38
df8e0ca6 39chomp(my @inc = qx($command));
40
41my %mods = reverse @inc;
eee9a548 42
43my @non_core_non_arch = grep +(
df8e0ca6 44 not (
45 /^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/
46 or /^\Q$Config{vendorarchexp}/ or /^\Q$Config{sitearchexp}/
47 )
48), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
eee9a548 49
50my $start = stripspace <<'END_START';
51 # This chunk of stuff was generated by Object::Remote::FatNode. To find
52 # the original file's code, look for the end of this BEGIN block or the
53 # string 'FATPACK'
54 BEGIN {
55 my %fatpacked;
56END_START
57my $end = stripspace <<'END_END';
58 s/^ //mg for values %fatpacked;
59
60 unshift @INC, sub {
61 if (my $fat = $fatpacked{$_[1]}) {
62 open my $fh, '<', \$fat;
63 return $fh;
64 }
8c81a0e5 65 #Uncomment this to find brokenness
66 #warn "Missing $_[1]";
eee9a548 67 return
68 };
69
70 } # END OF FATPACK CODE
71
72 use strictures 1;
73 use Object::Remote::Node;
74 Object::Remote::Node->run;
75END_END
76
77my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
78 @non_core_non_arch;
79
80my @segments = map {
81 (my $stub = $_) =~ s/\.pm$//;
82 my $name = uc join '_', split '/', $stub;
83 my $data = $files{$_}; $data =~ s/^/ /mg;
84 '$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
85 .qq!${data}${name}\n!;
86} sort keys %files;
87
88our $DATA = join "\n", $start, @segments, $end;
89
901;