| 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
Condition100%3/3
$self->{"busy"} or defined $self->{"ended"}->()
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"}->()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 48 | croakf 'Expected no %s of a feed from inside its own run', 'finish' | ||||||||||||||||||||||||||||
| 49 | 6 | ▶ | if $self->{busy}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->{"why"} // ($ended eq "died" ? "it died" : "a stage stopped it")
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 72 | 306 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 27 | 1; | |||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||