Pipeline/Feed.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 16 / 16 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 100% 70 / 70 CC 11 SCAR 11.3
CC
11
Cov
100%
_check_open
5.0
push
4.0
finish
3.0
CRAP 3.1
« Pipeline/Stages/Taps.pm ↑ Summary Pipeline/Stage.pm »
1 32 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Ekorn::Pipeline::Feed;
4  
5 32 ▶use Ekorn::Pipeline::Errors qw(croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Croak at the line that called Ekorn::Pipeline.
9 32 our $VERSION = 'v0.3.16';
10  
11 32 our @CARP_NOT = @Ekorn::Pipeline::Errors::INTERNAL;
12  
13 # Return a feed of a run, from its parts, each a code reference: push,
14 # taking values and returning what came out of them; close, ending the
15 # input and returning what the flushes give; finish, ending the run as
16 # from outside; and ended, returning how the run ended, or nothing
17 # while it's open.
18 426 ▶sub new ($class, %parts) {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
19 426 return bless {%parts, why => undef, busy => 0}, $class;
20 }
21  
22 # Return what came out of the values pushed: a list, or, asked for one
23 # value, an array reference of them.
24 #
25 # Checked inline, as a feed may be pushed a value at a time. A push that
26 # dies leaves busy set, but the run has died, which is checked first.
27 638 ▶sub push ($self, @values) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine push: called CC=4 SCAR=13.9
Pod documented
28 638 ▶ $self->_check_open('push') if $self->{busy} || defined $self->{ended}->();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"busy"} or defined $self->{"ended"}->() 5 633 638
Condition100%3/3
$self->{"busy"} or defined $self->{"ended"}->()
l!l&&r!l&&!r
23633
MC/DC100%2/2
$self->{"busy"} or defined $self->{"ended"}->()
$self->{"busy"} defined $self->{"ended"}->()
Truth table100%3/3
A or B
A= $self->{"busy"}B= defined $self->{"ended"}->()
ABresult
1X1
011
000
29 633 $self->{busy} = 1;
30 633 my @results = $self->{push}->(@values);
31 620 $self->{busy} = 0;
32 620 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 603 17 620
33 }
34  
35 # End the input, and return what the flushes give, as push returns its
36 # results.
37 332 ▶sub close ($self) { ## no critic (Subroutines::ProhibitBuiltinHomonyms, NamingConventions::ProhibitAmbiguousNames)
Subroutine close: called CC=2 SCAR=6.9
Pod documented
38 332 $self->_check_open('close');
39 327 $self->{busy} = 1;
40 327 my @results = $self->{close}->();
41 307 @$self{qw(busy why)} = (0, 'it was closed');
42 307 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 286 21 307
43 }
44  
45 # End the run, if it hasn't ended, as from outside.
46 11 ▶sub finish ($self) {
Subroutine finish: called CC=3 SCAR=11.0
Pod documented
47 11 ▶ return if defined $self->ended;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ended 6 5 11
48 croakf 'Expected no %s of a feed from inside its own run', 'finish'
49 5 ▶ if $self->{busy};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"busy"} 1 4 5
50 4 $self->{finish}->();
51 4 $self->{why} = 'it was finished';
52 4 return;
53 }
54  
55 # Return how the run ended: "done", "stopped" or "died"; nothing while
56 # it's open.
57 1674 ▶sub ended ($self) {
Subroutine ended: called CC=1 SCAR=0.0
Pod documented
58 1674 return $self->{ended}->();
59 }
60  
61 # Croak unless the run is open, and the call isn't from inside it: once
62 # the run has ended, busy may be left set by a push that died.
63 337 ▶sub _check_open ($self, $method) {
Subroutine _check_open: called CC=5 SCAR=16.1
64 337 my $ended = $self->ended;
65 croakf 'Expected a feed still open, but its run has ended: %s',
66 337 ▶ $self->{why} // ($ended eq 'died' ? 'it died' : 'a stage stopped it')
Branch: 2 branches
BranchTrueFalseTotal
if defined $ended 8 329 337
$ended eq 'died' ? : 2 2 4
Condition100%2/2
$self->{"why"} // ($ended eq "died" ? "it died" : "a stage stopped it")
l!l
44
MC/DC100%1/1
$self->{"why"} // ($ended eq "died" ? "it died" : "a stage stopped it")
$self->{"why"}
Truth table100%2/2
A
A= $self->{"why"}
Aresult
11
00
67 if defined $ended;
68 croakf 'Expected no %s of a feed from inside its own run', $method
69 329 ▶ if $self->{busy};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"busy"} 2 327 329
70 327 return;
71 }
72  
73 32 1;
74 __END__
« Pipeline/Stages/Taps.pm ↑ Summary Pipeline/Stage.pm »