Remote/FatNode.pm

filter: Statementstmt 83.1% 59 / 71 Branchbran 44.4% 8 / 18 Conditioncond 59.5% 25 / 42 MC/DCmcdc 22.2% 4 / 18 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 63.9% 103 / 161 CC 8 SCAR 14.6
CC
8
Cov
70%
propagate_fatpacked
12.0
generate_fatpack_hash
4.1
stripspace
2.0
CRAP 4.3
« Remote/ConnectionServer.pm ↑ Summary Remote/Connection.pm »
1 package Object::Remote::FatNode;
2  
3 14 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use B qw(perlstring);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 my @exclude_mods = qw(XSLoader.pm DynaLoader.pm);
9 #used by t/watchdog_fatnode
10 14 our $INHIBIT_RUN_NODE = 0;
11  
12 28 ▶sub stripspace {
Subroutine stripspace: called CC=2 SCAR=7.1
Pod undocumented
13 28 my ($text) = @_;
14 28 ▶ $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^(\s+)/ and $text =~ s/^$1//gm 28 0 28
15 28 $text;
16 }
17  
18 14 my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
19  
20 14 ▶my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
Condition66%2/3
ref $_ || $maybe_libs{$_}
l!l&&r!l&&!r
07042
MC/DC50%1/2
ref $_ || $maybe_libs{$_}
ref $_ $maybe_libs{$_}
Truth table66%2/3
A || B
A= ref $_B= $maybe_libs{$_}
ABresult
1X1
011
000
21 my $extra_libs = join '', map {
22 14 my $lib = $_;
23 42 $lib =~ s{'}{'\\''}g;
24 42 " -I'$lib'\n";
25 } @extra_libs;
26  
27 14 my $command = qq(
28 $^X
29 $extra_libs
30 -mObject::Remote
31 -mObject::Remote::Connector::STDIO
32 -mFuture
33 -mFuture::PP
34 -mMRO::Compat
35 -mClass::C3
36 -mClass::C3::next
37 -mAlgorithm::C3
38 -mObject::Remote::ModuleLoader
39 -mObject::Remote::Node
40 -mMethod::Generate::BuildAll
41 -mMethod::Generate::DemolishAll
42 -mMoo::HandleMoose::_TypeMap
43 -mJSON::PP
44 -mDevel::GlobalDestruction
45 -e 'print join "\\n", \%INC'
46 );
47  
48 14 $command =~ s/\n/ /g;
49  
50 14 chomp(my @inc = qx($command));
51  
52 14 my %exclude = map { $_ => 1 } @exclude_mods;
53  
54 14 my %file_names = @inc;
55  
56 # only include mods that match the filename,
57 # ie ones that will succeed with a require $module
58 # https://rt.cpan.org/Ticket/Display.html?id=100478
59 my %mods =
60 2434 map { $file_names{$_} => $_ }
61 14 grep { $file_names{$_} =~ /\Q$_\E$/ } keys %file_names;
62  
63 14 foreach(keys(%mods)) {
64 2434 ▶ if ($exclude{ $mods{$_} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude{$mods{$_}}) 28 2406 2434
65 28 delete($mods{$_});
66 }
67 }
68  
69 my @non_core_non_arch = ($file_names{'Devel/GlobalDestruction.pm'}
70 14 ▶ ? ( $file_names{'Devel/GlobalDestruction.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
$file_names{'Devel/GlobalDestruction.pm'} ? : 14 0 14
71 : ());
72 push @non_core_non_arch, grep +(
73 not (
74 #some of the config variables can be empty which will eval as a matching regex
75 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
76 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
77 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
78 14 ▶ or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
Condition52%11/21
$Object::Remote::FatNode::Config{'privlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'privlibexp'}\E/ || $Object::Remote::FatNode::Config{'archlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'archlibexp'}\E/ || $Object::Remote::FatNode::Config{'vendorarchexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'vendorarchexp'}\E/ || $Object::Remote::FatNode::Config{'sitearchexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'sitearchexp'}\E/
l!l&&r!l&&!r
6580866
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/ or $Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/ or $Object::Remote::FatNode::Config{"vendorarchexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"vendorarchexp"}\E/
l!l&&r!l&&!r
6580866
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/ or $Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/
l!l&&r!l&&!r
6580866
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/
!ll&&!rl&&r
0866658
$Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/
!ll&&!rl&&r
08660
$Object::Remote::FatNode::Config{"vendorarchexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"vendorarchexp"}\E/
!ll&&!rl&&r
86600
$Object::Remote::FatNode::Config{"sitearchexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"sitearchexp"}\E/
!ll&&!rl&&r
08660
MC/DC12%1/8
$Object::Remote::FatNode::Config{'privlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'privlibexp'}\E/ || $Object::Remote::FatNode::Config{'archlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'archlibexp'}\E/ || $Object::Remote::FatNode::Config{'vendorarchexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'vendorarchexp'}\E/ || $Object::Remote::FatNode::Config{'sitearchexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'sitearchexp'}\E/
$Object::Remote::FatNode::Config{"privlibexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/ $Object::Remote::FatNode::Config{"archlibexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/ $Object::Remote::FatNode::Config{"vendorarchexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"vendorarchexp"}\E/ $Object::Remote::FatNode::Config{"sitearchexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"sitearchexp"}\E/
Truth table6%2/31
A and B or C and D or E and F || G and H
A= $Object::Remote::FatNode::Config{"privlibexp"} ne ""B= /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/C= $Object::Remote::FatNode::Config{"archlibexp"} ne ""D= /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/E= $Object::Remote::FatNode::Config{"vendorarchexp"} ne ""F= /^\Q$Object::Remote::FatNode::Config{"vendorarchexp"}\E/G= $Object::Remote::FatNode::Config{"sitearchexp"} ne ""H= /^\Q$Object::Remote::FatNode::Config{"sitearchexp"}\E/
ABCDEFGHresult
11XXXXXX1
0X11XXXX1
1011XXXX1
0X0X11XX1
0X1011XX1
100X11XX1
101011XX1
0X0X0X111
0X0X10111
0X100X111
0X1010111
100X0X111
100X10111
10100X111
101010111
0X0X0X0X0
0X0X0X100
0X0X100X0
0X0X10100
0X100X0X0
0X100X100
0X10100X0
0X1010100
100X0X0X0
100X0X100
100X100X0
100X10100
10100X0X0
10100X100
1010100X0
101010100
79 )
80 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
81  
82 my @core_non_arch = grep +(
83 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
84 14 ▶ and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
Condition73%11/15
$Object::Remote::FatNode::Config{'privlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'privlibexp'}\E/ && !($Object::Remote::FatNode::Config{'archlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'archlibexp'}\E/ || /\Q$Object::Remote::FatNode::Config{'archname'}\E/ || /\Q$Object::Remote::FatNode::Config{'myarchname'}\E/)
!ll&&!rl&&r
1258490658
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/
!ll&&!rl&&r
012581148
$Object::Remote::FatNode::Config{'archlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'archlibexp'}\E/ || /\Q$Object::Remote::FatNode::Config{'archname'}\E/ || /\Q$Object::Remote::FatNode::Config{'myarchname'}\E/
l!l&&r!l&&!r
4900658
$Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/ or /\Q$Object::Remote::FatNode::Config{"archname"}\E/
l!l&&r!l&&!r
4900658
$Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/
!ll&&!rl&&r
0658490
MC/DC33%2/6
$Object::Remote::FatNode::Config{'privlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'privlibexp'}\E/ && !($Object::Remote::FatNode::Config{'archlibexp'} ne '' && /^\Q$Object::Remote::FatNode::Config{'archlibexp'}\E/ || /\Q$Object::Remote::FatNode::Config{'archname'}\E/ || /\Q$Object::Remote::FatNode::Config{'myarchname'}\E/)
$Object::Remote::FatNode::Config{"privlibexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/ $Object::Remote::FatNode::Config{"archlibexp"} ne "" /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/ /\Q$Object::Remote::FatNode::Config{"archname"}\E/ /\Q$Object::Remote::FatNode::Config{'myarchname'}\E/
Truth table33%3/9
A and B && not(C and D or E || F)
A= $Object::Remote::FatNode::Config{"privlibexp"} ne ""B= /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/C= $Object::Remote::FatNode::Config{"archlibexp"} ne ""D= /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/E= /\Q$Object::Remote::FatNode::Config{"archname"}\E/F= /\Q$Object::Remote::FatNode::Config{'myarchname'}\E/
ABCDEFresult
0XXXXX0
10XXXX0
1111XX0
110X1X0
11101X0
110X010
1110010
110X001
1110001
85 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
86 ), keys %mods;
87  
88 14 my $start = stripspace <<'END_START';
89 # This chunk of stuff was generated by Object::Remote::FatNode. To find
90 # the original file's code, look for the end of this BEGIN block or the
91 # string 'FATPACK'
92 BEGIN {
93 my (%fatpacked,%fatpacked_extra);
94 END_START
95  
96 14 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
97  
98 14 my $end = stripspace <<'END_END';
99 s/^ //mg for values %fatpacked, values %fatpacked_extra;
100  
101 sub load_from_hash {
102 if (my $fat = $_[0]->{$_[1]}) {
103 if ($exclude{$_[1]}) {
104 warn "Will not pre-load '$_[1]'";
105 return undef;
106 }
107  
108 #warn "Handling $_[1]";
109 open my $fh, '<', \$fat;
110 return $fh;
111 }
112  
113 #Uncomment this to find brokenness
114 #warn "Missing $_[1]";
115 return;
116 }
117  
118 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
119 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
120  
121 } # END OF FATPACK CODE
122  
123 use strictures 1;
124 use Object::Remote::Node;
125  
126 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
127 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
128 }
129  
130 END_END
131  
132 1538 ▶sub slurp {
Subroutine slurp: called CC=2 SCAR=7.1
Pod undocumented
133 1538 ▶ open(my $fh, '<', $_[0])
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $_[0] or die "Can't open file $_[0]: $!" 1538 0 1538
134 or die "Can't open file $_[0]: $!";
135 1538 local $/ = undef;
136 1538 return <$fh>;
137 }
138  
139 14 my %files = map +($mods{$_} => scalar do { slurp($_) }),
140 @non_core_non_arch, @core_non_arch;
141  
142 1538 ▶sub generate_fatpack_hash {
Subroutine generate_fatpack_hash: called CC=4 SCAR=14.2
Pod undocumented
143 1538 my ($hash_name, $orig) = @_;
144 1538 ▶ return '' unless $orig;
Branch: 1 branch
BranchTrueFalseTotal
unless $orig 0 1538 1538
145 1538 (my $stub = $orig) =~ s/\.pm$//;
146 1538 my $name = uc join '_', split '/', $stub;
147 1538 ▶ my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $files{$orig} or die $orig 1538 0 1538
148 1538 ▶ $data .= "\n" unless $data =~ m/\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /\n$/ 0 1538 1538
149 1538 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
150 .qq!${data}${name}\n!;
151 1538 return $ret;
152 }
153  
154 # HAARG notes that ideally Object::Remote should use Module::Reader to
155 # pass the sources of fatpacked modules to the remote. However, it has
156 # some problems with more recent Perl versions, which is why we go with
157 # the approach below (for now) -- EH 2025-07-20
158 0 ▶sub propagate_fatpacked {
Subroutine propagate_fatpacked: not called CC=3 SCAR=24.8
Pod undocumented
159 0 my ($hash_name, $fat_hash) = @_;
160 0 warn 'Propagating fatpacked hash' . $fat_hash;
161 0 my @segments;
162 0 ▶ while (my ($orig, $data) = each %{$fat_hash}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$fat_hash;}) 0 0 0
163 0 (my $stub = $orig) =~ s/\.pm//;
164 0 my $name = uc join '_', split '/', $stub;
165 0 $data =~ s/^/ /mg;
166 0 ▶ $data .= "\n" unless $data =~ m/\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /\n$/ 0 0 0
167 0 push @segments,
168 ('$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
169 .qq!${data}${name}\n!);
170 }
171 0 return @segments;
172 }
173  
174 my @segments = (
175 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
176 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
177 14 ▶ (map { propagate_fatpacked('fatpacked', $_) } grep { blessed($_) and ref($_) =~ m/^FatPacked::/ } @INC),
Condition33%1/3
builtin::blessed($_) && ref($_) =~ /^FatPacked::/
!ll&&!rl&&r
11200
MC/DC0%0/2
builtin::blessed($_) && ref($_) =~ /^FatPacked::/
builtin::blessed($_) ref($_) =~ /^FatPacked::/
Truth table33%1/3
A && B
A= builtin::blessed($_)B= ref($_) =~ /^FatPacked::/
ABresult
0X0
100
111
178 );
179  
180 #print STDERR Dumper(\@segments);
181 14 our $DATA = join "\n", $start, @segments, $end;
182  
183 14 1;
« Remote/ConnectionServer.pm ↑ Summary Remote/Connection.pm »