Pipeline/Stages/Batch.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 10 / 10 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 100% 79 / 79 CC 10 SCAR 8.3
CC
10
Cov
100%
batch
4.0
collect
4.0
__ANON__
2.0
CRAP 2.3
« Pipeline/Sources.pm ↑ Summary Pipeline/Stages/Flow.pm »
1 13 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Stages::Batch;
4  
5 13 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Ref::Util qw(is_coderef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Ekorn::Pipeline::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Ekorn::Pipeline::Gather qw(gather);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use namespace::clean -except => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 our $VERSION = 'v0.5.0';
14  
15 13 our @EXPORT = qw(batch collect); ## no critic (Modules::ProhibitAutomaticExportation)
16  
17 13 our @EXPORT_OK = @EXPORT;
18 13 our %EXPORT_TAGS = (all => \@EXPORT_OK);
19  
20 # Croak at the line that called Ekorn::Pipeline.
21 13 our @CARP_NOT = @Ekorn::Pipeline::Errors::INTERNAL;
22  
23 # Return a stage passing values on in batches of $size, as array
24 # references, the last, shorter batch once the values run out.
25 37 ▶sub batch ($size) {
Subroutine batch: called CC=4 SCAR=13.9
Pod documented
26 37 ▶ croakf 'Expected a batch size of 1 or more'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $size && $size =~ / \A \d+ \z /ax or $size < 1 8 29 37
Condition100%6/6
not defined $size && $size =~ / \A \d+ \z /ax or $size < 1
l!l&&r!l&&!r
7129
defined $size && $size =~ / \A \d+ \z /ax
!ll&&!rl&&r
1630
MC/DC100%3/3
not defined $size && $size =~ / \A \d+ \z /ax or $size < 1
defined $size $size =~ / \A \d+ \z /ax $size < 1
Truth table100%4/4
not(A && B) or C
A= defined $sizeB= $size =~ / \A \d+ \z /axC= $size < 1
ABCresult
0XX1
10X1
1111
1100
27 if !defined $size || $size !~ m( \A \d+ \z )xa || $size < 1;
28 156 ▶ return gather {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 156 my @batch;
30 return {
31 # Without a signature, as it's called for each value.
32 546 ▶ step => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
33 546 push @batch, $_[0];
34 546 ▶ return @batch < $size ? () : [splice @batch];
Branch: 1 branch
BranchTrueFalseTotal
@batch < $size ? : 358 188 546
35 },
36 142 ▶ flush => sub () { @batch ? [splice @batch] : () },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@batch ? : 97 45 142
37 # It holds values back: a batch, made from many, has no original.
38 156 holds => 1,
39 };
40 29 };
41 }
42  
43 # Return a stage holding every value, and, once they run out, passing on
44 # what the block given makes of them, or, without one, an array of them.
45 17 ▶sub collect : prototype(;&) ($make = undef) {
Subroutine collect: called CC=4 SCAR=13.9
Pod documented
46 17 ▶ croakf 'Expected a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $make and not Ref::Util::XS::is_coderef($make) 1 16 17
Condition100%3/3
defined $make and not Ref::Util::XS::is_coderef($make)
!ll&&!rl&&r
1331
MC/DC100%2/2
defined $make and not Ref::Util::XS::is_coderef($make)
defined $make not Ref::Util::XS::is_coderef($make)
Truth table100%3/3
A and not(B)
A= defined $makeB= not Ref::Util::XS::is_coderef($make)
ABresult
0X0
100
111
47 if defined $make && !is_coderef($make);
48 76 ▶ return gather {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 76 my @values;
50 return {
51 # Without a signature, as it's called for each value.
52 345 ▶ step => sub { push @values, $_[0]; return },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 76 ▶ flush => sub () {
Subroutine __ANON__: called CC=2 SCAR=6.9
54 76 my @all = splice @values;
55 76 ▶ return $make ? $make->(@all) : \@all;
Branch: 1 branch
BranchTrueFalseTotal
$make ? : 4 72 76
56 },
57 76 };
58 16 };
59 }
60  
61 13 1;
62 __END__
« Pipeline/Sources.pm ↑ Summary Pipeline/Stages/Flow.pm »