reject XSLoader at fatnode module loader if it made it through
[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
1900601d 43#my @non_core = grep +(
44# not (
45# /^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/
46# )
47#), keys %mods;
48
49my @non_core = keys %mods;
eee9a548 50
c6749bdd 51#my @core_non_arch = grep +(
52# /^\Q$Config{privlibexp}/
53#), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
54my @core_non_arch;
1ef3d225 55
eee9a548 56my $start = stripspace <<'END_START';
57 # This chunk of stuff was generated by Object::Remote::FatNode. To find
58 # the original file's code, look for the end of this BEGIN block or the
59 # string 'FATPACK'
60 BEGIN {
1ef3d225 61 my (%fatpacked,%fatpacked_extra);
eee9a548 62END_START
63my $end = stripspace <<'END_END';
1ef3d225 64 s/^ //mg for values %fatpacked, values %fatpacked_extra;
eee9a548 65
1ef3d225 66 sub load_from_hash {
1900601d 67 if ($_[1] eq 'XSLoader.pm') {
68 warn "XSLoader made it into the fat node";
69 return undef;
70 }
71
1ef3d225 72 if (my $fat = $_[0]->{$_[1]}) {
eee9a548 73 open my $fh, '<', \$fat;
74 return $fh;
75 }
1900601d 76
8c81a0e5 77 #Uncomment this to find brokenness
78 #warn "Missing $_[1]";
eee9a548 79 return
1ef3d225 80 }
81
82 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
83 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
eee9a548 84
85 } # END OF FATPACK CODE
86
87 use strictures 1;
88 use Object::Remote::Node;
89 Object::Remote::Node->run;
90END_END
91
92my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
bad3fec6 93 @non_core, @core_non_arch;
eee9a548 94
1ef3d225 95sub generate_fatpack_hash {
96 my ($hash_name, $orig) = @_;
97 (my $stub = $orig) =~ s/\.pm$//;
eee9a548 98 my $name = uc join '_', split '/', $stub;
1ef3d225 99 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
100 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
eee9a548 101 .qq!${data}${name}\n!;
1ef3d225 102}
103
c6749bdd 104use Data::Dumper;
105warn "Dumping list of shipped modules";
106print STDERR "Core non-arch: ", Dumper(\@core_non_arch);
107print STDERR "Non-core: ", Dumper(\@non_core);
108
1ef3d225 109my @segments = (
6d3fbfa2 110 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core),
111 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
1ef3d225 112);
eee9a548 113
114our $DATA = join "\n", $start, @segments, $end;
115
1161;