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