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;
21 my $extra_libs = join '', map " -I$_\n", @extra_libs;
27 -mObject::Remote::Connector::STDIO
33 -mObject::Remote::ModuleLoader
34 -mObject::Remote::Node
35 -mMethod::Generate::BuildAll
36 -mMethod::Generate::DemolishAll
38 -e 'print join "\\n", \%INC'
43 chomp(my @inc = qx($command));
45 my %exclude = map { $_ => 1 } @exclude_mods;
46 my %mods = reverse @inc;
47 my %file_names = @inc;
49 foreach(keys(%mods)) {
50 if ($exclude{ $mods{$_} }) {
55 my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} );
56 push @non_core_non_arch, grep +(
58 #some of the config variables can be empty which will eval as a matching regex
59 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
60 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
61 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
62 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
64 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
66 my @core_non_arch = grep +(
67 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
68 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
69 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
72 my $start = stripspace <<'END_START';
73 # This chunk of stuff was generated by Object::Remote::FatNode. To find
74 # the original file's code, look for the end of this BEGIN block or the
77 my (%fatpacked,%fatpacked_extra);
80 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
82 my $end = stripspace <<'END_END';
83 s/^ //mg for values %fatpacked, values %fatpacked_extra;
86 if (my $fat = $_[0]->{$_[1]}) {
87 if ($exclude{$_[1]}) {
88 warn "Will not pre-load '$_[1]'";
92 #warn "Handling $_[1]";
93 open my $fh, '<', \$fat;
97 #Uncomment this to find brokenness
98 #warn "Missing $_[1]";
102 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
103 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
105 } # END OF FATPACK CODE
108 use Object::Remote::Node;
110 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
111 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
116 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
117 @non_core_non_arch, @core_non_arch;
119 sub generate_fatpack_hash {
120 my ($hash_name, $orig) = @_;
121 (my $stub = $orig) =~ s/\.pm$//;
122 my $name = uc join '_', split '/', $stub;
123 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
124 $data .= "\n" unless $data =~ m/\n$/;
125 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
126 .qq!${data}${name}\n!;
132 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
133 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
136 #print STDERR Dumper(\@segments);
137 our $DATA = join "\n", $start, @segments, $end;