blib/lib/Ekorn/Pipeline/Workers/Wire.pm

filter: Statementstmt 100% 36 / 36 Branchbran 92.8% 13 / 14 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 98.5% 66 / 67 CC 9 SCAR 9.3
CC
9
Cov
98%
resolve
4.0
write_frame
3.0
_read_exactly
3.0
CRAP 2.5
« blib/lib/Ekorn/Pipeline/Workers.pm ↑ Summary
1 366 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Workers::Wire;
4  
5 # What the program and its workers share: messages framed by length on
6 # a socket, and functions found by name. For Ekorn::Pipeline::Workers'
7 # own modules, not its callers.
8  
9 366 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 366 our $VERSION = 'v0.1.0';
12 366 our @EXPORT_OK = qw(write_frame read_frame resolve unplaced token_variable);
13  
14  
15 # The environment variable that gives a worker its token: its
16 # environment, not its command line, which every user of the computer
17 # can read (Ekorn-Pipeline's 2026-0065, D16).
18 372 ▶sub token_variable () {
Subroutine token_variable: called CC=1 SCAR=0.0
Pod documented
19 372 return 'EKORN_PIPELINE_WORKERS_TOKEN';
20 }
21  
22  
23 # A message without the places Perl added to it: Storable's own file
24 # and line, and the pool's, say nothing a caller can act on.
25 287 ▶sub unplaced ($message) {
Subroutine unplaced: called CC=1 SCAR=0.0
Pod documented
26 287 return $message =~ s( (?: ,?\ at\ \S+\ line\ \d+ )+ \.? \n? \z )()xsr;
27 }
28  
29  
30 # The code a name gives, loading its module if it must; undef if none.
31 # A module that won't load dies with Perl's reason, less its place, so
32 # a caller learns why, not only that there's no function.
33 4435 ▶sub resolve ($name) {
Subroutine resolve: called CC=4 SCAR=13.9
Pod documented
34 4435 my($module) = $name =~ m( \A (.+) :: \w+ \z )x;
35 366 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4435 ▶ unless (defined &{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$name;}) 579 3856 4435
37 579 (my $file = "$module.pm") =~ s( :: )(/)gx;
38 579 ▶ eval { require $file; 1 } or die unplaced($@) . "\n";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file; 1 } } or die unplaced($@) . "\n" 360 219 579
39 }
40 4216 ▶ return defined &{ $name } ? \&{ $name } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined &{$name;} ? : 4034 182 4216
41 }
42  
43  
44 # Write a frame: its length, then it. False if the socket's gone.
45 21626 ▶sub write_frame ($fh, $frame) {
Subroutine write_frame: called CC=3 SCAR=11.0
Pod documented
46 21626 my $data = pack('N', length $frame) . $frame;
47 21626 ▶ while (length $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data) 21626 21626 43252
48 21626 my $wrote = syswrite $fh, $data;
49 21626 ▶ return 0 unless $wrote;
Branch: 1 branch
BranchTrueFalseTotal
unless $wrote 0 21626 21626
50 21626 substr $data, 0, $wrote, '';
51 }
52 21626 return 1;
53 }
54  
55  
56 53866 ▶sub _read_exactly ($fh, $length) {
Subroutine _read_exactly: called CC=3 SCAR=11.0
57 53866 my $data = '';
58 53866 ▶ while (length $data < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data < $length) 53866 53626 107492
59 53866 my $read = sysread $fh, $data, $length - length $data, length $data;
60 53866 ▶ return undef unless $read; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
unless $read 240 53626 53866
61 }
62 53626 return $data;
63 }
64  
65  
66 27053 ▶sub read_frame ($fh) {
Subroutine read_frame: called CC=2 SCAR=6.9
Pod documented
67 27053 ▶ my $header = _read_exactly($fh, 4) // return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Condition100%2/2
_read_exactly($fh, 4) // (return undef)
l!l
26813240
MC/DC100%1/1
_read_exactly($fh, 4) // (return undef)
_read_exactly($fh, 4)
Truth table100%2/2
A
A= _read_exactly($fh, 4)
Aresult
11
00
68 26813 return _read_exactly($fh, unpack 'N', $header);
69 }
70  
71 366 1;
72  
73 __END__
« blib/lib/Ekorn/Pipeline/Workers.pm ↑ Summary