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'
45 chomp(my @inc = qx($command));
47 my %exclude = map { $_ => 1 } @exclude_mods;
49 my %mods = reverse @inc;
51 foreach(keys(%mods)) {
52 if ($exclude{ $mods{$_} }) {
57 #TODO quick and dirty mod for testing - vendorarchexp from a perlbrew build
58 #was set to '' which evaluates as a true regex
61 #print STDERR Dumper([keys %mod_files]);
62 #print STDERR Dumper([keys %mods]);
64 my @non_core_non_arch = ( $mod_files{'Devel/GlobalDestruction.pm'} );
65 push @non_core_non_arch, grep +(
67 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
68 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
69 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
70 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
72 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
74 my @core_non_arch = grep +(
75 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
76 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
77 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
80 #print STDERR "non-core non-arch ", Dumper(\@non_core_non_arch);
81 #print STDERR "core non-arch ", Dumper(\@core_non_arch);
83 #TODO this is the wrong path to go down - fork() will bring
84 #the env vars with it and the ssh connector can handle
85 #forwarding the env vars
87 if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) {
88 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
89 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n";
91 if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) {
92 my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
93 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n";
95 if (defined($ENV{OBJECT_REMOTE_LOG_SELECTIONS})) {
96 my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS};
97 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_SELECTIONS} = "' . $selections . "\";\n";
99 if (defined($ENV{OBJECT_REMOTE_LOG_FORWARDING})) {
100 my $forwarding = $ENV{OBJECT_REMOTE_LOG_FORWARDING};
101 $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORWARDING} = "' . $forwarding . "\";\n";
104 my $start = stripspace <<'END_START';
105 # This chunk of stuff was generated by Object::Remote::FatNode. To find
106 # the original file's code, look for the end of this BEGIN block or the
109 my (%fatpacked,%fatpacked_extra);
112 $start .= 'my %exclude = map { $_ => 1 } qw(' . join(' ', @exclude_mods) . ");\n";
114 my $end = stripspace <<'END_END';
115 s/^ //mg for values %fatpacked, values %fatpacked_extra;
118 if (my $fat = $_[0]->{$_[1]}) {
119 if ($exclude{$_[1]}) {
120 warn "Will not pre-load '$_[1]'";
124 #warn "handling $_[1]";
125 open my $fh, '<', \$fat;
129 #Uncomment this to find brokenness
130 #warn "Missing $_[1]";
134 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
135 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
137 } # END OF FATPACK CODE
140 use Object::Remote::Node;
142 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
143 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
148 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
149 @non_core_non_arch, @core_non_arch;
152 sub generate_fatpack_hash {
153 my ($hash_name, $orig) = @_;
154 (my $stub = $orig) =~ s/\.pm$//;
155 my $name = uc join '_', split '/', $stub;
156 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
157 return () if $did_pack{$hash_name}{$orig};
158 $did_pack{$hash_name}{$orig} = 1;
159 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
160 .qq!${data}${name}\n!;
164 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
165 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
168 #print STDERR Dumper(\@segments);
169 our $DATA = join "\n", $start, $env_pass, @segments, $end;