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;
64 #TODO obviously this should be made into a method or configurable some how
66 if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) {
67 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
68 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n";
70 if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) {
71 my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
72 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n";
74 if (defined($ENV{OBJECT_REMOTE_LOG_SELECTIONS})) {
75 my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS};
76 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_SELECTIONS} = "' . $selections . "\";\n";
80 my $start = stripspace <<'END_START';
81 # This chunk of stuff was generated by Object::Remote::FatNode. To find
82 # the original file's code, look for the end of this BEGIN block or the
85 my (%fatpacked,%fatpacked_extra);
88 $start .= 'my %exclude = map { $_ => 1 } qw(' . join(' ', @exclude_mods) . ");\n";
90 my $end = stripspace <<'END_END';
91 s/^ //mg for values %fatpacked, values %fatpacked_extra;
94 if (my $fat = $_[0]->{$_[1]}) {
95 if ($exclude{$_[1]}) {
96 warn "Will not pre-load '$_[1]'";
100 #warn "handling $_[1]";
101 open my $fh, '<', \$fat;
105 #Uncomment this to find brokenness
106 #warn "Missing $_[1]";
110 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
111 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
113 } # END OF FATPACK CODE
116 use Object::Remote::Node;
118 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
119 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
124 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
125 @before_inc, @after_inc;
127 sub generate_fatpack_hash {
128 my ($hash_name, $orig) = @_;
129 (my $stub = $orig) =~ s/\.pm$//;
130 my $name = uc join '_', split '/', $stub;
131 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
132 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
133 .qq!${data}${name}\n!;
137 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @before_inc),
138 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @after_inc),
141 our $DATA = join "\n", $start, $env_pass, @segments, $end;