Commit | Line | Data |
eee9a548 |
1 | package Object::Remote::FatNode; |
2 | |
3 | use strictures 1; |
4 | use Config; |
5 | use B qw(perlstring); |
6 | |
f6ac5927 |
7 | my @exclude_mods = qw(XSLoader.pm DynaLoader.pm); |
1bf55307 |
8 | #used by t/watchdog_fatnode |
f1d70835 |
9 | our $INHIBIT_RUN_NODE = 0; |
f6ac5927 |
10 | |
eee9a548 |
11 | sub stripspace { |
12 | my ($text) = @_; |
13 | $text =~ /^(\s+)/ && $text =~ s/^$1//mg; |
14 | $text; |
15 | } |
16 | |
17 | my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.'); |
18 | |
668343cd |
19 | my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC; |
20 | my $extra_libs = join '', map { |
21 | my $lib = $_; |
22 | $lib =~ s{'}{'\\''}g; |
23 | " -I'$lib'\n"; |
24 | } @extra_libs; |
eee9a548 |
25 | |
26 | my $command = qq( |
27 | $^X |
28 | $extra_libs |
29 | -mObject::Remote |
30 | -mObject::Remote::Connector::STDIO |
783105c4 |
31 | -mFuture |
8c81a0e5 |
32 | -mMRO::Compat |
eee9a548 |
33 | -mClass::C3 |
8c81a0e5 |
34 | -mClass::C3::next |
35 | -mAlgorithm::C3 |
eee9a548 |
36 | -mObject::Remote::ModuleLoader |
37 | -mObject::Remote::Node |
4c8c83d7 |
38 | -mMethod::Generate::BuildAll |
39 | -mMethod::Generate::DemolishAll |
dd6e1327 |
40 | -mMoo::HandleMoose::_TypeMap |
eee9a548 |
41 | -mJSON::PP |
df8e0ca6 |
42 | -e 'print join "\\n", \%INC' |
eee9a548 |
43 | ); |
44 | |
45 | $command =~ s/\n/ /g; |
46 | |
df8e0ca6 |
47 | chomp(my @inc = qx($command)); |
48 | |
1bf55307 |
49 | my %exclude = map { $_ => 1 } @exclude_mods; |
df8e0ca6 |
50 | my %mods = reverse @inc; |
5e850e3e |
51 | my %file_names = @inc; |
eee9a548 |
52 | |
f6ac5927 |
53 | foreach(keys(%mods)) { |
54 | if ($exclude{ $mods{$_} }) { |
55c0d020 |
55 | delete($mods{$_}); |
f6ac5927 |
56 | } |
57 | } |
58 | |
5e850e3e |
59 | my @non_core_non_arch = ( $file_names{'Devel/GlobalDestruction.pm'} ); |
15b847bb |
60 | push @non_core_non_arch, grep +( |
61c6bba7 |
61 | not ( |
15b847bb |
62 | #some of the config variables can be empty which will eval as a matching regex |
55c0d020 |
63 | $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/ |
15b847bb |
64 | or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/ |
65 | or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/ |
66 | or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/ |
67 | ) |
68 | ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods; |
69 | |
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}/) |
74 | ), keys %mods; |
75 | |
eee9a548 |
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 |
79 | # string 'FATPACK' |
80 | BEGIN { |
1ef3d225 |
81 | my (%fatpacked,%fatpacked_extra); |
eee9a548 |
82 | END_START |
f6ac5927 |
83 | |
cc62b744 |
84 | $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n"; |
f6ac5927 |
85 | |
eee9a548 |
86 | my $end = stripspace <<'END_END'; |
1ef3d225 |
87 | s/^ //mg for values %fatpacked, values %fatpacked_extra; |
eee9a548 |
88 | |
1ef3d225 |
89 | sub load_from_hash { |
90 | if (my $fat = $_[0]->{$_[1]}) { |
f6ac5927 |
91 | if ($exclude{$_[1]}) { |
92 | warn "Will not pre-load '$_[1]'"; |
55c0d020 |
93 | return undef; |
f6ac5927 |
94 | } |
55c0d020 |
95 | |
cc62b744 |
96 | #warn "Handling $_[1]"; |
eee9a548 |
97 | open my $fh, '<', \$fat; |
98 | return $fh; |
99 | } |
55c0d020 |
100 | |
8c81a0e5 |
101 | #Uncomment this to find brokenness |
102 | #warn "Missing $_[1]"; |
f6ac5927 |
103 | return; |
1ef3d225 |
104 | } |
105 | |
106 | unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) }; |
107 | push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) }; |
eee9a548 |
108 | |
109 | } # END OF FATPACK CODE |
110 | |
111 | use strictures 1; |
112 | use Object::Remote::Node; |
55c0d020 |
113 | |
f129bfaf |
114 | unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) { |
55c0d020 |
115 | Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT); |
f129bfaf |
116 | } |
55c0d020 |
117 | |
eee9a548 |
118 | END_END |
119 | |
120 | my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }), |
15b847bb |
121 | @non_core_non_arch, @core_non_arch; |
eee9a548 |
122 | |
1ef3d225 |
123 | sub generate_fatpack_hash { |
124 | my ($hash_name, $orig) = @_; |
125 | (my $stub = $orig) =~ s/\.pm$//; |
eee9a548 |
126 | my $name = uc join '_', split '/', $stub; |
1ef3d225 |
127 | my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg; |
3ab6f7e2 |
128 | $data .= "\n" unless $data =~ m/\n$/; |
129 | my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n! |
130 | .qq!${data}${name}\n!; |
131 | # warn $ret; |
132 | return $ret; |
1ef3d225 |
133 | } |
134 | |
135 | my @segments = ( |
15b847bb |
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), |
1ef3d225 |
138 | ); |
eee9a548 |
139 | |
90f5193d |
140 | #print STDERR Dumper(\@segments); |
141 | our $DATA = join "\n", $start, @segments, $end; |
eee9a548 |
142 | |
143 | 1; |