Pipeline/Sources.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 19 / 19 Podpod 100% 4 / 4 totaltotal 100% 94 / 94 CC 12 SCAR 8.5
CC
12
Cov
100%
counter
5.0
__ANON__
4.0
__ANON__
2.0
CRAP 2.3
« Pipeline/Iterator.pm ↑ Summary Pipeline/Stages/Batch.pm »
1 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Sources;
4  
5 7 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Scalar::Util qw(looks_like_number openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Ekorn::Pipeline::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Ekorn::Pipeline::Factories qw(source);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use namespace::clean -except => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 our @EXPORT_OK = qw(from_array from_fh from_file counter);
12 7 our %EXPORT_TAGS = (all => \@EXPORT_OK);
13  
14 # Croak at the line that called Ekorn::Pipeline.
15 7 our @CARP_NOT = @Ekorn::Pipeline::Errors::INTERNAL;
16  
17 # Return a source giving the values given, from the first, each run.
18 56 ▶sub from_array (@values) {
Subroutine from_array: called CC=1 SCAR=0.0
Pod documented
19 55 ▶ return source {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 55 my $i = 0;
21  
22 # Without a signature, as it's called for each value.
23 55 ▶ return sub { $i < @values ? $values[$i++] : () };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$i < @values ? : 102 40 142
24 56 };
25 }
26  
27  
28 # Return a source giving the filehandle's records, as $/ divides them,
29 # with $/ taken off, leaving it open, for its opener to close.
30 6 ▶sub from_fh ($fh) {
Subroutine from_fh: called CC=2 SCAR=6.9
Pod documented
31 6 ▶ croakf 'Expected an open filehandle' unless defined openhandle($fh);
Branch: 1 branch
BranchTrueFalseTotal
unless defined &openhandle($fh) 2 4 6
32 4 ▶ return source { _records($fh) };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 }
34  
35  
36 # Return a source giving the file's records, as $/ divides them, with $/
37 # taken off; the file is opened for each run, with the I/O layers given,
38 # if any, such as ':raw', and closed as it ends.
39 13 ▶sub from_file ($path, $layers = '') {
Subroutine from_file: called CC=2 SCAR=6.9
Pod documented
40 13 ▶ return source {
Subroutine __ANON__: called CC=2 SCAR=6.9
41 # Open for the run, and closed by its end.
42 13 ▶ open my $fh, "<$layers", $path or croakf ## no critic (InputOutput::RequireBriefOpen)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$layers", $path or croakf("Can't read %s: %s", $path, $!) 12 1 13
43 q(Can't read %s: %s), $path, $!;
44 12 ▶ return {step => _records($fh), end => sub ($how) { close $fh }};
Subroutine __ANON__: called CC=1 SCAR=0.0
45 13 };
46 }
47  
48  
49 # Return a source giving $start, then on by $step, without end.
50 6 ▶sub counter ($start = 1, $step = 1) {
Subroutine counter: called CC=5 SCAR=16.1
Pod documented
51 6 ▶ croakf 'Expected a number to start from, and one to step by'
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($start) and &looks_like_number($step) 2 4 6
Condition100%3/3
&looks_like_number($start) and &looks_like_number($step)
!ll&&!rl&&r
114
MC/DC100%2/2
&looks_like_number($start) and &looks_like_number($step)
&looks_like_number($start) &looks_like_number($step)
Truth table100%3/3
A and B
A= &looks_like_number($start)B= &looks_like_number($step)
ABresult
0X0
100
111
52 unless looks_like_number($start) && looks_like_number($step);
53 5 ▶ return source {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 5 my $next = $start;
55  
56 # Without a signature, as it's called for each value.
57 5 ▶ return sub { my $n = $next; $next += $step; return $n };
Subroutine __ANON__: called CC=1 SCAR=0.0
58 4 };
59 }
60  
61  
62 # Return a step reading the filehandle's records, as $/ divides them, at
63 # each read, with $/ taken off. With $/ undefined, what's left is one
64 # record, and an empty file none, where readline gives an empty string.
65 16 ▶sub _records ($fh) {
Subroutine _records: called CC=1 SCAR=0.0
66 # Without a signature, as it's called for each value.
67 76 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
68 76 my $read = readline $fh;
69 76 ▶ return if !defined $read || (!defined $/ && $read eq '');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $read or not defined $/ and $read eq "" 14 62 76
Condition100%6/6
not defined $read or not defined $/ and $read eq ""
l!l&&r!l&&!r
12262
not defined $/ and $read eq ""
!ll&&!rl&&r
6022
MC/DC100%3/3
not defined $read or not defined $/ and $read eq ""
not defined $read not defined $/ $read eq ""
Truth table100%4/4
not(A) or not(B) and C
A= not defined $readB= not defined $/C= $read eq ""
ABCresult
1XX1
0111
00X0
0100
70 62 chomp $read;
71 62 return $read;
72 16 };
73 }
74  
75 7 1;
76  
77 __END__
« Pipeline/Iterator.pm ↑ Summary Pipeline/Stages/Batch.pm »