remove incomplete non-blocking support; make select() timeout duration configurable...
[scpubgit/Object-Remote.git] / lib / Object / Remote / FatNode.pm
CommitLineData
eee9a548 1package Object::Remote::FatNode;
2
3use strictures 1;
4use Config;
5use B qw(perlstring);
6
7sub stripspace {
8 my ($text) = @_;
9 $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
10 $text;
11}
12
13my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
14
15my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
16
17my $extra_libs = join '', map " -I$_\n", @extra_libs;
18
19my $command = qq(
20 $^X
21 $extra_libs
22 -mObject::Remote
23 -mObject::Remote::Connector::STDIO
24 -mCPS::Future
8c81a0e5 25 -mMRO::Compat
eee9a548 26 -mClass::C3
8c81a0e5 27 -mClass::C3::next
28 -mAlgorithm::C3
eee9a548 29 -mObject::Remote::ModuleLoader
30 -mObject::Remote::Node
4c8c83d7 31 -mMethod::Generate::BuildAll
32 -mMethod::Generate::DemolishAll
eee9a548 33 -mJSON::PP
df8e0ca6 34 -e 'print join "\\n", \%INC'
eee9a548 35);
36
37$command =~ s/\n/ /g;
38
df8e0ca6 39chomp(my @inc = qx($command));
40
41my %mods = reverse @inc;
eee9a548 42
3a966220 43#TODO oi this isn't right yet
eee9a548 44my @non_core_non_arch = grep +(
df8e0ca6 45 not (
46 /^\Q$Config{privlibexp}/ or /^\Q$Config{archlibexp}/
3a966220 47 #or /^\Q$Config{vendorarchexp}/ or /^\Q$Config{sitearchexp}/
df8e0ca6 48 )
f225a199 49), keys %mods;
eee9a548 50
1ef3d225 51my @core_non_arch = grep +(
52 /^\Q$Config{privlibexp}/
53 and not(/^\Q$Config{archlibexp}/ or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
54), keys %mods;
55
23591f5f 56my $env_pass = '';
57if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) {
58 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
59 return unless $level =~ /^\w+$/;
60 $env_pass = '$ENV{OBJECT_REMOTE_LOG_LEVEL} = "' . $level . "\";\n";
61}
62
eee9a548 63my $start = stripspace <<'END_START';
64 # This chunk of stuff was generated by Object::Remote::FatNode. To find
65 # the original file's code, look for the end of this BEGIN block or the
66 # string 'FATPACK'
67 BEGIN {
1ef3d225 68 my (%fatpacked,%fatpacked_extra);
eee9a548 69END_START
70my $end = stripspace <<'END_END';
1ef3d225 71 s/^ //mg for values %fatpacked, values %fatpacked_extra;
eee9a548 72
1ef3d225 73 sub load_from_hash {
74 if (my $fat = $_[0]->{$_[1]}) {
eee9a548 75 open my $fh, '<', \$fat;
76 return $fh;
77 }
8c81a0e5 78 #Uncomment this to find brokenness
79 #warn "Missing $_[1]";
eee9a548 80 return
1ef3d225 81 }
82
83 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
84 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
eee9a548 85
86 } # END OF FATPACK CODE
87
88 use strictures 1;
89 use Object::Remote::Node;
69aaad21 90 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
eee9a548 91END_END
92
93my %files = map +($mods{$_} => scalar do { local (@ARGV, $/) = ($_); <> }),
1ef3d225 94 @non_core_non_arch, @core_non_arch;
eee9a548 95
1ef3d225 96sub generate_fatpack_hash {
97 my ($hash_name, $orig) = @_;
98 (my $stub = $orig) =~ s/\.pm$//;
eee9a548 99 my $name = uc join '_', split '/', $stub;
1ef3d225 100 my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
101 return '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
eee9a548 102 .qq!${data}${name}\n!;
1ef3d225 103}
104
105my @segments = (
106 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
107 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
108);
eee9a548 109
23591f5f 110our $DATA = join "\n", $start, $env_pass, @segments, $end;
eee9a548 111
1121;