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;
20 my $extra_libs = join '', map {
30 -mObject::Remote::Connector::STDIO
36 -mObject::Remote::ModuleLoader
37 -mObject::Remote::Node
38 -mMethod::Generate::BuildAll
39 -mMethod::Generate::DemolishAll
40 -mMoo::HandleMoose::_TypeMap
42 -e 'print join "\\n", \%INC'
47 chomp(my @inc = qx($command));
49 my %exclude = map { $_ => 1 } @exclude_mods;
50 my %mods = reverse @inc;
51 my %file_names = @inc;
53 foreach(keys(%mods)) {
54 if ($exclude{ $mods{$_} }) {
59 my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} );
60 push @non_core_non_arch, grep +(
62 #some of the config variables can be empty which will eval as a matching regex
63 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
64 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
65 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
66 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
68 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
70 my @core_non_arch = grep +(
71 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
72 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
73 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
76 my $start = stripspace <<'END_START';
77 # This chunk of stuff was generated by Object::Remote::FatNode. To find
78 # the original file's code, look for the end of this BEGIN block or the
81 my (%fatpacked,%fatpacked_extra);
84 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
86 my $end = stripspace <<'END_END';
87 s/^ //mg for values %fatpacked, values %fatpacked_extra;
90 if (my $fat = $_[0]->{$_[1]}) {
91 if ($exclude{$_[1]}) {
92 warn "Will not pre-load '$_[1]'";
96 #warn "Handling $_[1]";
97 open my $fh, '<', \$fat;
101 #Uncomment this to find brokenness
102 #warn "Missing $_[1]";
106 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
107 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
109 } # END OF FATPACK CODE
112 use Object::Remote::Node;
114 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
115 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
120 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
121 @non_core_non_arch, @core_non_arch;
123 sub generate_fatpack_hash {
124 my ($hash_name, $orig) = @_;
125 (my $stub = $orig) =~ s/\.pm$//;
126 my $name = uc join '_', split '/', $stub;
127 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
128 $data .= "\n" unless $data =~ m/\n$/;
129 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
130 .qq!${data}${name}\n!;
136 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
137 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
140 #print STDERR Dumper(\@segments);
141 our $DATA = join "\n", $start, @segments, $end;