Pipeline/Factories.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 18 / 18 Podpod 100% 7 / 7 totaltotal 100% 78 / 78 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 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Factories;
4  
5 11 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Ref::Util qw(is_coderef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Ekorn::Pipeline qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Ekorn::Pipeline::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Ekorn::Pipeline::Gather qw(gather);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Ekorn::Pipeline::Sink qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Ekorn::Pipeline::Source qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Ekorn::Pipeline::Stage qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 our @EXPORT_OK
15 11 = qw(pipeline stage gather source generator yield sink_one sink_many);
16 11 our %EXPORT_TAGS = (all => \@EXPORT_OK);
17  
18 # Croak at the line that called Ekorn::Pipeline.
19 11 our @CARP_NOT = @Ekorn::Pipeline::Errors::INTERNAL;
20  
21 # The values a generator's block has yielded in the run under way, if
22 # any: local to each run, so a generator read inside another's block
23 # keeps its own.
24 11 our $YIELDED;
25  
26 # Return a pipeline of the stages given, each a code reference, a
27 # pipeline, or the name of one, looked up in the caller's package.
28 59 ▶sub pipeline (@stages) {
Subroutine pipeline: called CC=1 SCAR=0.0
Pod documented
29 59 return Ekorn::Pipeline->pipeline_in(scalar caller, @stages);
30 }
31  
32 # Return a Stage of the block given.
33 37 ▶sub stage : prototype(&) ($code) {
Subroutine stage: called CC=1 SCAR=0.0
Pod documented
34 37 return Ekorn::Pipeline::Stage->new($code);
35 }
36  
37  
38 # Return a Source made for each run by the set-up given.
39 166 ▶sub source : prototype(&) ($setup) {
Subroutine source: called CC=1 SCAR=0.0
Pod documented
40 166 return Ekorn::Pipeline::Source->new($setup);
41 }
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  
61 # Add the values given to what the generator whose block is running
62 # gives.
63 19 ▶sub yield (@values) {
Subroutine yield: called CC=2 SCAR=6.9
Pod documented
64 19 ▶ croakf 'Expected yield to be called inside a generator' unless $YIELDED;
Branch: 1 branch
BranchTrueFalseTotal
unless $Ekorn::Pipeline::Factories::YIELDED 1 18 19
65 18 push @$YIELDED, @values;
66 18 return;
67 }
68  
69  
70 # Return a Sink made for each run by the set-up given, its result one
71 # value.
72 28 ▶sub sink_one : prototype(&) ($setup) {
Subroutine sink_one: called CC=1 SCAR=0.0
Pod documented
73 28 return Ekorn::Pipeline::Sink->new_sink_one($setup);
74 }
75  
76  
77 # Return a Sink made for each run by the set-up given, its result a
78 # list.
79 14 ▶sub sink_many : prototype(&) ($setup) {
Subroutine sink_many: called CC=1 SCAR=0.0
Pod documented
80 14 return Ekorn::Pipeline::Sink->new_sink_many($setup);
81 }
82  
83 11 1;
84  
85 __END__
« Pipeline/Sink.pm ↑ Summary Pipeline/Source.pm »