Pipeline/Feed.pm

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