1 package Object::Remote::FatNode;
7 my @exclude_mods = qw(XSLoader.pm DynaLoader.pm);
9 #used by t/watchdog_fatnode
10 our $INHIBIT_RUN_NODE = 0;
14 $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
18 my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
20 my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
22 my $extra_libs = join '', map " -I$_\n", @extra_libs;
28 -mObject::Remote::Connector::STDIO
34 -mObject::Remote::ModuleLoader
35 -mObject::Remote::Node
36 -mMethod::Generate::BuildAll
37 -mMethod::Generate::DemolishAll
39 -e 'print join "\\n", \%INC'
44 chomp(my @inc = qx($command));
46 my %exclude = map { $_ => 1 } @exclude_mods;
47 my %mods = reverse @inc;
49 foreach(keys(%mods)) {
50 if ($exclude{ $mods{$_} }) {
57 /^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/
61 my @before_inc = grep { filter_not_core() } keys %mods;
65 if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) {
66 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
67 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n";
69 if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) {
70 my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
71 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n";
74 my $start = stripspace <<'END_START';
75 # This chunk of stuff was generated by Object::Remote::FatNode. To find
76 # the original file's code, look for the end of this BEGIN block or the
79 my (%fatpacked,%fatpacked_extra);
82 $start .= 'my %exclude = map { $_ => 1 } qw(' . join(' ', @exclude_mods) . ");\n";
84 my $end = stripspace <<'END_END';
85 s/^ //mg for values %fatpacked, values %fatpacked_extra;
88 if (my $fat = $_[0]->{$_[1]}) {
89 if ($exclude{$_[1]}) {
90 warn "Will not pre-load '$_[1]'";
94 #warn "handling $_[1]";
95 open my $fh, '<', \$fat;
99 #Uncomment this to find brokenness
100 #warn "Missing $_[1]";
104 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
105 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
107 } # END OF FATPACK CODE
110 use Object::Remote::Node;
112 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
113 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
118 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
119 @before_inc, @after_inc;
121 sub generate_fatpack_hash {
122 my ($hash_name, $orig) = @_;
123 (my $stub = $orig) =~ s/\.pm$//;
124 my $name = uc join '_', split '/', $stub;
125 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
126 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
127 .qq!${data}${name}\n!;
131 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @before_inc),
132 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @after_inc),
135 our $DATA = join "\n", $start, $env_pass, @segments, $end;