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 chomp(my @base_libs = `"$^X" -le"print for grep defined and !ref, \@INC"`);
18 my %base_libs = map +($_ => 1), @base_libs;
20 my @extra_libs = grep not(ref($_) or $base_libs{$_}), @INC;
21 my $extra_libs = join ' ', map {
31 -mObject::Remote::Connector::STDIO
37 -mObject::Remote::ModuleLoader
38 -mObject::Remote::Node
39 -mMethod::Generate::BuildAll
40 -mMethod::Generate::DemolishAll
41 -mMoo::HandleMoose::_TypeMap
43 -e 'print join "\\n", \%INC'
48 chomp(my @inc = qx($command));
50 my %exclude = map { $_ => 1 } @exclude_mods;
52 my %file_names = @inc;
54 # only include mods that match the filename,
55 # ie ones that will succeed with a require $module
56 # https://rt.cpan.org/Ticket/Display.html?id=100478
58 map { $file_names{$_} => $_ }
59 grep { $file_names{$_} =~ /\Q$_\E$/ } keys %file_names;
61 foreach(keys(%mods)) {
62 if ($exclude{ $mods{$_} }) {
67 my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} );
68 push @non_core_non_arch, grep +(
70 #some of the config variables can be empty which will eval as a matching regex
71 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
72 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
73 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
74 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
76 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
78 my @core_non_arch = grep +(
79 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
80 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
81 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
84 my $start = stripspace <<'END_START';
85 # This chunk of stuff was generated by Object::Remote::FatNode. To find
86 # the original file's code, look for the end of this BEGIN block or the
89 my (%fatpacked,%fatpacked_extra);
92 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
94 my $end = stripspace <<'END_END';
95 s/^ //mg for values %fatpacked, values %fatpacked_extra;
98 if (my $fat = $_[0]->{$_[1]}) {
99 if ($exclude{$_[1]}) {
100 warn "Will not pre-load '$_[1]'";
104 #warn "Handling $_[1]";
105 open my $fh, '<', \$fat;
109 #Uncomment this to find brokenness
110 #warn "Missing $_[1]";
114 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
115 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
117 } # END OF FATPACK CODE
120 use Object::Remote::Node;
122 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
123 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
128 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
129 @non_core_non_arch, @core_non_arch;
131 sub generate_fatpack_hash {
132 my ($hash_name, $orig) = @_;
133 (my $stub = $orig) =~ s/\.pm$//;
134 my $name = uc join '_', split '/', $stub;
135 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
136 $data .= "\n" unless $data =~ m/\n$/;
137 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
138 .qq!${data}${name}\n!;
144 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
145 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
148 #print STDERR Dumper(\@segments);
149 our $DATA = join "\n", $start, @segments, $end;