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{$_} }) {
54 my @non_core_non_arch = ( $mods{'Devel/GlobalDestruction.pm'} );
55 push @non_core_non_arch, grep +(
57 #some of the config variables can be empty which will eval as a matching regex
58 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
59 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
60 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
61 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
63 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
65 my @core_non_arch = grep +(
66 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
67 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
68 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
71 my $start = stripspace <<'END_START';
72 # This chunk of stuff was generated by Object::Remote::FatNode. To find
73 # the original file's code, look for the end of this BEGIN block or the
76 my (%fatpacked,%fatpacked_extra);
79 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
81 my $end = stripspace <<'END_END';
82 s/^ //mg for values %fatpacked, values %fatpacked_extra;
85 if (my $fat = $_[0]->{$_[1]}) {
86 if ($exclude{$_[1]}) {
87 warn "Will not pre-load '$_[1]'";
91 #warn "Handling $_[1]";
92 open my $fh, '<', \$fat;
96 #Uncomment this to find brokenness
97 #warn "Missing $_[1]";
101 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
102 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
104 } # END OF FATPACK CODE
107 use Object::Remote::Node;
109 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
110 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
115 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
116 @non_core_non_arch, @core_non_arch;
118 sub generate_fatpack_hash {
119 my ($hash_name, $orig) = @_;
120 (my $stub = $orig) =~ s/\.pm$//;
121 my $name = uc join '_', split '/', $stub;
122 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
123 $data .= "\n" unless $data =~ m/\n$/;
124 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
125 .qq!${data}${name}\n!;
131 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
132 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
135 #print STDERR Dumper(\@segments);
136 our $DATA = join "\n", $start, @segments, $end;