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;
51 my %file_names = @inc;
53 # only include mods that match the filename,
54 # ie ones that will succeed with a require $module
55 # https://rt.cpan.org/Ticket/Display.html?id=100478
57 map { $file_names{$_} => $_ }
58 grep { $file_names{$_} =~ /\Q$_\E$/ } keys %file_names;
60 foreach(keys(%mods)) {
61 if ($exclude{ $mods{$_} }) {
66 my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} );
67 push @non_core_non_arch, grep +(
69 #some of the config variables can be empty which will eval as a matching regex
70 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
71 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
72 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
73 or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
75 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
77 my @core_non_arch = grep +(
78 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
79 and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
80 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
83 my $start = stripspace <<'END_START';
84 # This chunk of stuff was generated by Object::Remote::FatNode. To find
85 # the original file's code, look for the end of this BEGIN block or the
88 my (%fatpacked,%fatpacked_extra);
91 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
93 my $end = stripspace <<'END_END';
94 s/^ //mg for values %fatpacked, values %fatpacked_extra;
97 if (my $fat = $_[0]->{$_[1]}) {
98 if ($exclude{$_[1]}) {
99 warn "Will not pre-load '$_[1]'";
103 #warn "Handling $_[1]";
104 open my $fh, '<', \$fat;
108 #Uncomment this to find brokenness
109 #warn "Missing $_[1]";
113 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
114 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
116 } # END OF FATPACK CODE
119 use Object::Remote::Node;
121 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
122 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
127 my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
128 @non_core_non_arch, @core_non_arch;
130 sub generate_fatpack_hash {
131 my ($hash_name, $orig) = @_;
132 (my $stub = $orig) =~ s/\.pm$//;
133 my $name = uc join '_', split '/', $stub;
134 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
135 $data .= "\n" unless $data =~ m/\n$/;
136 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
137 .qq!${data}${name}\n!;
143 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
144 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
147 #print STDERR Dumper(\@segments);
148 our $DATA = join "\n", $start, @segments, $end;