Pipeline/Factories.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 18 / 18 Podpod 100% 7 / 7 totaltotal 100% 79 / 79 CC 4 SCAR 2.5
CC
4
Cov
100%
generator
2.0
__ANON__
2.0
yield
2.0
CRAP 1.3
« Pipeline/Sink.pm ↑ Summary Pipeline/Source.pm »
1 16 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Factories;
4  
5 16 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Ref::Util qw(is_coderef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Ekorn::Pipeline qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Ekorn::Pipeline::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Ekorn::Pipeline::Gather qw(gather);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Ekorn::Pipeline::Sink qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Ekorn::Pipeline::Source qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Ekorn::Pipeline::Stage qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 16 our $VERSION = 'v0.4.0';
15  
16 our @EXPORT_OK
17 16 = qw(pipeline stage gather source generator yield sink_one sink_many);
18 16 our %EXPORT_TAGS = (all => \@EXPORT_OK);
19  
20 # Croak at the line that called Ekorn::Pipeline.
21 16 our @CARP_NOT = @Ekorn::Pipeline::Errors::INTERNAL;
22  
23 # The values a generator's block has yielded in the run under way, if
24 # any: local to each run, so a generator read inside another's block
25 # keeps its own.
26 16 our $YIELDED;
27  
28 # Return a pipeline of the stages given, each a code reference, a
29 # pipeline, or the name of one, looked up in the caller's package.
30 59 ▶sub pipeline (@stages) {
Subroutine pipeline: called CC=1 SCAR=0.0
Pod documented
31 59 return Ekorn::Pipeline->pipeline_in(scalar caller, @stages);
32 }
33  
34 # Return a Stage of the block given.
35 61 ▶sub stage : prototype(&) ($code) {
Subroutine stage: called CC=1 SCAR=0.0
Pod documented
36 61 return Ekorn::Pipeline::Stage->new($code);
37 }
38  
39 # Return a Source made for each run by the set-up given.
40 248 ▶sub source : prototype(&) ($setup) {
Subroutine source: called CC=1 SCAR=0.0
Pod documented
41 248 return Ekorn::Pipeline::Source->new($setup);
42 }
43  
44 # Return a Source giving what the block yields: each run calls the block
45 # once, collecting every value it passes to yield, and gives them all
46 # as one step, so the block runs to its end before the first goes on.
47 7 ▶sub generator : prototype(&) ($block) {
Subroutine generator: called CC=2 SCAR=6.9
Pod documented
48 7 ▶ croakf 'Expected a code reference' unless is_coderef($block);
Branch: 1 branch
BranchTrueFalseTotal
unless is_coderef($block) 1 6 7
49 6 ▶ return Ekorn::Pipeline::Source->new(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 6 my $ran;
51 10 ▶ return sub () {
Subroutine __ANON__: called CC=2 SCAR=6.9
52 10 ▶ return if $ran++;
Branch: 1 branch
BranchTrueFalseTotal
if $ran++ 4 6 10
53 6 local $YIELDED = [];
54 6 $block->();
55 6 return @$YIELDED;
56 6 };
57 6 });
58 }
59  
60 # Add the values given to what the generator whose block is running
61 # gives.
62 19 ▶sub yield (@values) {
Subroutine yield: called CC=2 SCAR=6.9
Pod documented
63 19 ▶ croakf 'Expected yield to be called inside a generator' unless $YIELDED;
Branch: 1 branch
BranchTrueFalseTotal
unless $Ekorn::Pipeline::Factories::YIELDED 1 18 19
64 18 push @$YIELDED, @values;
65 18 return;
66 }
67  
68 # Return a Sink made for each run by the set-up given, its result one
69 # value.
70 48 ▶sub sink_one : prototype(&) ($setup) {
Subroutine sink_one: called CC=1 SCAR=0.0
Pod documented
71 48 return Ekorn::Pipeline::Sink->new_sink_one($setup);
72 }
73  
74 # Return a Sink made for each run by the set-up given, its result a
75 # list.
76 14 ▶sub sink_many : prototype(&) ($setup) {
Subroutine sink_many: called CC=1 SCAR=0.0
Pod documented
77 14 return Ekorn::Pipeline::Sink->new_sink_many($setup);
78 }
79  
80 16 1;
81  
82 __END__
« Pipeline/Sink.pm ↑ Summary Pipeline/Source.pm »