Remote/FatNode.pm

filter: Statementstmt 59.1% 42 / 71 Branchbran 11.1% 2 / 18 Conditioncond 7.1% 3 / 42 MC/DCmcdc 5.5% 1 / 18 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 4 totaltotal 32.9% 53 / 161 CC 8 SCAR 22.1
CC
8
Cov
36%
generate_fatpack_hash
20.0
propagate_fatpacked
12.0
slurp
6.0
CRAP 9.1
« Remote/ModuleSender.pm ↑ Summary Remote/Logging/Logger.pm »
1 package Object::Remote::FatNode;
2  
3 1 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use B qw(perlstring);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 my @exclude_mods = qw(XSLoader.pm DynaLoader.pm);
9 #used by t/watchdog_fatnode
10 1 our $INHIBIT_RUN_NODE = 0;
11  
12 2 ▶sub stripspace {
Subroutine stripspace: called CC=2 SCAR=7.1
Pod undocumented
13 2 my ($text) = @_;
14 2 ▶ $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^(\s+)/ and $text =~ s/^$1//gm 2 0 2
15 2 $text;
16 }
17  
18 1 my %maybe_libs = map +($_ => 1), grep defined, (values %Config, '.');
19  
20 1 ▶my @extra_libs = grep not(ref($_) or $maybe_libs{$_}), @INC;
Condition66%2/3
ref $_ || $maybe_libs{$_}
l!l&&r!l&&!r
053
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 1 my $lib = $_;
23 3 $lib =~ s{'}{'\\''}g;
24 3 " -I'$lib'\n";
25 } @extra_libs;
26  
27  
28 ### NOTE: The command above can't have single quotes:
29 ## single quotes are not compatible with Windows
30 1 my $command = qq(
31 $^X
32 $extra_libs
33 -mObject::Remote
34 -mObject::Remote::Connector::STDIO
35 -mFuture
36 -mFuture::PP
37 -mMRO::Compat
38 -mClass::C3
39 -mClass::C3::next
40 -mAlgorithm::C3
41 -mObject::Remote::ModuleLoader
42 -mObject::Remote::Node
43 -mMethod::Generate::BuildAll
44 -mMethod::Generate::DemolishAll
45 -mMoo::HandleMoose::_TypeMap
46 -mJSON::PP
47 -mDevel::GlobalDestruction
48 -e "print join(\\"\\n\\", \%INC)"
49 );
50 ### NOTE: The command above can't have single quotes:
51 ## single quotes are not compatible with Windows
52  
53 1 $command =~ s/\n/ /g;
54  
55 1 chomp(my @inc = qx($command));
56  
57 1 my %exclude = map { $_ => 1 } @exclude_mods;
58  
59 1 my %file_names = @inc;
60  
61 # only include mods that match the filename,
62 # ie ones that will succeed with a require $module
63 # https://rt.cpan.org/Ticket/Display.html?id=100478
64 my %mods =
65 0 map { $file_names{$_} => $_ }
66 0 grep { $file_names{$_} =~ /\Q$_\E$/ } keys %file_names;
67  
68 1 foreach(keys(%mods)) {
69 0 ▶ if ($exclude{ $mods{$_} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude{$mods{$_}}) 0 0 0
70 0 delete($mods{$_});
71 }
72 }
73  
74 my @non_core_non_arch = ($file_names{'Devel/GlobalDestruction.pm'}
75 1 ▶ ? ( $file_names{'Devel/GlobalDestruction.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
$file_names{'Devel/GlobalDestruction.pm'} ? : 0 1 1
76 : ());
77 push @non_core_non_arch, grep +(
78 not (
79 #some of the config variables can be empty which will eval as a matching regex
80 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
81 or $Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
82 or $Config{vendorarchexp} ne '' && /^\Q$Config{vendorarchexp}/
83 1 ▶ or $Config{sitearchexp} ne '' && /^\Q$Config{sitearchexp}/
Condition0%0/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
000
$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
000
$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
000
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/
!ll&&!rl&&r
000
$Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/
!ll&&!rl&&r
000
$Object::Remote::FatNode::Config{"vendorarchexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"vendorarchexp"}\E/
!ll&&!rl&&r
000
$Object::Remote::FatNode::Config{"sitearchexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"sitearchexp"}\E/
!ll&&!rl&&r
000
MC/DC0%0/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 table0%0/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
84 )
85 ), grep !/\Q$Config{archname}/, grep !/\Q$Config{myarchname}/, keys %mods;
86  
87 my @core_non_arch = grep +(
88 $Config{privlibexp} ne '' && /^\Q$Config{privlibexp}/
89 1 ▶ and not($Config{archlibexp} ne '' && /^\Q$Config{archlibexp}/
Condition0%0/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
000
$Object::Remote::FatNode::Config{"privlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"privlibexp"}\E/
!ll&&!rl&&r
000
$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
000
$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
000
$Object::Remote::FatNode::Config{"archlibexp"} ne "" and /^\Q$Object::Remote::FatNode::Config{"archlibexp"}\E/
!ll&&!rl&&r
000
MC/DC0%0/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 table0%0/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
90 or /\Q$Config{archname}/ or /\Q$Config{myarchname}/)
91 ), keys %mods;
92  
93 1 my $start = stripspace <<'END_START';
94 # This chunk of stuff was generated by Object::Remote::FatNode. To find
95 # the original file's code, look for the end of this BEGIN block or the
96 # string 'FATPACK'
97 BEGIN {
98 my (%fatpacked,%fatpacked_extra);
99 END_START
100  
101 1 $start .= 'my %exclude = map { $_ => 1 } (\'' . join("','", @exclude_mods) . "');\n";
102  
103 1 my $end = stripspace <<'END_END';
104 s/^ //mg for values %fatpacked, values %fatpacked_extra;
105  
106 sub load_from_hash {
107 if (my $fat = $_[0]->{$_[1]}) {
108 if ($exclude{$_[1]}) {
109 warn "Will not pre-load '$_[1]'";
110 return undef;
111 }
112  
113 #warn "Handling $_[1]";
114 open my $fh, '<', \$fat;
115 return $fh;
116 }
117  
118 #Uncomment this to find brokenness
119 #warn "Missing $_[1]";
120 return;
121 }
122  
123 unshift @INC, sub { load_from_hash(\%fatpacked, $_[1]) };
124 push @INC, sub { load_from_hash(\%fatpacked_extra, $_[1]) };
125  
126 } # END OF FATPACK CODE
127  
128 use strictures 1;
129 use Object::Remote::Node;
130  
131 unless ($Object::Remote::FatNode::INHIBIT_RUN_NODE) {
132 Object::Remote::Node->run(watchdog_timeout => $WATCHDOG_TIMEOUT);
133 }
134  
135 END_END
136  
137 0 ▶sub slurp {
Subroutine slurp: not called CC=2 SCAR=17.9
Pod undocumented
138 0 ▶ open(my $fh, '<', $_[0])
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $_[0] or die "Can't open file $_[0]: $!" 0 0 0
139 or die "Can't open file $_[0]: $!";
140 0 local $/ = undef;
141 0 return <$fh>;
142 }
143  
144 0 my %files = map +($mods{$_} => scalar do { slurp($_) }),
145 @non_core_non_arch, @core_non_arch;
146  
147 0 ▶sub generate_fatpack_hash {
Subroutine generate_fatpack_hash: not called CC=4 SCAR=30.0
Pod undocumented
148 0 my ($hash_name, $orig) = @_;
149 0 ▶ return '' unless $orig;
Branch: 1 branch
BranchTrueFalseTotal
unless $orig 0 0 0
150 0 (my $stub = $orig) =~ s/\.pm$//;
151 0 my $name = uc join '_', split '/', $stub;
152 0 ▶ my $data = $files{$orig} or die $orig; $data =~ s/^/ /mg;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $files{$orig} or die $orig 0 0 0
153 0 ▶ $data .= "\n" unless $data =~ m/\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /\n$/ 0 0 0
154 0 my $ret = '$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
155 .qq!${data}${name}\n!;
156 0 return $ret;
157 }
158  
159 # HAARG notes that ideally Object::Remote should use Module::Reader to
160 # pass the sources of fatpacked modules to the remote. However, it has
161 # some problems with more recent Perl versions, which is why we go with
162 # the approach below (for now) -- EH 2025-07-20
163 0 ▶sub propagate_fatpacked {
Subroutine propagate_fatpacked: not called CC=3 SCAR=24.8
Pod undocumented
164 0 my ($hash_name, $fat_hash) = @_;
165 0 warn 'Propagating fatpacked hash' . $fat_hash;
166 0 my @segments;
167 0 ▶ while (my ($orig, $data) = each %{$fat_hash}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$fat_hash;}) 0 0 0
168 0 (my $stub = $orig) =~ s/\.pm//;
169 0 my $name = uc join '_', split '/', $stub;
170 0 $data =~ s/^/ /mg;
171 0 ▶ $data .= "\n" unless $data =~ m/\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /\n$/ 0 0 0
172 0 push @segments,
173 ('$'.$hash_name.'{'.perlstring($orig).qq!} = <<'${name}';\n!
174 .qq!${data}${name}\n!);
175 }
176 0 return @segments;
177 }
178  
179 my @segments = (
180 map(generate_fatpack_hash('fatpacked', $_), sort map $mods{$_}, @non_core_non_arch),
181 map(generate_fatpack_hash('fatpacked_extra', $_), sort map $mods{$_}, @core_non_arch),
182 0 ▶ (map { propagate_fatpacked('fatpacked', $_) } grep { blessed($_) and ref($_) =~ m/^FatPacked::/ } @INC),
Condition33%1/3
builtin::blessed($_) && ref($_) =~ /^FatPacked::/
!ll&&!rl&&r
800
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
183 );
184  
185 #print STDERR Dumper(\@segments);
186 1 our $DATA = join "\n", $start, @segments, $end;
187  
188 1 1;
« Remote/ModuleSender.pm ↑ Summary Remote/Logging/Logger.pm »