1 package Object::Remote::FatNode;
7 my @exclude_mods = qw(XSLoader.pm DynaLoader.pm);
8 #used by t/watchdog_fatnode
9 our $INHIBIT_RUN_NODE = 0;
13 $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
17 my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
19 my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
20 my $extra_libs = join '', map {
30 -mObject::Remote::Connector::STDIO
36 -mObject::Remote::ModuleLoader
37 -mObject::Remote::Node
38 -mMethod::Generate::BuildAll
39 -mMethod::Generate::DemolishAll
41 -e 'print join "\\n", \%INC'
46 chomp(my @inc = qx($command));
48 my %exclude = map { $_ => 1 } @exclude_mods;
49 my %mods = reverse @inc;
50 my %file_names = @inc;
52 foreach(keys(%mods)) {
53 if ($exclude{ $mods{$_} }) {
58 my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} );
59 push @non_core_non_arch, grep +(
61 #some of the config variables can be empty which will eval as a matching regex
62 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
63 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
64 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
65 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
67 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
69 my @core_non_arch = grep +(
70 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
71 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
72 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
75 my $start = stripspace <<'END_START';
76 # This chunk of stuff was generated by Object::Remote::FatNode. To find
77 # the original file's code, look for the end of this BEGIN block or the
80 my (%fatpacked,%fatpacked_extra);
83 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
85 my $end = stripspace <<'END_END';
86 s/^ //mg for values %fatpacked, values %fatpacked_extra;
89 if (my $fat = $_[0]->{$_[1]}) {
90 if ($exclude{$_[1]}) {
91 warn "Will not pre-load '$_[1]'";
95 #warn "Handling $_[1]";
96 open my $fh, '<', \$fat;
100 #Uncomment this to find brokenness
101 #warn "Missing $_[1]";
105 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
106 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
108 } # END OF FATPACK CODE
111 use Object::Remote::Node;
113 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
114 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
119 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
120 @non_core_non_arch, @core_non_arch;
122 sub generate_fatpack_hash {
123 my ($hash_name, $orig) = @_;
124 (my $stub = $orig) =~ s/\.pm$//;
125 my $name = uc join '_', split '/', $stub;
126 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
127 $data .= "\n" unless $data =~ m/\n$/;
128 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
129 .qq!${data}${name}\n!;
135 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
136 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
139 #print STDERR Dumper(\@segments);
140 our $DATA = join "\n", $start, @segments, $end;