| 1 | 12 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Ekorn::Pipeline::Stages::Batch; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Ref::Util qw(is_coderef); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Ekorn::Pipeline::Errors qw(croakf); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Ekorn::Pipeline::Gather qw(gather); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use namespace::clean -except => 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | our $VERSION = 'v0.3.16'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | our @EXPORT = qw(batch collect); ## no critic (Modules::ProhibitAutomaticExportation) | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | our @EXPORT_OK = @EXPORT; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Croak at the line that called Ekorn::Pipeline. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | 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 | 35 | ▶ | sub batch ($size) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
batch: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | ▶ | croakf 'Expected a batch size of 1 or more' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $size && $size =~ / \A \d+ \z /ax or $size < 1
defined $size && $size =~ / \A \d+ \z /ax
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
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | if !defined $size || $size !~ m( \A \d+ \z )xa || $size < 1; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 154 | ▶ | return gather { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 154 | my @batch; | |||||||||||||||||||||||||||||||||||||||||
| 30 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # Without a signature, as it's called for each value. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 538 | ▶ | step => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 538 | push @batch, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 538 | ▶ | return @batch < $size ? () : [splice @batch]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 140 | ▶ | flush => sub () { @batch ? [splice @batch] : () }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 27 | }; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # Return a stage holding every value, and, once they run out, passing on | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # what the block given makes of them, or, without one, an array of them. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | sub collect : prototype(;&) ($make = undef) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collect: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 16 | ▶ | croakf 'Expected a code reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $make and not Ref::Util::XS::is_coderef($make)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | if defined $make && !is_coderef($make); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 75 | ▶ | return gather { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 75 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 48 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # Without a signature, as it's called for each value. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 342 | ▶ | step => sub { push @values, $_[0]; return }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 75 | ▶ | flush => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 75 | my @all = splice @values; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 75 | ▶ | return $make ? $make->(@all) : \@all; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 75 | }; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||||||||||||