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;
48 foreach(keys(%mods)) {
49 if ($exclude{ $mods{$_} }) {
56 /^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/
60 my @file_names = keys %mods;
61 my @before_inc = grep { filter_not_core() } @file_names;
64 #TODO this is the wrong path to go down - fork() will bring
65 #the env vars with it and the ssh connector can handle
66 #forwarding the env vars
68 if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) {
69 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
70 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n";
72 if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) {
73 my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
74 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n";
76 if (defined($ENV{OBJECT_REMOTE_LOG_SELECTIONS})) {
77 my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS};
78 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_SELECTIONS} = "' . $selections . "\";\n";
80 if (defined($ENV{OBJECT_REMOTE_LOG_FORWARDING})) {
81 my $forwarding = $ENV{OBJECT_REMOTE_LOG_FORWARDING};
82 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORWARDING} = "' . $forwarding . "\";\n";
87 my $start = stripspace <<'END_START';
88 # This chunk of stuff was generated by Object::Remote::FatNode. To find
89 # the original file's code, look for the end of this BEGIN block or the
92 my (%fatpacked,%fatpacked_extra);
95 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
97 my $end = stripspace <<'END_END';
98 s/^ //mg for values %fatpacked, values %fatpacked_extra;
101 if (my $fat = $_[0]->{$_[1]}) {
102 if ($exclude{$_[1]}) {
103 warn "Will not pre-load '$_[1]'";
107 #warn "Handling $_[1]";
108 open my $fh, '<', \$fat;
112 #Uncomment this to find brokenness
113 #warn "Missing $_[1]";
117 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
118 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
120 } # END OF FATPACK CODE
123 use Object::Remote::Node;
125 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
126 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
131 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
132 @before_inc, @after_inc;
134 sub generate_fatpack_hash {
135 my ($hash_name, $orig) = @_;
136 (my $stub = $orig) =~ s/\.pm$//;
137 my $name = uc join '_', split '/', $stub;
138 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
139 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
140 .qq!${data}${name}\n!;
144 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @before_inc),
145 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @after_inc),
148 our $DATA = join "\n", $start, $env_pass, @segments, $end;